Getting group and role information from microsoft adal + spring boot integration with azure active directory

315 views Asked by At

I'm integrating azure active directory using microsoft adal and spring boot. Now I'm only getting information of user only. I need to get the group as well as role information also. What are the steps I need to take care off. Any help would be appreciable.

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 { }

Getting the user information from below code

this.adalService.userInfo
1

There are 1 answers

2
unknown On

You could call MS Graph to get user, roles, and groups. And you will need to add required permissions to your scope in the API permissions of the portal.

Note: About the permission you need to add, you could refer to user permission, group permission, and role 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();

There is the issue about reading roles by msal-angular, see here.