D365: Graph API(一)Postman调用Graph API获取AAD用户信息
Postman 调用Graph API获取AAD用户信息
1,注册Azure AD应用
2,应用授权
3,Postman获取访问token
Request Type: POST
Request URL: https://login.microsoftonline.com/{{TenantID}}/oauth2/v2.0/token
Body Type: x-www-form-urlencoded
Body Key/Value Pairs:
grant_type = client_credentials
client_id = {{ClientID}}
client_secret = {{ClientSecret}}
scope = https://graph.microsoft.com/.default
4,通过token发起Graph API请求
Request Type: GET
Request URL: https://graph.microsoft.com/v1.0/users
Headers:
Key: Authorization, Value: Bearer {{AccessToken}}
Key: ConsistencyLevel, Value: eventual
Key: Content-Type, Value: application/json
其他说明
1,增加查询条件用filter,例如filter=employeeId eq null and accountEnabled eq true
2,查询指定字段,例如select=onPremisesSamAccountName,officeLocation,AccountEnabled,employeeId,UserPrincipalName,Mail,id
3,查询条数,例如top=999,Graph api的单次查询量默认为100条即是按100条数据做分页,最多可以指定到单次查询999,如果数据超出,需要根据返回的
https://graph.microsoft.com/v1.0/users?$count=true&$filter=employeeId eq null and accountEnabled eq true &$select=onPremisesSamAccountName,officeLocation,AccountEnabled,employeeId,UserPrincipalName,Mail,id