Skip to main content

Azure Active Directory - How to create an application (part 1)

I’m starting a series of blog post that will be about Azure Active Directory (AAD). This blog posts will cover the following topics:

  • How to create an application for AAD
  • How to get access token for Office 365 from a native application (SL,WPF, Store)
  • How to get access token for Office 365 from a web application or Windows Phone 8
  • Multi-factor Authentication 

In this post we will talk about AAD and application over AAD. When we are working with AAD, we can manage users, groups and credentials similar with the Active Directory system that we have on-premises. Both of them are very similar, only the administration UI is a little different.
To be able to access different resources in the name of the user we need to authenticate the user in only one place. In this way, the 3rd parties’ application will not handle the user credentials. This is the most important thing that we should take into account.

This can be done using AAD because we have native support for Single Sign-On. When we are talking about Single Sign-On we should think to an application that don’t require user credentials from user, but it displays a page from WAAD tenant (AAD) where user can enter his own credentials. These page is not handled by the application, only the tenant has control over this page. After the authentication process ends, the application will receive a unique token from tenant that can be used by application to access in the name of the user specific resources for a limited time period.
From portal, we have the option to create to different types of application

  • Web Application
  • Native Client Application

You should know that the Web Application can be used with any application type, because we need to render an HTML page from AAD backend. This can be done in a web application, in a WPF application or in a Windows Phone application.
The native client application can be used with success for the type of application for which we have native support. By native support, we are referring to a library that can be used directly, without having to render a custom HTML page and so (more details in the next post of this series).
In both cases, you should know that you cannot customize the page where user credentials need to be entered. The only think that you can change is the logo. The scope of this limitation is to give the user the confident that the page where he enters his credentials is the real page and not a fake one.
When you create the application on Azure portal, you will see that you have a unique client id. Using this unique client id, your application will be unique identified (we are referring to the application that access AAD and not the one that you want to develop).
Also, you will need to specify the redirect URI. This address will be used for OAuth 2.0 when the redirect is done. Don’t wary if you don’t have a real address. You only need to specify a valid one – http://localhost or should be fine.
The most important think is the “Permissions to other applications” section. Using this section you specify which resources can be accessed using  the token that will be generated for your application.
In this example we want to give access to Office 365 Exchange Online. In this case we will add “Office 365 Exchange Online” in the applications list of this section. For testing purpose, you can set all the permissions to TRUE. Don’t forget to save the changes.
From this moment anybody that will have a token from this application will be able to access the Exchange Account from Office 365.
All this options are valid for Native Client Application. For Web Application, there are some additional options that can be set.
There is a list of keys that can be automatically generated. The key list is useful when you will need to request an access token. You will need to provide this key. Be aware on one thing. The key value is displayed only when you create it. After that moment the key is not displayed anymore. You will be able only to delete it (remove).
Each application had an APP ID URI and a REPLY URL. For testing purpose you can set them to http://localhost/. APP ID URI represent the address of your application. The second one is the address that will be used by AAD to reply to the authentication request.
In the next post we will see what code we need to write to be able to get a token from a Silverlight, Console or Store application.


Popular posts from this blog

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Entity Framework (EF) TransactionScope vs Database.BeginTransaction

In today blog post we will talk a little about a new feature that is available on EF6+ related to Transactions.
Until now, when we had to use transaction we used ‘TransactionScope’. It works great and I would say that is something that is now in our blood.
using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (SqlConnection conn = new SqlConnection("...")) { conn.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = conn; sqlCommand.CommandText = ... sqlCommand.ExecuteNonQuery(); ... } scope.Complete(); } Starting with EF6.0 we have a new way to work with transactions. The new approach is based on Database.BeginTransaction(), Database.Rollback(), Database.Commit(). Yes, no more TransactionScope.
In the followi…

GET call of REST API that contains '/'-slash character in the value of a parameter

Let’s assume that we have the following scenario: I have a public HTTP endpoint and I need to post some content using GET command. One of the parameters contains special characters like “\” and “/”. If the endpoint is an ApiController than you may have problems if you encode the parameter using the http encoder.
using (var httpClient = new HttpClient()) { httpClient.BaseAddress = baseUrl; Task<HttpResponseMessage> response = httpClient.GetAsync(string.Format("api/foo/{0}", "qwert/qwerqwer"))); response.Wait(); response.Result.EnsureSuccessStatusCode(); } One possible solution would be to encode the query parameter using UrlTokenEncode method of HttpServerUtility class and GetBytes method ofUTF8. In this way you would get the array of bytes of the parameter and encode them as a url token.
The following code show to you how you could write the encode and decode methods.