Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Authentication Library (MSAL) never returns from AcquireTokenAsync() on Android

I have a Xamarin.Forms iOS/Android app and have to authenticate the user against a Microsoft Azure B2C AD.

I have added the Microsoft.Identity.Client NuGet and using this for authentication.

It works fine on iOS but on Android the same code never returns from the AcquireTokenAsync().

The login UI is shown as it should and the username and password accepted and the UI presented by the MSAL library dismisses as it should but the call to await AcquireTokenAsync() never returns.

The code is in a PCL in the core project of the app.

I have tried on Android 4, 5 and 6 devices.

I know MSAL is still in alpha I just would like to have confirmation if this due to that or I might be doing something wrong.

like image 815
Nicolai Henriksen Avatar asked Jun 14 '16 11:06

Nicolai Henriksen


People also ask

What is Microsoft authentication library Msal?

The Microsoft Authentication Library (MSAL) enables developers to acquire security tokens from the Microsoft identity platform to authenticate users and access secured web APIs. It can be used to provide secure access to Microsoft Graph, other Microsoft APIs, third-party web APIs, or your own web API.

What is Msal v2?

Microsoft Authentication Library for JavaScript v2. x: A browser-based, framework-agnostic browser library that enables authentication and token acquisition with the Microsoft Identity platform in JavaScript applications. Implements the OAuth 2.0 Authorization Code Flow with PKCE, and is OpenID-compliant.


1 Answers

So apparently I need this piece of code in my MainActivity.cs and I overlooked that in their example:

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);
        AuthenticationAgentContinuationHelper.SetAuthenticationAgentContinuationEventArgs(requestCode, resultCode, data);
    }
like image 173
Nicolai Henriksen Avatar answered Nov 07 '22 13:11

Nicolai Henriksen