【发布时间】:2020-10-14 17:04:51
【问题描述】:
我下载了守护程序应用程序的 Azure 示例,并且在调试代码的末尾有一个不记名令牌。我坚持的事情是使用此令牌调用 Web API 进行身份验证。这是在 .NET Core 2.2 中
public void ConfigureServices(IServiceCollection services)
{
// This is required to be instantiated before the OpenIdConnectOptions starts getting configured.
// By default, the claims mapping will map claim names in the old format to accommodate older SAML applications.
// 'http://schemas.microsoft.com/ws/2008/06/identity/claims/role' instead of 'roles'
// This flag ensures that the ClaimsIdentity claims collection will be built from the claims in the token
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
services.AddProtectWebApiWithMicrosoftIdentityPlatformV2(Configuration);
services.Configure<JwtBearerOptions>(AzureADDefaults.JwtBearerAuthenticationScheme, options =>
{
//options.TokenValidationParameters.RoleClaimType = "roles";
});
//// Creating policies that wraps the authorization requirements
services.AddAuthorization(options =>
{
options.AddPolicy("AdminUsers", policy => policy.RequireRole("AdminUsers"));
});
services.AddControllers();
}
[HttpGet]
[Authorize]
public IActionResult Get()
{
return Ok(TodoStore.Values);
}
我删除了这些角色,只是让所有人都可以使用它,不确定我是否需要在此处设置组授权才能使其正常工作。我无法让它开箱即用。我正在考虑修改其中的一些以使其正常工作。我们只需要进行身份验证,然后根据他们所在的应用程序使用他们的电子邮件来获取角色。
提前致谢。
【问题讨论】:
标签: azure asp.net-web-api .net-core active-directory azure-active-directory