我有一個與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