场合
我想为我的网络应用程序使用Azure B2C身份验证服务。但是,我希望应用的管理员限制对某些电子邮件或域的访问,例如白名单如下:
所以只有前两封电子邮件和其他任何人以电子邮件结尾于" alphabet.com"可以访问该网站。
问题
我已经实施了所有内容并且工作正常,但是我很难获得经过身份验证的用户的电子邮件地址,以便在登录/登录过程中进行白名单检查。 AuthenticationTicket具有所请求的所有声明(FirstName,LastName,Name,Object Identifer等),但电子邮件不存在(它已在Azure B2C中设置为声明)。
如何访问电子邮件,这是正确的检查位置?
Startup.App.cs
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,
AuthorizationCodeReceived = (context) =>
{
// no claims present here
return Task.FromResult(0);
},
SecurityTokenReceived = (context) =>
{
// no claims present here
return Task.FromResult(0);
},
SecurityTokenValidated = (context) =>
{
// print all claims - quite a few except email :( Is this where this check should be done?
foreach (var claim in context.AuthenticationTicket.Identity.Claims)
{
Console.WriteLine(claim.Value);
}
return Task.FromResult(0);
},
},
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"
},
};
}
任何帮助非常感谢。