C# 使用JWT检索Azure广告组信息
我有需要Azure AD承载身份验证的APIC# 使用JWT检索Azure广告组信息,c#,azure-active-directory,bearer-token,azure-acs,json-web-token,C#,Azure Active Directory,Bearer Token,Azure Acs,Json Web Token,我有需要Azure AD承载身份验证的API public void ConfigureAuth(IAppBuilder app) { app.UseWindowsAzureActiveDirectoryBearerAuthentication( new WindowsAzureActiveDirectoryBearerAuthenticationOptions { // ... }); } 然后是否可以查询Azure AD(可能使用
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
// ...
});
}
然后是否可以查询Azure AD(可能使用Graph API)以确定调用用户的组信息?这里的最终目标是对API方法/控制器应用基于角色的安全性,如下所示(或类似)
此外,如何以及在何处将标识信息应用于执行线程?最近,您可以使用角色声明和/或组声明来执行此操作。如果您有受承载身份验证保护的web API(如中),则可以配置API,以便访问令牌包含组和/或角色声明 OWIN中间件将读取JWT承载令牌中的声明,并在
System.IdentityModel.Tokens.JWT.JwtSecurityTokenHandler
()中使用适当的声明填充ClaimSideEntity
要将API配置为接收组声明,您需要编辑应用程序清单的“groupMembershipClaims”
属性,其值为“All”
或“SecurityGroups”
(分别包括或排除通讯组列表),如中所示,它使用组声明使用[Authorize]
标记将基于角色的安全性应用于web应用
要将API配置为接收角色声明,您还需要编辑清单,在“appRoles”
属性中定义应用程序角色,如所示(链接尚未激活-将在未来几天内激活),该属性使用角色声明执行相同的操作。定义应用程序角色后,可以在Azure门户或通过GraphAPI将用户和组分配给这些角色。注意:由于AAD发出的声明属于类型“roles”
,因此需要将RoleClaimType设置为:
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
...
TokenValidationParameters = new TokenValidationParameters {
RoleClaimType = "roles",
},
...
}
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
...
TokenValidationParameters = new TokenValidationParameters {
RoleClaimType = "roles",
},
...
}