AcquireTokenAsync fails in a UWP app

0

I'm using ADAL in my Win10 UWP app. Here is a snippet of code:

// WinRT, UWP app. Doesn't work
TokenCache TC = new TokenCache();
authContext = new AuthenticationContext(authority, true, TC);
var authresult = await authContext.AcquireTokenAsync(resourceUri, clientID, new Uri(redirectUri));
token = authresult.AccessToken;

Sometimes it fails with the following error, without ever bringing up the auth window:

authentication_ui_failed: The browser based authentication dialog failed to complete. Value does not fall within the expected range.

Occasionally, it does bring up the auth window but fails to redirect, producing:

"authentication_ui_failed: The browser based authentication dialog failed to complete. The system cannot locate the resource specified. (Exception from HRESULT: 0x800C0005)"

This uses a WinRT version of the library. A similar code using .NET version works great from the console app:

// .NET, console app. Works great
TokenCache TC = new TokenCache();
authContext = new AuthenticationContext(authority, TC);
var authresult = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri));
token = authresult.AccessToken;
azure-active-directory
adal
asked on Stack Overflow Jul 31, 2015 by arturl • edited Jul 31, 2015 by arturl

1 Answer

2

This is typically caused by the sandboxing of store and UWP apps. At a minimum, the redirect uri of the app should match the one assigned by the runtime - see the windows store sample on github.com/azuread. Other things that might impact the behavior are privacy settings on the box, use of local network without asking for the correct capabilities..: all the restrictions that apply to windows store apps will apply to the use of ADAL as well. Also: can I ask you why you are passing a custom cache to the app? That's not usual for apps running on sandboxes environments like the windows store apps.

answered on Stack Overflow Jul 31, 2015 by vibronet

User contributions licensed under CC BY-SA 3.0