【发布时间】:2019-03-28 11:12:52
【问题描述】:
这是我在 Startup.Auth.cs 中的代码
public void ConfigureAuth(IAppBuilder app) {
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer=false,
NameClaimType = "upn",
RoleClaimType ="roles"
}
});
}
在我的 MVC 视图中,我正在检查返回 True 的 @User.IsInRole("CBUser") ,因为用户具有 CBUSer 角色。所有这些代码在带有 Azure AD Authentication and Authorization 的 Visual Studio 中都能正常工作。但是当我将应用程序移动到 Azure 时,@User.IsInRole("CBUser") 总是返回 false。我如何才能在 MVC 视图或控制器中读取用户角色。我尝试使用下面的代码来读取在 VS2015 中调试时工作正常的用户角色。但是一旦应用程序移动到 Azure 环境就无法工作
var appRoles = new List<string>();
foreach (Claim claim in ClaimsPrincipal.Current.FindAll("roles"))
appRoles.Add(claim.Value);
【问题讨论】:
-
您是否对部署到 Azure 的应用使用相同的
clientId值?
标签: azure asp.net-mvc-4 azure-active-directory azure-web-app-service openid-connect