{"id":2107,"date":"2013-04-22T08:00:12","date_gmt":"2013-04-22T15:00:12","guid":{"rendered":"http:\/\/www.cloudidentity.com\/blog\/?p=2107"},"modified":"2013-04-22T21:28:47","modified_gmt":"2013-04-23T04:28:47","slug":"windows-azure-authentication-library-aal-for-windows-store-a-deep-dive","status":"publish","type":"post","link":"https:\/\/www.cloudidentity.com\/blog\/2013\/04\/22\/windows-azure-authentication-library-aal-for-windows-store-a-deep-dive\/","title":{"rendered":"Windows Azure Authentication Library (AAL) for Windows Store: a Deep Dive"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image27.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image_thumb27.png\" width=\"604\" height=\"341\" border=\"0\" \/><\/a><\/p>\n<p>I have been longing to publish this post for a looong time <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/><br \/>\nToday we are announcing the next batch of preview features for Windows Azure Active Directory. You can find most details in Alex\u2019 announcement <a href=\"http:\/\/blogs.msdn.com\/b\/active_directory_team_blog\/archive\/2013\/04\/22\/developer-preview-of-oauth-code-grant-and-aal-for-windows-store-apps.aspx\"><strong>here<\/strong><\/a>, but in a nutshell:<\/p>\n<ul>\n<li>We now have endpoints capable of handling the OAuth2 code grant flow<\/li>\n<li>We are releasing a preview of the Windows Azure Authentication Library for Windows Store \u2013 it\u2019s available directly from VS as a NuGet package<\/li>\n<\/ul>\n<p>As much as I am excited about the endpoints, it\u2019s the AAL for Windows Store announcement that is making my heart racing: the DevEx team has been nurturing this baby bird for a long time, and it\u2019s finally time to let it fly.<\/p>\n<p><a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=296708\">This walkthrough<\/a> and <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=296713\">this sample<\/a> show you how to use AAL for Windows Store to add authentication capabilities to your modern Windows applications and secure calls to a Web API project. Head there to learn how to use the library, it\u2019s easy!<\/p>\n<p>In this post I will go deeper (much deeper) in the library features and share with you some design considerations behind the choices we made. I like to think that we really took advantage of what the new Windows Runtime has to offer here, but you be the judge! <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/><\/p>\n<p>This is not required reading, come along for the ride only if you are very curious about it.<\/p>\n<h2>AAL in a Nutshell<\/h2>\n<p>If you are new to AAL, you might want to take a look at the intro post <a href=\"https:\/\/www.cloudidentity.com\/blog\/2012\/11\/20\/a-refresh-of-the-windows-azure-authentication-library-developer-preview-2\/\">here<\/a>: but in brief, <em>the Windows Azure Authentication Library (AAL) makes it very easy for developers to add to their <strong>client<\/strong> applications the logic for authenticating users to Windows Azure Active Directory, and obtain access tokens for securing API calls<\/em>.\u00a0 No deep protocol expertise required!<\/p>\n<p>Here there\u2019s the laundry list of the main features in AAL for Windows Store:<\/p>\n<ul>\n<li>Easy programming model for adding Windows Azure AD authentication to Windows Store apps\n<ul>\n<li>Take advantage of your Office365 accounts to authenticate in your Windows Store apps, too!<\/li>\n<\/ul>\n<\/li>\n<li>Works with Windows 8 and Windows RT devices<\/li>\n<li>Support for multi factors authentication<\/li>\n<li>Can be used from both C# and JavaScript\/HTML5 apps<\/li>\n<li>Persistent token cache<\/li>\n<li>Automatic, just-in-time token refresh<\/li>\n<li>Token roaming across trusted devices<\/li>\n<li>easy-to-use wrap of the WebAuthenticationBroker API for business apps<\/li>\n<\/ul>\n<p>I am definitely biased, but that sounds pretty exciting to me\u2026 <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/><\/p>\n<p>AAL for Windows Store is not our first foray in the client authentication space. We already have <a href=\"https:\/\/www.cloudidentity.com\/blog\/2012\/11\/20\/a-refresh-of-the-windows-azure-authentication-library-developer-preview-2\/\">a preview of AAL<\/a> out, designed to work with client applications written with .NET 4.0 and up: that includes both apps with user interaction and server-side apps operating in a client role (e.g. middle tiers calling other services). The developer passes as parameters what he or she knows about the scenario, library itself picks up which protocols to use to make authentication happen.<br \/>\nGiven the nature of Windows Store apps, for which server to server authentication flows would not make much sense, <em>AAL for Windows Store focuses exclusively on enabling user-based, interactive authentication<\/em>. Behind the scenes, AAL for Windows Store implements that flow using the new OAuth2 code grant endpoints in Windows Azure AD.<\/p>\n<h2>Scenario and Programming Model<\/h2>\n<p>As mentioned, AAL for Windows Store tries to solve about the same class of problems tackled by AAL .NET. Here there\u2019s a short excerpt from the original announcement, describing the basic scenario from the PoV of the developer (that would be you! <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/>).<\/p>\n<ul>\n<li>I know I want to call service A, and I know how to call it<br \/>\n(e.g. REST or otherwise, which parameters\/verbs\/etc to use,\u2026)<\/li>\n<li>Without knowing other details, I know that to call A I need to present a \u201ctoken\u201d representing the user of my app<\/li>\n<li>I know that Windows Azure AD knows all the details of how to do authentication in this scenario, though I might be a bit blurry about what those details might be<\/li>\n<\/ul>\n<p><a href=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2012\/08\/7144.image_5F00_3641E549.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2012\/08\/7144.image_5F00_3641E549.png\" width=\"455\" height=\"303\" border=\"0\" \/><\/a><\/p>\n<p>AAL offers you a programming model that has counterparts for all those concepts, interlinked by the same functional relationships. In short, for Windows Store apps you implement the scenario following those 3 steps:<\/p>\n<ol>\n<li>Initialize an instance of the <strong>AuthenticationContext<\/strong> class, which represents the Windows Azure AD tenant that knows about the users and the services\/resources you want to work with<\/li>\n<li>Ask to your AuthenticationContext instance to to get a token for your client to access your target service, by invoking it method <strong>AcquireTokenAsync <\/strong>passing client and target service info\n<ol>\n<li>the library takes care of all the necessary authentication experience (though often it won\u2019t be required, see the token lifecycle section)<\/li>\n<\/ol>\n<\/li>\n<li>AcquireTokenAsync returns an <strong>AuthenticationResult<\/strong> instance. If the operation was successful, you can extract the token from its <strong>AccessToken <\/strong>property and use it to call your target service<\/li>\n<\/ol>\n<p>For once, I am not oversimplifying: that is exactly what happens. Here there\u2019s some C# code implementing the sequence, in the case in which the target resource is a REST service:<\/p>\n<div id=\"codeSnippetWrapper\">\n<div id=\"codeSnippet\" style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;\">\n<p><span id=\"lnum1\" style=\"color: #606060;\"> 1:<\/span> AuthenticationContext authenticationContext =<\/p>\n<p><span style=\"color: #0000ff;\">new<\/span> AuthenticationContext(<span style=\"color: #006080;\">&#8220;https:\/\/login.windows.net\/treyresearch1.onmicrosoft.com&#8221;<\/span>);<\/p>\n<p><!--CRLF--><\/p>\n<p><span id=\"lnum2\" style=\"color: #606060;\"> 2:<\/span> AuthenticationResult result =<\/p>\n<p>await authenticationContext.AcquireTokenAsync(\u201c<span style=\"color: #006080;\"><a href=\"http:\/\/myapps\/quotesapp\">http:\/\/myapps\/quotesapp<\/a>\u201d<\/span>,<\/p>\n<p><span style=\"color: #006080;\">&#8220;2b8606b7-6bad-4e8b-ac3c-1356aca8ab0e&#8221;<\/span>);<\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum3\" style=\"color: #606060;\">   3:<\/span> HttpClient httpClient = <span style=\"color: #0000ff;\">new<\/span> HttpClient();<\/pre>\n<p><!--CRLF--><\/p>\n<p><span id=\"lnum4\" style=\"color: #606060;\"> 4:<\/span> httpClient.DefaultRequestHeaders.Authorization =<\/p>\n<p><span style=\"color: #0000ff;\">new<\/span> AuthenticationHeaderValue(<span style=\"color: #006080;\">&#8220;Bearer&#8221;<\/span>, result.AccessToken);<\/p>\n<p><!--CRLF--><\/p>\n<p><span id=\"lnum5\" style=\"color: #606060;\"> 5:<\/span> HttpResponseMessageresponse =<\/p>\n<p>await httpClient.GetAsync(<span style=\"color: #006080;\"><a href=\"https:\/\/poorsmanas.azurewebsites.net\/api\/InspiringQuotes\">https:\/\/poorsmanas.azurewebsites.net\/api\/InspiringQuotes<\/a><\/span>);<\/p>\n<p><!--CRLF--><\/p>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Please note, AAL is actually used just in the first 2 lines: the rest shows how to use the resulting token to call a REST service, all standard .NET code. Let\u2019s see what happens in a bit more detail, line by line.<\/p>\n<ol>\n<li>This line creates an instance of AuthenticationContext tied to the Windows Azure AD tenant TreyResearch1.<\/li>\n<li>Here we ask to our AuthenticationContext to get for us a token to access the service identified by the URI \u201chttp:\/\/myapps\/quotesapp\u201d. In order to do so, the corresponding Windows Azure AD tenant must know the client app originating the request, hence we provide the ID identifying the app as well (more details later). Here two things can happen:\n<ol>\n<li>the call returns right away, in case a suitable token is already available in the cache (more details in the section about caching)<\/li>\n<li>the call triggers the display of the WinRT\u2019s <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/apps\/windows.security.authentication.web.webauthenticationbroker.aspx\">WebAuthenticationBroker<\/a> dialog, presenting the user with the Windows Azure AD authentication experience.\n<p>Assuming that the authentication took place successfully<\/li>\n<\/ol>\n<\/li>\n<li>We create a new HttpClient<\/li>\n<li>We add an HTTP Authorization header, containing the token obtained in #2 and formatted according to the OAuth2 bearer resource access style<\/li>\n<li>We invoke the service; the presence of the token in the header provides the access info that the resource needs to verify before granting access.<\/li>\n<\/ol>\n<p>\u2026and that\u2019s all you need to do! <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/><\/p>\n<h3>More About the Object Model<\/h3>\n<p>The AAL developer surface is really reduced to the essential, however there is a bit more to it than the absolute basic scenario described above. In the fullness of time we\u2019ll have a complete MSDN reference, but for the time being here there\u2019s a quick glance at the main primitives.<\/p>\n<h4>AuthenticationContext<\/h4>\n<p>AuthenticationContext is the proxy of your Windows Azure AD tenant; it is the primitive you use every time you need your tenant to do something for you. In some sense, AuthenticationContext *is* AAL. Here there\u2019s some more details on how it works.<\/p>\n<h5>Construction<\/h5>\n<p>The code snippet above showed the main way of constructing an AuthenticationContext: you pass the complete URL of your Windows Azure AD tenant. In the future we will offer some kind of resource-driven discovery mechanism, but for the time being the explicit, full URL is required at construction time. Also note: if you pass a string of a format different from the login.windows.net\/&lt;tenant&gt; one, AAL validation of the tenant URL template will fail: that is for preventing redirect attacks in case you have dynamic logic that determines the tenant\u2019s URL. There is an overload of the constructor which allows you to turn validation off, should you need to do so for development purposes.<\/p>\n<p style=\"border: 2px solid;\">IMPORTANT. Whereas AAL .NET works with both ACS2.0 namespaces and Windows Azure AD tenants, <em>AAL for Windows Store works only with Windows Azure AD tenants<\/em>.<br \/>\nThis is largely a function of the protocol types supported by the WebAuthenticationBroker, and the availability of such protocols on the service side. AAL for Windows Store engages with Windows Azure AD via the new code grant endpoints, but those endpoints are not available for ACS namespaces.<\/p>\n<h5>Method AcquireTokenAsync<\/h5>\n<p>You already encountered the simplest form of AcquireTokenAsync:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;\">IAsyncOperation&lt;AuthenticationResult&gt; AcquireTokenAsync(<span style=\"color: #0000ff;\">string<\/span> resource, <span style=\"color: #0000ff;\">string<\/span> clientId);<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<p>This overload requires you to pass (hence know) the URI and the ID with which the Windows Azure AD knows the target resource and your client application, respectively.<\/p>\n<p>If you know how the OAuth2 code grant flow you might be wondering what return URI is used, given that none is being passed as a parameter: well, in this case we use the URI assigned to the app by the Windows Runtime itself, the one of the form<strong> ms-app\/\/&lt;SID&gt;<\/strong>. You\u2019ll read more about this in the section on Windows Store features; here I\u2019ll just say that the use of such URI will cause the WebAuthenticationBroker used during authentication to operate in \u201cSSO mode\u201d.<\/p>\n<p>AcquireTokenAsync has another overload, taking far more parameters:<\/p>\n<div id=\"codeSnippetWrapper\">\n<p>IAsyncOperation&lt;AuthenticationResult&gt; AcquireTokenAsync(<span style=\"color: #0000ff;\">string<\/span> resource, <span style=\"color: #0000ff;\">string<\/span> clientId,<\/p>\n<p><span style=\"color: #0000ff;\">string<\/span> redirectUri, <span style=\"color: #0000ff;\">string<\/span> loginHint, <span style=\"color: #0000ff;\">string<\/span> extraQueryParameters);<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<p>The first two parameters are the same as the ones in the first overload.<\/p>\n<p><strong>redirectUri<\/strong> allows you to specify a return URI different from the one assigned to the client by the Windows Runtime. There are multiple reasons for which you might want to do this: the entry representing the client app in Windows Azure AD might use an arbitrary value; you might want to opt out from WebAuthenticationBroker\u2019s SSO mode for this call ; and so on.<\/p>\n<p><strong>loginHint<\/strong> allows you to specify the username (e.g. <a href=\"mailto:adam@treyresearch1.onmicrosoft.com\">adam@treyresearch1.onmicrosoft.com<\/a>) of the user you want to use for this specific authentication operation. The value of loginHint will be used to filter the token cache entries, selecting only the ones that match; if no cache entries for the username and the resource exist, the loginHint value is used for initializing the username textbox in the authentication dialog.<\/p>\n<p><strong>extraQueryParameters <\/strong>is there for giving you more latitude. The Windows Azure AD authorization server might accept more parameters in the future, and we don\u2019t want AcquireTokenAsync to get too long. Talking in OAuth2 terms, extraQueryParameter can be used for adding whatever extra info you want to send with the token request to the authorization endpoint.<\/p>\n<p>To be completely transparent, personally I am not very happy of having just 2 overloads: I would have wanted to have at least another one taking resource, client id and an arbitrary return URL\u2026 but I lost that battle <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/>. As you guys send us feedback, we\u2019ll have more data on how you use AcquireTokenAsync and on if we need to add more overloads.<\/p>\n<h5>Property TokenCache<\/h5>\n<p>By default, successful invocations of AcquireTokenAsync result in the storing in a persistent cache of the requested token. AAL for Windows Store comes equipped with such persistent cache out of the box: you can find more details about that later in the post.<\/p>\n<p>If you need to customize the caching logic, you can write your own cache (implementing the <strong>ITokenCache<\/strong> interface) and use it instead of the default one: all you need to do is to create an instance of your custom class and assign it to the TokenCache property.<\/p>\n<p>If you want to get rid of caching altogether, all you need to do is assigning TokenCache to null.<\/p>\n<h5>Method AcquireTokenbyRefreshTokenAsync<\/h5>\n<div>\n<p>IAsyncOperation&lt;AuthenticationResult&gt; AcquireTokenByRefreshTokenAsync(<\/p>\n<p><span style=\"color: #0000ff;\">string<\/span> refreshToken, <span style=\"color: #0000ff;\">string<\/span> clientId);<\/p>\n<\/div>\n<div>If for some reason you don\u2019t want to (or can\u2019t) take advantage of the automatic refresh of tokens offered by the AAL cache, you have the opportunity of getting matters in your own hands. The method <strong>AcquireTokenbyRefreshTokenAsync<\/strong> (yep, we plan to improve the name: any ideas?) allows you to pass a refresh token (usually obtained from a former call to AcquireTokenAsync) and a client ID to trigger a token refresh.<\/div>\n<div><\/div>\n<h4>AuthenticationResult<\/h4>\n<p>All token acquisition operations result in an <strong>AuthenticationResult <\/strong>instance. Its purpose is to carry to your code the outcome of the authentication, so that you can make use of it: that typically materializes as extracting access tokens to be used in your service invocations, or examining error info if something went wrong.<\/p>\n<p>Here there\u2019s the full list of public members:<\/p>\n<h5>Property AuthenticationStatus Status<\/h5>\n<p>Communicates the outcome of the authentication operation. Possible values, from the enum AuthenticationStatus, are <strong>Succeeded<\/strong> and <strong>Failed<\/strong>.<\/p>\n<h5>Property string AccessToken<\/h5>\n<p>Upon successful authentication (or positive cache hit) this property holds the bits of the token intended to be used for the target resource.<\/p>\n<h5>Property DateTime ExpiresOn<\/h5>\n<p>This value indicates the time at which the token will expire.<\/p>\n<h5>Property string RefreshToken<\/h5>\n<p>If emitted by the authentication operation, this property returns a token that can be sued to refresh the access token without having to prompt the user for credentials.<\/p>\n<h5>Properties string Error, string ErrorDescription<\/h5>\n<p>In case of error those two properties surface details about the issue, so that it can be dealt with appropriately. Returning errors in the status makes error handling in asynchronous situations easier than through classic exceptions; that is especially evident when working in JavaScript.<\/p>\n<h2>Windows Store Exclusive Features<\/h2>\n<p>The Windows Runtime API, coupled with the Windows Store apps \u201csandboxing\u201d system, offers an extremely powerful platform to build on. Here there\u2019s a list of the areas in which AAL takes advantage of Windows Runtime specific features to help you handling authentication as smoothly as possible.<\/p>\n<h3>AAL for Windows Store is a Windows Runtime Component<\/h3>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image26.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image_thumb26.png\" width=\"600\" height=\"339\" border=\"0\" \/><\/a><\/p>\n<p>There are many languages you can choose from when it comes to developing Windows Store applications: C#, JavaScript\/HTML5, C++\u2026 we wanted to make sure you retain that freedom when you use AAL.<\/p>\n<p>As its .NET counterpart, AAL for Windows Store is a library meant to live in-process with your application. However, AAL for Windows Store does <em>not <\/em>come as an assembly\/DLL: that would constrain its usage to Windows Store apps written in C# and VB.<br \/>\nAAL for Windows Store it is packaged as a <strong><span style=\"text-decoration: underline;\">Windows Runtime Component<\/span><\/strong>, a file with extension .winmd.<\/p>\n<p>You can head to MSDN for a more accurate description, but in super-short: a Windows Runtime Component is a reusable library, written in either C# or C++, which takes advantage of the language projection mechanisms of the Windows Runtime. The basic idea is that if your library exposes only Windows Runtime types, and it is packaged appropriately, then your classes can be transparently projected in the syntax of each of the languages supported for Windows Store apps development. In our case, that means that with a single library we can enable both C# and JS\/HTML5 based apps to take advantage of Windows Azure AD. That\u2019s pretty sweet! <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/><\/p>\n<p>P.S: in theory the library should also work for Windows Store apps written in C++\/CX. However at packaging time the NuGet support for distributing Windows Runtime Components did not cover C++ project types. If you really want to experiment with that you can get the NuGet package and extract the WINMD by hand, however you should know that the scenario is untested. Please let us know if you use C++ a lot for your business Windows Store apps!<\/p>\n<h3>WebAuthenticationBroker and App Capabilities<\/h3>\n<p>AAL for .NET hosts the authentication experience in a dialog containing a WebBrowser control. With AAL for Windows Store, however, we did not need to build such dialog: the Windows Runtime already offers a specific API providing a surface for rendering Web content at authentication time. That API is exposed through the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/apps\/windows.security.authentication.web.webauthenticationbroker.aspx\">WebAuthenticationBroker<\/a> class.<\/p>\n<p>The WebAuthenticationBroker (can I call it WAB from now on? it\u2019s really long to type <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/>) is very handy: it\u2019s basically a system dialog, with fixed rules for size, positioning and consistent look &amp; feel, which providers are standardizing on. It also takes specific steps for maintaining a level of isolation between the app itself and the context in which the authentication takes place.<\/p>\n<p>Used directly, the WAB requires the developer to provide in input protocol-specific information. For example, if you want to use it for driving an OAuth2 code grant flow you\u2019d have to construct the exact URL containing the request for the authorization endpoint; and once you\u2019d get back the code, you\u2019d be responsible to parte the request to retrieve it and use it to hit the token endpoint with the right message format.<\/p>\n<p>AAL for Windows Store fully wraps the WAB, presenting you with an object model that is only concerned with the actors coming into play in your solution (your client, the windows azure AD tenant, the resource you want to access)\u00a0 and making all of the necessary calls on your behalf. Hence, in theory you would not even need to know that the WAB is the API used to render the auth UI.<br \/>\nIn practice, the WAB has useful features that can be used even when wrapped hence it\u2019s worth calling it out. The main one, I\u2019d say, is the way in which it handles cookies.<\/p>\n<h4>AAL and WAB\u2019s Cookie Management<\/h4>\n<p>Authentication cookies management in Windows Store is less straightforward than on the classic desktop, and that influences how AAL for Windows Store operates.<\/p>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image28.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image_thumb28.png\" width=\"600\" height=\"371\" border=\"0\" \/><\/a><\/p>\n<p>When you use AcquireTokenAsync without specifying a return URL, AAL invokes the WAB in \u201c<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/apps\/xaml\/jj856909.aspx\">SSO mode<\/a>\u201d. In a nutshell that means that the WAB will expect the auth provider to deliver its results by redirecting toward a special URI of the form ms-app:\/\/&lt;SID&gt; where the SID is the package ID of the Windows Store application. In return for this proof of tight coupling between the authority and the app itself, the WAB will grant access to a persistent cookie jar shared by all SSO mode applications: that will allow taking advantage of information associated to previous runs (such as persistent cookies) and occasionally achieve the SSO that gives the name to this mode. If App1 authenticated with Authority A in SSO mode, and A dropped a persistent cookie to represent an ongoing session, App2 opening the WAB in SSO mode will be able to authenticate with A by leveraging the existing cookie.<\/p>\n<p>When you use AcquireTokenAsync specifying an arbitrary return URL, that value is passed straight to the WAB. And then the WAB operates on an arbitrary return URL, it assumes a \u201clow trust\u201d connection with the provider and constrains execution against a brand-new empty cookie jar. That is for protecting the user from low-trust apps, which could leverage existing cookies to silently access data on the web sites the user is authenticated with.<\/p>\n<p>That\u2019s pretty handy! But, say, what if you want to take advantage of SSO mode (which you automatically get with the simplest AcquireTokenAsync) while also specifying the login_hint for the current user? Easy. You can use the longer AcquireTokenAsync overload, and pass as return URI the address that the WAB would use if you would not specify any. You can obtain that programmatically by calling <strong>WebAuthenticationBroker.GetCurrentApplicationCallbackUri()<\/strong>.<\/p>\n<h4>Windows Store Application Capabilities<\/h4>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image29.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image_thumb29.png\" width=\"604\" height=\"298\" border=\"0\" \/><\/a><\/p>\n<p>Windows Store applications are executed in a sandboxed environment, which limits what they can do with system resources to the things that the user explicitly allowed at install time.<\/p>\n<p>Being Windows Azure AD meant to enable business scenarios, the use of AAL for facilitating authentication flows will more often than not entail access to enterprise resources and capabilities such as<\/p>\n<ul>\n<li>Ability to navigate to intranet locations<\/li>\n<li>Ability to leverage domain authentication for the current user<\/li>\n<li>Ability to access certificate stores and smartcards for multifactor authentication<\/li>\n<\/ul>\n<p>Windows Store applications can do none of those things, unless you explicitly enable them in the capabilities section of the Package.appxmanifest file. And given that it\u2019s really impossible for us to know in advance what will be required (that\u2019s really driven by the Windows Azure AD tenant: is it federated with a local ADFS2 instance? Does it require certificate based auth?) and even if you\u2019d know at a given time, the authenticating authority can change policy much faster than your app\u2019s install\/update lifecycle.<\/p>\n<p>For those reasons, if you don\u2019t turn on those capabilities in your manifest AAL might not work as expected. This is another area for which we are eager to get your feedback: is it acceptable for your business and enterprise apps to request those capabilities? Let us know about your scenarios, it will be of tremendous help for us to understand how to handle those aspects moving forward.<\/p>\n<h3>Token Lifecycle: Persistent Cache, Automatic Refresh, Roaming<\/h3>\n<p>Ah, I finally get to write about my favorite feature of the release: automatic token lifecycle.<\/p>\n<p>Besides the protocol and security details, one of the main pain points of working with authentication in rich clients is having to handle sessions. Obtaining a token is only the start: if you want to access the protected resource more than once, you need to save the token somewhere; retrieve it when you need it again, possibly after the app has been closed and reopened; verify that it is still valid; if you have more than one resource, ensure that you are retrieving the right token; and so on. You normally have to worry about all that, while at the same time minimizing the times in which you prompt the user for credentials without adding any security horrors in the process. OAuth2 provides a super-useful artifact for handling that, the refresh token, however that comes at the cost of extra moving parts in the session management logic.<\/p>\n<p>What if I\u2019d tell you that AAL for Windows Store takes care of all that for you, without requiring any explicit action? <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/><\/p>\n<p>By default, AAL for Windows Store engages with a persistent token cache every single time you invoke AcquireTokenAsync. The cache entry structure is shown below:<\/p>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image30.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; margin-right: auto; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image_thumb30.png\" width=\"240\" height=\"217\" border=\"0\" \/><\/a><\/p>\n<p>Further below you can find a flowchart describing exactly what happens, but for the ones among you preferring text to visuals:<\/p>\n<p>Say that you invoke AcquireTokenAsync passing myresource, myclientid, and myloginhint (the other parameters are not used in the cache).<br \/>\nAAL looks up in the cache if there is an entry matching the Windows Azure AD tenant associated to the current AuthenticationContext, myresource and myclientid, myloginhint.<\/p>\n<ol>\n<li>if there is an entry\n<ol>\n<li>is there a valid access token?\n<ol>\n<li><strong>if there is, return the cache entry right away<\/strong><\/li>\n<li>if there isn\u2019t\n<ol>\n<li>is there a refresh token?\n<ol>\n<li>if there is, use it\n<ol>\n<li>if the refresh succeeded, <strong>replace the old entry and return it<\/strong><\/li>\n<li>if the refresh did not succeed, prompt the user for auth\n<ol>\n<li>if successful, <strong>save results in cache and return <\/strong><\/li>\n<li>if unsuccessful, <strong>return error info<\/strong><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li>if there isn\u2019t, prompt the user for auth\n<ol>\n<ol>\n<li>if successful, <strong>save results in cache and return<\/strong><\/li>\n<li>if unsuccessful, <strong>return error info<\/strong><\/li>\n<\/ol>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li>if there isn\u2019t, prompt the user for auth\n<ol>\n<li>if successful, <strong>save results in cache and return<\/strong><\/li>\n<li>if unsuccessful, <strong>return error info<\/strong><!--EndFragment-->\n<p><!--EndFragment--><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Flowchart:<\/p>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image31.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image_thumb31.png\" width=\"600\" height=\"485\" border=\"0\" \/><\/a><\/p>\n<p>The bottom line is: <strong><em><span style=\"color: #ff0000;\">use <span style=\"text-decoration: underline;\">AcquireTokenAsync<\/span> every time you need a token<\/span><\/em><\/strong>. AAL will take care of querying the cache for you and even transparently refresh when necessary. The user will be prompted only when there\u2019s absolutely no other alternative.<\/p>\n<p>In this release the default cache implementation is very simple: everything is handled transparently, the only explicit operation you can do is flushing its content via the <strong>Clean()<\/strong> method. The next refresh will offer a more sophisticated cache, offering fine grained access to the entries.<br \/>\nAAL uses the default cache implementation using the ITokenCache interface methods, which means that you can plug in your own cache implementation if you so choose. In this phase, however, I would rather\u00a0 have you guys tell us which features you\u2019d like in the default cache, so that we can incorporate them and give you the best experience right out of the box.<\/p>\n<h4>AAL for Windows Store Cache and Windows\u2019 Password Vault<\/h4>\n<p>Windows 8 and Windows RT have a great feature, the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/apps\/windows.security.credentials.passwordvault.aspx?cs-save-lang=1&amp;cs-lang=csharp#code-snippet-1\">Password Vault<\/a>, which is what allowed us to easily set up a persistent token cache.<\/p>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image35.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image_thumb35.png\" width=\"600\" height=\"481\" border=\"0\" \/><\/a><\/p>\n<p>The idea is pretty simple: every Windows Store app have one secure store that can be used for saving credentials, accessed via the PasswordVault class.<br \/>\nWithin the Windows Runtime execution environment, <strong><em>data saved in that area can only be accessed by the app that wrote them, when operated by the user that was logged in Windows at save time<\/em><\/strong>.<\/p>\n<p>Can you believe it? A per-app isolated area, which survives across multiple launches of the app, right out of the box! That was just the perfect fit for a persistent token cache. AAL uses the PasswordVault as a flat store for the cache entries of the form described earlier: there is no direct connection to a particular\u00a0 AuthenticationContext instance, given that every entry is keyed per authority there\u2019s really no need for it; every cache operation goes straight to the Vault app-wide.<\/p>\n<p>As added bonus, the use of the PasswordVault grants to AAL\u2019s cache a very interesting capability: <strong>cross-devices roaming of the saved tokens<\/strong>. In short: say that you install App1 on one of your Windows 8 or Windows RT devices and you authenticate using it. Say that you pick up another device of yours, and you install App1 there as well. At first launch of App1 you might discover that you are already authenticated without the need of entering any credentials!<\/p>\n<p>I can\u2019t say that we did this intentionally, that was not a feature high in the stack, but it just comes with the use of the Vault. In fact, there\u2019s really nothing we can do to influence it from code: the way in which roaming takes place is more of a function of how your user\u2019s machines are configured. The rules determining how roaming takes place are summarized in the picture above.<br \/>\nIn summary:<\/p>\n<ul>\n<li><em>outgoing <\/em>roaming only happens if the user is signed in the machine with a Microsoft Account AND the machine is listed as a trusted device in the corresponding Microsoft Account settings.\n<ul>\n<li>However if the machine is also domain joined, outgoing roaming does NOT take place.<\/li>\n<\/ul>\n<\/li>\n<li><em>inbound <\/em>roaming happens on devices where the same originating app is installed, the receiving device is marked as trusted by the same Microsoft Account, and the Microsoft Account (or a domain account linked to that Microsoft Account) is present on the device<\/li>\n<\/ul>\n<p>If you refer to those rules there should be no surprise roams: if you don\u2019t want roam to happens you can enforce your choices via devices settings or by opting out from the default caching implementation altogether.<\/p>\n<p>All in all, pretty awesome <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/><\/p>\n<h2>Client Registration and Permissions Settings<\/h2>\n<p>In closing of this long deep dive, I want to mention few things that are not strictly inherent to AAL itself, but are aspects of working with Windows Azure AD and rich clients you have to be aware of.<\/p>\n<p>If you\u2019ve been using AAL .NET for authenticating against services, or in fact wrote <em>any<\/em> rich client accessing protected remote resources in the last 10 years or so, you are already familiar with the authentication model: there is an authority that knows about the service you want to invoke, and that knows how to authenticate you; if you can prove who you are, you get a token that grants you access to the service. In that picture, it does not really matter which rich client you are using: if you write code that implements that flow in a WPF app you can copy &amp; paste it as is in any other WPF app, WinForm app, Excel plugin, Visual Studio extension and whatever else comes to mind without having to change anything on the authority and service side.<\/p>\n<p>Well, the above holds for classic authentication protocols; but it does not (usually) hold anymore when you use an authorization framework like OAuth2, which happens to be what is used by AAL for Windows Store to drive the authentication flow.<\/p>\n<p>I won\u2019t repeat here <a href=\"https:\/\/www.cloudidentity.com\/blog\/2013\/01\/02\/oauth-2-0-and-sign-in-4\/\">the mega-post I wrote on the relationship between OAuth2 and sign on<\/a>, nor I will start a dissertation about whether accessing a protected resource from a rich client amounts to \u201csign in\u201d; those will come in some future post. Here I\u2019ll just list some practicalities about how things are different and what to do about it to make AAL for Windows Store work in your apps.<\/p>\n<p>The idea here is that you are not as much authenticating the user; rather, you are authorizing the app to access the resource on behalf of the user. The idea might sound subtle, but once again it has important consequences.<\/p>\n<h3>App Registration<\/h3>\n<p>The first consequence is that now the identity of the client application <em>does<\/em> matter. No longer just a transparent extension of the user, the app in itself is an active actor whose identity has an impact on whether access will be granted or denied: the exact same user might gain access to a resource when using App1, but see his\/here requests denied when using App2. As such,\u00a0 <strong><span style=\"text-decoration: underline;\"><em>your client apps need to be registered in your Windows Azure AD tenant<\/em><\/span><\/strong>.<\/p>\n<p>As counterintuitive as it might sound, the entity used for representing your client is a ServicePrincipal <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/> or in fact an Application object (see <a href=\"https:\/\/www.cloudidentity.com\/blog\/2013\/04\/16\/the-windows-azure-ad-application-model\/\">here<\/a> for more details).<\/p>\n<p>Here there\u2019s a dump of the Application object representing one of my test clients:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;\">{\r\n     <span style=\"color: #006080;\">\"odata.type\"<\/span>: <span style=\"color: #006080;\">\"Microsoft.WindowsAzure.ActiveDirectory.Application\"<\/span>,\r\n     <span style=\"color: #006080;\">\"objectType\"<\/span>: <span style=\"color: #006080;\">\"Application\"<\/span>,\r\n     <span style=\"color: #006080;\">\"objectId\"<\/span>: <span style=\"color: #006080;\">\"d22366d4-2692-4074-a079-0eabad5dbaa3\"<\/span>,\r\n     <span style=\"color: #006080;\">\"appId\"<\/span>: <span style=\"color: #006080;\">\"2b8606b7-6bad-4e8b-ac3c-1356aca8ab0e\"<\/span>,\r\n     <span style=\"color: #006080;\">\"availableToOtherTenants\"<\/span>: <span style=\"color: #0000ff;\">false<\/span>,\r\n     <span style=\"color: #006080;\">\"displayName\"<\/span>: <span style=\"color: #006080;\">\"Todo Client\"<\/span>,\r\n     <span style=\"color: #006080;\">\"errorUrl\"<\/span>: <span style=\"color: #0000ff;\">null<\/span>,\r\n     <span style=\"color: #006080;\">\"homepage\"<\/span>: <span style=\"color: #0000ff;\">null<\/span>,\r\n     <span style=\"color: #006080;\">\"identifierUris\"<\/span>: [\r\n       <span style=\"color: #006080;\">\"ms-app:\/\/s-1-15-2-4261528085-3522513112-2976465067-1243652757-3393620086-3686240607-3579810098\/\"<\/span>\r\n     ],\r\n     <span style=\"color: #006080;\">\"keyCredentials\"<\/span>: [],\r\n     <span style=\"color: #006080;\">\"mainLogo@odata.mediaContentType\"<\/span>: <span style=\"color: #006080;\">\"image\"<\/span>,\r\n     <span style=\"color: #006080;\">\"logoutUrl\"<\/span>: <span style=\"color: #0000ff;\">null<\/span>,\r\n     <span style=\"color: #006080;\">\"passwordCredentials\"<\/span>: [],\r\n     <span style=\"color: #006080;\">\"publicClient\"<\/span>: <span style=\"color: #0000ff;\">true<\/span>,\r\n     <span style=\"color: #006080;\">\"replyUrls\"<\/span>: [\r\n       <span style=\"color: #006080;\">\"ms-app:\/\/s-1-15-2-4261528085-3522513112-2976465067-1243652757-3393620086-3686240607-3579810098\/\"<\/span>\r\n     ],\r\n     <span style=\"color: #006080;\">\"samlMetadataUrl\"<\/span>: <span style=\"color: #0000ff;\">null<\/span>\r\n   }<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<p>The schema is the same, but it is used a bit differently: without going too much in details, note the appId (which in AAL for Windows Store is used as clientid in AcquireTokenAsync) and the reply URL, which happens to be one of the SSO ones that the WAB likes.<\/p>\n<p>The corresponding ServicePrincipal (from now on SP) is not terribly interesting, but I\u2019ll paste it anyway in case you are curious:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;\">{\r\n      <span style=\"color: #006080;\">\"odata.type\"<\/span>: <span style=\"color: #006080;\">\"Microsoft.WindowsAzure.ActiveDirectory.ServicePrincipal\"<\/span>,\r\n      <span style=\"color: #006080;\">\"objectType\"<\/span>: <span style=\"color: #006080;\">\"ServicePrincipal\"<\/span>,\r\n      <span style=\"color: #006080;\">\"objectId\"<\/span>: <span style=\"color: #006080;\">\"47ed0cac-fb08-4f3c-844f-96fecefdc165\"<\/span>,\r\n      <span style=\"color: #006080;\">\"accountEnabled\"<\/span>: <span style=\"color: #0000ff;\">true<\/span>,\r\n      <span style=\"color: #006080;\">\"appId\"<\/span>: <span style=\"color: #006080;\">\"2b8606b7-6bad-4e8b-ac3c-1356aca8ab0e\"<\/span>,\r\n      <span style=\"color: #006080;\">\"displayName\"<\/span>: <span style=\"color: #006080;\">\"Todo Client\"<\/span>,\r\n      <span style=\"color: #006080;\">\"errorUrl\"<\/span>: <span style=\"color: #0000ff;\">null<\/span>,\r\n      <span style=\"color: #006080;\">\"homepage\"<\/span>: <span style=\"color: #0000ff;\">null<\/span>,\r\n      <span style=\"color: #006080;\">\"keyCredentials\"<\/span>: [],\r\n      <span style=\"color: #006080;\">\"logoutUrl\"<\/span>: <span style=\"color: #0000ff;\">null<\/span>,\r\n      <span style=\"color: #006080;\">\"passwordCredentials\"<\/span>: [],\r\n      <span style=\"color: #006080;\">\"publisherName\"<\/span>: <span style=\"color: #006080;\">\"Microsoft AAA\"<\/span>,\r\n      <span style=\"color: #006080;\">\"replyUrls\"<\/span>: [\r\n        <span style=\"color: #006080;\">\"ms-app:\/\/s-1-15-2-4261528085-3522513112-2976465067-1243652757-3393620086-3686240607-3579810098\/\"<\/span>\r\n      ],\r\n      <span style=\"color: #006080;\">\"samlMetadataUrl\"<\/span>: <span style=\"color: #0000ff;\">null<\/span>,\r\n      <span style=\"color: #006080;\">\"servicePrincipalNames\"<\/span>: [\r\n        <span style=\"color: #006080;\">\"ms-app:\/\/s-1-15-2-4261528085-3522513112-2976465067-1243652757-3393620086-3686240607-3579810098\/\"<\/span>,\r\n        <span style=\"color: #006080;\">\"2b8606b7-6bad-4e8b-ac3c-1356aca8ab0e\"<\/span>\r\n      ],\r\n      <span style=\"color: #006080;\">\"tags\"<\/span>: []\r\n    }<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<p>\u2026all pretty standard.<\/p>\n<h3>Permissions<\/h3>\n<p>As of today, registering the client is necessary but not sufficient condition for your app to access a service. You need to let your Windows Azure AD tenant know that your app has the necessary permissions to access the service(s) you are targeting.<\/p>\n<p>That can be achieved by adding a suitable entry in yet another new entity, the Permissions collection. Such entry must tie the SP\u2019s entry of your client with the SP entry of the target service, and declare the access level the client should enjoy. Here there\u2019s the entry enabling the client described above:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;\">{\r\n      <span style=\"color: #006080;\">\"clientId\"<\/span>: <span style=\"color: #006080;\">\"47ed0cac-fb08-4f3c-844f-96fecefdc165\"<\/span>,\r\n      <span style=\"color: #006080;\">\"consentType\"<\/span>: <span style=\"color: #006080;\">\"AllPrincipals\"<\/span>,\r\n      <span style=\"color: #006080;\">\"expiryTime\"<\/span>: <span style=\"color: #006080;\">\"9999-12-31T23:59:59.9999999\"<\/span>,\r\n      <span style=\"color: #006080;\">\"objectId\"<\/span>: <span style=\"color: #006080;\">\"rAztRwj7PE-ET5b-zv3BZcw8dYEmKBdGl7heaQ_BLzU\"<\/span>,\r\n      <span style=\"color: #006080;\">\"principalId\"<\/span>: <span style=\"color: #0000ff;\">null<\/span>,\r\n      <span style=\"color: #006080;\">\"resourceId\"<\/span>: <span style=\"color: #006080;\">\"81753ccc-2826-4617-97b8-5e690fc12f35\"<\/span>,\r\n      <span style=\"color: #006080;\">\"scope\"<\/span>: <span style=\"color: #006080;\">\"user_impersonation\"<\/span>,\r\n      <span style=\"color: #006080;\">\"startTime\"<\/span>: <span style=\"color: #006080;\">\"0001-01-01T00:00:00\"<\/span>\r\n }<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<p>Now, don\u2019t get confused! The clientId here is not the clientid you\u2019d use in AAL for Windows Store for identifying the client (that would be the SP\u2019s appId). Rather, it is the <em>objectId<\/em> of the SP representing the client; you can verify by comparing with the earlier entries.<br \/>\nThe resourceId, I am sure you already guessed it, is the objectId of the SP representing the service.<\/p>\n<p>The other interesting value there is scope: the ones among you familiar with OAuth2 will recognize it. In short, that\u2019s simply the kind of access the client has to the service: in this case, accessing it as the user (which for interactive rich apps is pretty much the equivalent of the more traditional user authentication flows).<\/p>\n<p>With that entry, Windows Azure AD has all it needs for enabling the scenario. All you need to do is plugging the correct values in the AAL for Windows Store API, hit F5 and watch the magic unfold.<\/p>\n<h3>The Graph Explorer<\/h3>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image33.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image_thumb33.png\" width=\"636\" height=\"424\" border=\"0\" \/><\/a><\/p>\n<p>Although you can &#8211; if you so choose &#8211; create the entries for the client app and the permission element directly via the Graph API, you don\u2019t have to.<\/p>\n<p>The <a href=\"https:\/\/graphexplorer.cloudapp.net\/\">Graph Explorer<\/a> has been updated to help you do both tasks with just few clicks: the <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=296708\">walkthrough<\/a> and the <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=296713\">sample<\/a> guide you though the exact procedure you need to follow.<\/p>\n<p>Note: the entries for your clients will appear in the Windows Azure portal, alongside the ones of the Web apps you are creating following the GA path. For now the portal does not expose the necessary settings: I\u2019ll ask what the official guidance is, but for the time being my recommendation (you do remember my disclaimer, right?) would be to avoid modifying those entries via web UI.<\/p>\n<h2>2FA!<\/h2>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image34.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/image_thumb34.png\" width=\"604\" height=\"342\" border=\"0\" \/><\/a><\/p>\n<p>A short note here to highlight that the same tricks for <a href=\"https:\/\/www.cloudidentity.com\/blog\/2013\/03\/04\/want-multi-factor-authentication-when-accessing-web-services-try-aal-and-aad\/\">supporting multi factor authentication shown in this post for AAL .NET<\/a> will work for AAL for Windows Store, too: just authenticate as a user who was marked for 2Fa, and watch your Windows Store app gain an extra level of authentication assurance without changing a line of code <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/><\/p>\n<h2>Next<\/h2>\n<p>Well, I promised a long post, and a long post you got.<\/p>\n<p>I know that the ability of using Windows Azure AD from Windows Store apps was one of the most requested features in the past few months, and I can\u2019t tell you how impatient I am to see how you will use this preview <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-smile6.png\" \/><\/p>\n<p>You can expect the next update to AAL .NET to incorporate some of the innovations we have in AAL for Windows Store, like the use of AuthenticationResult as a return type and the support for the OAuth2 code grant flow. How much of the rest makes its way back in the library, and how AAL for Windows Store, will in large part depend on your feedback. Happy coding <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-winkingsmile\" alt=\"Winking smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/04\/wlEmoticon-winkingsmile4.png\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; I have been longing to publish this post for a looong time Today we are announcing the next batch of preview features for Windows Azure Active Directory. You can find most details in Alex\u2019 announcement here, but in a nutshell: We now have endpoints capable of handling the OAuth2 code grant flow&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2119,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2107","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/2107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/comments?post=2107"}],"version-history":[{"count":16,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/2107\/revisions"}],"predecessor-version":[{"id":2147,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/2107\/revisions\/2147"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media\/2119"}],"wp:attachment":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media?parent=2107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/categories?post=2107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/tags?post=2107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}