【发布时间】:2018-02-03 18:19:22
【问题描述】:
我有一个与 Azure AD B2C 连接的 Asp.NET MVC 应用程序。
在管理员设置中我创建了一个管理员组:
在我的代码中我想使用[Authorize(Roles = "Administrator")]
使用常规 Azure Active Directory 很容易添加(只需 3 行代码)。但是对于 Azure AD B2C,我在网络上找不到任何有效的教程或示例。也许你可以告诉我我需要修改什么。
这是我的 Startup.Auth.cs 的 ConfigureAuth 方法
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
// Generate the metadata address using the tenant and policy information
MetadataAddress = String.Format(AadInstance, Tenant, DefaultPolicy),
// These are standard OpenID Connect parameters, with values pulled from web.config
ClientId = ClientId,
RedirectUri = RedirectUri,
PostLogoutRedirectUri = RedirectUri,
// Specify the callbacks for each type of notifications
Notifications = new OpenIdConnectAuthenticationNotifications
{
RedirectToIdentityProvider = OnRedirectToIdentityProvider,
AuthorizationCodeReceived = OnAuthorizationCodeReceived,
AuthenticationFailed = OnAuthenticationFailed,
},
// Specify the claims to validate
TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name"
},
// Specify the scope by appending all of the scopes requested into one string (separated by a blank space)
Scope = $"openid profile offline_access {ReadTasksScope} {WriteTasksScope}"
}
);
}
【问题讨论】:
标签: c# asp.net-mvc azure asp.net-mvc-5 azure-ad-b2c