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.