How do you read Roles/Permissions using MSAL-ANGULAR

后端 未结 4 1676
天涯浪人
天涯浪人 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 11:52

    To get the groups a user belongs to, you will need to add directory.read.all to your scope in your Angular app and also in the API permissions in the Azure app settings.

    let graphUser = await graphClient.api('/me').get();
    let graphUserGroups = await graphClient.api(`/users/${graphUser.id}/memberOf`).get();
    
    let user = new User();
    user.id = graphUser.id;
    user.displayName = graphUser.displayName;
    // Prefer the mail property, but fall back to userPrincipalName
    user.email = graphUser.mail || graphUser.userPrincipalName;
    
    graphUserGroups.value.forEach(group => {
        user.groups.push({
            group_id: group.id,
            group_name: group.displayName
        });
    });
    

提交回复
热议问题