1
votes

Previously I have been using MobileServiceClient.LoginAsync(..) to initiate authentication flow with social identity providers.

More recently I set up Azure B2C - I have used Microsoft.Identity.Client.PublicClientApplication.AcquireTokenAsync(..) to initiate authentication in browser and obtain a JSON web token:

Can I use the JSON web token from B2C to authenticate with the Azure App Service?

Can I use the following to authenticate with the Azure App service?

MobileServiceClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, [JWT HERE])

Is there an easier way to authenticate with Azure App Service + Azure B2C?

Thanks, Tom.

1
There are quite a few examples available, I'm guessing your scenario is in there? - rickvdbosch
Any process now? - Joey Cai

1 Answers

0
votes

The code you provided is Integrating Azure Active Directory B2C with Azure Mobile Apps.

The method CreateOptionsFromPolicy will take the Policy name as input parameter and will return an object of type OpenIdConnectAuthenticationOptions, This object is responsible for controlling the OpenID Connect middleware.

The TokenValidationParameters is used to store the information needed to validate the tokens, we only need to change 2 settings here, the NameClaimType and the SaveSigninToken .

private OpenIdConnectAuthenticationOptions CreateOptionsFromPolicy(string policy)
{
    return new OpenIdConnectAuthenticationOptions
     {
         // For each policy, give OWIN the policy-specific metadata address, and
         // set the authentication type to the id of the policy
         MetadataAddress = String.Format(aadInstance, tenant, policy),
         AuthenticationType = policy,
         // These are standard OpenID Connect parameters, with values pulled from web.config  
         ClientId = clientId,
         RedirectUri = redirectUri,
         PostLogoutRedirectUri = redirectUri,
         Notifications = new OpenIdConnectAuthenticationNotifications
         {
             AuthenticationFailed = AuthenticationFailed
         },
         Scope = "openid",
         ResponseType = "id_token",
         // This piece is optional - it is used for displaying the user's name in the navigation bar.
         TokenValidationParameters = new TokenValidationParameters
         {
            NameClaimType = "name",
            SaveSigninToken = true //important to save the token in boostrapcontext
         }
    };
}

If you want to Integrate Azure AD B2C with Web App, you could refer to this article and this one.