我在entra id中有一个后台应用程序,它具有不同的角色-例如Role1和Role2.我还有一个前端应用程序,它具有后台作为API权限.

API: enter image description here

APP: enter image description here

当我在前端使用身份验证时,登录用户的角色不会从后台应用程序下载.这对我来说是一个问题,因为我不想在两个地方拥有角色,而且我不能,因为我正在使用后台的id角色.

export function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration {
    const protectedResourceMap = new Map<string, Array<string>>();
    protectedResourceMap.set(environment.graphUrl + '/me/memberOf', ['user.read']);
    protectedResourceMap.set('user.read', [environment.scope]);
    return {
        interactionType: InteractionType.Redirect,
        protectedResourceMap,
    };
}

这可能吗?

First token doesn't return any roles from the API application. (maybe is needed include scope but I don't know how) enter image description here

First token: enter image description here

The second token is for calling backend and there is adding scope for API application. enter image description here

推荐答案

我创建了一个Microsoft Entra应用程序(API)并公开了一个添加API的授权客户端应用程序:

enter image description here

并创建了应用程序角色:

enter image description here

在前端应用程序中,我授予了API应用程序的API权限:

enter image description here

要获取令牌中的角色,请确保在API企业应用程序中为用户分配角色:

enter image description here

对于一个示例,我通过Postman生成了一个访问令牌:

https://login.microsoftonline.com/TenantID/oauth2/v2.0/token

client_id:APPClientID
grant_type:authorization_code
scope:api://APIClientID/.default 
code:code
redirect_uri:https://jwt.ms
client_secret:ClientSecret

enter image description here

解码后,角色和范围就会出现:

enter image description here

Angular相关问答推荐

日语字符不受角形约束控制

停靠的Angular 应用程序的Nginx反向代理无法加载assets资源

未触发HTTP拦截器

独立Angular 零部件不在辅零部件或共享零部件中工作

更改动态表单控制Angular 的值

我应该对我想要在我的Angular 17+组件中显示的任何变量使用信号吗?

带区域设置用法的Angular 日期管道

RXJS拆分返回值,多次调用后重新加入

Angular 15 在 URL 中使用@进行路由

使用 Observable 进行渐进式填充

关闭 Dynamsoft Web Twain 弹出窗口

Observable .do() 运算符 (rxjs) 的用例

使用 NPM 安装 Font Awesome 5

将环境变量传递给Angular 库

如何在数据表angular material中显示空消息,如果未找到数据

如何在 Angular Cli 中生成 .angular-cli.json 文件?

相对于根目录的 SCSS 导入

Angular 5 手动导入语言环境

Angular2:如果 img src 无效,则显示占位符图像

如何在 Angular CLI 6: angular.json 中添加 Sass 编译?