Matt F
Matt F

Reputation: 204

MSAL + Azure App Services

I've posted this before, but the thread became pretty extensive and confusing and a resolution was never met. I'm reposting with a clear and concise block of code and my desired outcome.

I'm looking to use client-flow authentication for an Azure App Services backend. I'd like to use MSAL, to support both Microsoft Accounts (MSA) and AAD accounts. Been stuck on this for weeks with no resolution in sight.

PublicClientApplication myApp = new PublicClientApplication("registered-app-id-in-apps.dev-portal");                            
string[] scopes = new string[] { "User.Read" };
AuthenticationResult authenticationResult = await myApp.AcquireTokenAsync(scopes);
JObject payload = new JObject();                            
payload["access_token"] = authenticationResult.AccessToken;
payload["id_token"] = authenticationResult.IdToken;                            
user = await MobileService.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, payload);

Why doesn't this work? What do I have to do to get it to work?

Getting a 401 exception, tried with MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory as well as MobileServiceAuthenticationProvider.Microsoftaccount

--App Service Auth Config for Microsoft Account:

ClientID and ClientSecret as it appears in apps.dev.microsoft.com

--App Service Auth Config for AAD:

ClientID as it appears in apps.dev.microsoft.com

Issuer URL: https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration

Client Secret: (Blank)

Upvotes: 4

Views: 1175

Answers (1)

Carl Heinrich Hancke
Carl Heinrich Hancke

Reputation: 2810

Been having the same issue, having set up Azure Active Directory authentication on the App Service & attempting to authenticate from a WinForms client using MSAL. Turns out that, as of the time of this writing, Azure App Service does not support AAD V2 (including MSAL). Found the below note here:

At this time, AAD V2 (including MSAL) is not supported for Azure App Services and Azure Functions. Please check back for updates.

So ADAL seems to be the only viable option at the moment, unless you handle the authentication inside your backend code yourself.

Upvotes: 1

Related Questions