azureazure-active-directoryangular7azure-ad-graph-apiadgroup

How to call graph AD api from Angular 7


after AD authentiction the returned JWT token does not have the group names, it just shows "Has groups"="true". When searching on this topic i understood that if there are multiple group it will send only this rather than group list and we need to use AD graph API to get this. Can anyone help me on how to call the graph API from Angular 7?

Want to get the group names of the particular user from Graph API


Solution

  • You can just send a http request or use microsoft-graph-client library to call the graph api.

    Before that, you need to grant your app the needed permission. What you need is Directory.Read.All permission.

    Click Azure Active Directory->App registrations->find your application registered->API permissions->Add a permission->choose Microsoft Graph->Delegated permission->find Directory.Read.All permission->save-> click grant admin consent button.

    enter image description here

    Use http request:

    GET https://graph.microsoft.com/v1.0/me/memberOf
    

    You can refer to this document.

    Use microsoft-graph-client library:

    import { Client } from '@microsoft/microsoft-graph-client';
    
    graphClient.api('/me/memberOf').get();
    

    Refer to this document for more details.