Deepak Kothari
Deepak Kothari

Reputation: 1753

How to know if current logged in user is tenant admin using graph api

I have a requirement to check if logged in user is tenant admin or not using MS graph api. I tried below https://graph.microsoft.com/v1.0/me/ and get below response and there is nothing related to roles in below response. How to determine whether the below "id" is tenant Admin or not?

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
    "businessPhones": [],
    "displayName": "",
    "givenName": "",
    "jobTitle": null,
    "mail": "",
    "mobilePhone": null,
    "officeLocation": "",
    "preferredLanguage": ,
    "surname": "",
    "userPrincipalName": "",
    "id": "Guid"
}

Upvotes: 2

Views: 2493

Answers (2)

Julian
Julian

Reputation: 427

I know that this is an already answered question, but i found here that you can also check if roleTemplateId is equal to 62e90394-69f5-4237-9190-012177145e10 to determine if your user have admin rights. (which I think is quite better than checking the displayName)

And please note that your App will need more permissions than just User.Read to receive all the information. You will at least need Directory.Read.All.

Upvotes: 0

Hury Shen
Hury Shen

Reputation: 15754

You can use Get https://graph.microsoft.com/v1.0/me/memberOf to implement your requirement.

If the first item of the value in the api response data is Company Administrator, the logged in user is admin. If not, the user is not admin (shown as below screenshot). enter image description here

Upvotes: 3

Related Questions