简体   繁体   中英

ADAL for Windows Phone 8.1 Problems

I'm creating a Windows Phone 8.1 app (Windows Runtime) that will need to authenticate against an Azure Active Directory OAuth endpoint. I'm using the ADAL for WP81 nuget package as the authentication manager to get the OAuth token back.

The problem I am struggling with, is where I need to call the various ADAL Login methods in the Phone page lifecycle. Right now I'm calling AuthenticationContext.AquireTokenAndContine() in the Page.Loaded event. I've also implemented the ContinuationManager , IWebAuthenticationContinuable , and App.Activated events as described in the github sample code. I'm also using Windows.Security.Authentication.Web.WebAuthenticationBroker.GetCurrentApplicationCallbackUri() to get my client URI.

No matter what I do, I continue to get the following error. Any insight on what i can do? Thank you in advance for your help.

'Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException' occurred in mscorlib.ni.dll but was not handled in user code

Additional information: authentication_ui_failed: The browser based authentication dialog failed to complete

async void MainPage_Loaded(object sender, RoutedEventArgs e)
{

        await LoadFromViewModel();
}

public async Task LoadFromViewModel()
{
 // Try to get a token without triggering any user prompt. 
 // ADAL will check whether the requested token is in the cache or can be obtained without user itneraction (e.g. via a refresh token).
    AuthenticationResult result = await authContext.AcquireTokenSilentAsync(this.viewModel.RESTApiResourceUri, this.viewModel.AzureADClientId);
    if (result != null && result.Status == AuthenticationStatus.Success)
    {
      // A token was successfully retrieved. Get the To Do list for the current user  
      await viewModel.BindData();
    }
    else
    {
      // Acquiring a token without user interaction was not possible. 
      // Trigger an authentication experience and specify that once a token has been obtained the GetTodoList method should be called

     authContext.AcquireTokenAndContinue(this.viewModel.RESTApiResourceUri, this.viewModel.AzureADClientId, this.viewModel.AzureADRedirectUri, AuthenticationSuceeded);
         }
    }

ADAL uses the WebAUthenticationBroker (WAB) for displaying its prompts. The WAB in Windows Phone 8.1 will not show up until the entire UX of the app has been loaded, hence your current method location won't work - at least until the WAB behavior doesn't change. Please see Authentication failed with Azure Active Directory in Windows Phone for a similar thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM