简体   繁体   中英

Calling Microsoft Graph API to get the users AD group in Angular 7

We need to call the Microsoft graph API from Angular 7 application to get the users AD group details.

we have registered app in Azure AD and we have read API permission for Azure Active Directory Graph and Microsoft Graph.

now we want to verify whether we are able to access the graph api or not in post man. can any one help how to test in post man.

it would be helpful if any sample code to call the graph api from Angular 7 application

You can refer to the following steps to test it in Postman:

Register an application with the Microsoft identity platform . I believe that you have completed this step. But you still need to do more configuration. Get group requires these permissions . I will use Delegated permission: Group.Read.All here. On Azure portal -> your Azure AD app -> API permissions -> Add a permission -> Microsoft Graph -> Delegated permissions.

在此处输入图片说明

After adding this permission, don't forget to click on "Grant admin consent for {your tenant}". (There is a delay between permissions being configured and when they appear on the consent prompt. Please wait a few minutes before granting admin consent)

在此处输入图片说明

You need to add a client secret for late use (Record it after you get it. It will be unvisable after you leave this page):

在此处输入图片说明

Next you could Get authorization . Just access this url in your broswer:

https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
client_id={client id of your Azure AD app}
&response_type=code
&redirect_uri={redirect uri of your Azure AD app}
&response_mode=query
&scope=offline_access Group.Read.All
&state=12345

Use your account to log in and you will get a code in the response in address bar.

Now open Postman to get a token . Genarate a request like this:

在此处输入图片说明

After getting the access token, you can call GET https://graph.microsoft.com/v1.0/groups or GET https://graph.microsoft.com/v1.0/groups/{group id} to get the AD group details.

在此处输入图片说明

Please note that the value format of Authorization is: "bearer {access_token}". There is a space between "bearer" and "{access_token}".

Here are someAngular code samples for Microsoft Graph for your reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM