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

问题描述

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

@H_502_4@*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

enter image description here

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

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

ASPNET Core WebAPI:配置为 azure ad api app

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

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

的权限

API 权限:

enter image description here

AzureAD api 应用:具有范围 api:api app id/acces_as_user、应用角色 admin、令牌配置以将组包含为角色。 令牌配置:

enter image description here

应用角色:

enter image description here

公开 API:

enter image description here

解决方法

这是因为您选择了将群组作为角色声明,其中涵盖了您的应用角色。

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