【问题标题】:Getting group and role information from microsoft adal + spring boot integration with azure active directory从 microsoft adal + spring boot 与 azure Active Directory 集成获取组和角色信息
【发布时间】:2020-09-29 13:19:30
【问题描述】:

我正在使用 microsoft adal 和 spring boot 集成 azure Active Directory。现在我只获取用户信息。我还需要获取组以及角色信息。我需要注意哪些步骤。任何帮助都将不胜感激。

app.module.ts
-----------------

function initializer(adalService: MsAdalAngular6Service) {
      return () => new Promise((resolve, reject) => {
        if (adalService.isAuthenticated) {
          resolve();
        } else {
          adalService.login();
        }
      });
    }

    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        HttpClientModule,
        MsAdalAngular6Module.forRoot({
          tenant: 'xxxbef18-40f6-44e6-972c-407462a99xxx',
          clientId: 'xxx4602f-e3c8-4114-ae23-42bf9e57dxxx',
          redirectUri: 'http://localhost:4200',
          navigateToLoginRequestUrl: false,
          cacheLocation: 'localStorage'
      })
      ],
      providers: [ {
        provide: APP_INITIALIZER,
        useFactory: initializer,
        multi: true,
        deps: [MsAdalAngular6Service]
      },
        {
          provide: HTTP_INTERCEPTORS,
          useClass: TokenInterceptorService,
          multi: true
        }],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

从下面的代码中获取用户信息

this.adalService.userInfo

【问题讨论】:

    标签: spring-boot azure-active-directory ms-adal-angular


    【解决方案1】:

    您可以调用 MS Graph 来获取用户、角色和组。您需要在门户的API permissions 中为您的范围添加所需的权限。

    注意:关于需要添加的权限,可以参考user permissiongroup permissionrole permission

        // get user
        let graphUser = await graphClient.api('/me').get();
    
        // get groups by user_id
        let graphUserGroups = await graphClient.api('/users/${graphUser.id}').get();
    
        // get roles by user_id
        let graphRoles = await graphClient.Users["${graphUser.id}"].AppRoleAssignments.Request().GetAsync();
    

    msal-angular 读取角色存在问题,请参阅here

    【讨论】:

    • 谢谢帕梅拉,我真正需要的是一个与“microsoft-adal-angular6”库和“@microsoft/microsoft-graph-client”集成的示例。我可以使用从“adal”返回的相同 accessToken。
    • @MelvinMoses 代码是基于 JavaScript 的,见here,这是你的问题。
    猜你喜欢
    • 2020-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 2014-06-16
    • 1970-01-01
    相关资源
    最近更新 更多