How do you read Roles/Permissions using MSAL-ANGULAR

后端 未结 4 1673
天涯浪人
天涯浪人 2021-01-06 11:44

So I\'ve successfully integrated Azure AD authentication in my angular site as per the instructions in msal-angular and now I\'m at the point where I\'m looking to define an

4条回答
  •  旧巷少年郎
    2021-01-06 12:13

    You only needs User.Read permission and to use memberof v1. Use import * as MicrosoftGraph from '@microsoft/microsoft-graph-client'; to fix microsoft-graph-client header export bug. uniqueId is your AzureAD user id.

    private loginSuccess(uniqueId: string) {
         console.log('LOGIN SUCCESS ', uniqueId);
         (this.graphClient = MicrosoftGraph.Client.init({
          authProvider: async (done) => {
            let param: AuthenticationParameters = { authority:"https://login.microsoftonline.com/{TenantId}",
                                                  scopes:["User.Read"]
                          };
            let response = await this.authService.acquireTokenSilent(param)
            .catch((reason) => {
              done(reason, null);
              });
    
            if (response) {
              done(null, response.accessToken);
            } else {
              done("Could not get an access token", null);
            }
          }
        })).api(`/users/${uniqueId}/memberOf`).get()
        .then((response)=>{
            this.groups = response.value;
            console.log("members ok", this.groups);
        },
        (error)=>{
          console.error('memberOf error');
        });
    
    }
    

提交回复
热议问题