我有一个与Azure AD B2C连接的Asp.NET MVC应用程序。Azure AD B2C - 角色管理
在管理员设置我创建一个Administrators组:
在我的代码我想用[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}"
}
);
}
首先非常感谢您的回答! 我还剩下两个问题。 我应该在哪里添加该URL(步骤4)以及什么是Redirect uri(这是b2c的回复URI?)? 另一个问题的代码: 我填写变量什么要高度重视: - GraphClientId - GraphRedirectUri - GraphClientSecret - userTokenCache 和VisualStudio的呼吁,在一条错误消息:新的C。声明 非常感谢您的帮助:-) – DarkWing89
进行了更新,以进一步阐明应用程序注册说明并解决c.Claim问题。 – Saca
GraphClientID =您注册的应用程序的应用程序ID, GraphSecret =应用程序密钥, GraphRedirectUri =您指定的重定向URI, userTokenCache应该已经从示例中已经在该OnAuthorizationCodeReceived中的代码定义。 – Saca