AzureAD 的访问令牌中缺少应用程序角色

Missing app roles in access token from AzureAD

SPA 应用登录 AzureAD 并获取访问令牌 api:api app id/acces_as_user。但是访问令牌中没有角色。

*created() {
    //this.$msal.signOut();    
     if (!this.$msal.isAuthenticated()) {        
       this.$msal.signIn();    
    }
    else{
      console.log(this.$msal)
      // get access token to webapi
      this.$msal
        .acquireToken({scopes: ["api://58ca819e-/access_as_user"]})
        .then((res)=>{
          console.log(res)
          auth.accessToken = res
        })
        .catch(err=>console.error(err))
    }
  },*

有什么想法吗?

我的配置:

AzureAD 用户已分配给 api 应用中的角色 admin

SPA客户端(Vue):配置为azure ad client app

Vue.use(msal, {
  auth: {
    clientId: 'be7e77ba-',
    tenantId: '3a0cf09b-',
    redirectUri: appInfo.redirectUri,
    autoRefreshToken: true,
  },   
  cache: {
    cacheLocation: 'localStorage',
  },
});

ASPNET Core WebAPI:配置为 azure ad api app

"AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "ClientId": "58ca819e-",
    "TenantId": "3a0cf09b-"
  },

AzureAD 客户端应用程序:具有 api 应用程序 api:api app id/acces_as_user

的权限

API 权限:

AzureAD api 应用:具有范围 api:api app id/acces_as_user、应用角色 admin、将组作为角色包含在内的令牌配置。 代币配置:

应用角色:

公开一个API:

这是因为您select将组作为角色声明发出,这涵盖了您的应用角色。

如果您想将群组声明与应用角色一起获取,请取消select 将群组作为角色声明发出configure "groupMembershipClaims": "SecurityGroup" in the manifest