Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Active Directory Administrators using Azure AD Graph Client

Using the Azure Active Directory Graph Client, I can successfully query the AD for its user roles with the ff. code:

var activeDirectoryClient = new ActiveDirectoryClient(); // Instantiate the Graph Client here.
var adRoles = await activeDirectoryClient.DirectoryRoles.ExecuteAsync();

Is it possible, however, to get:

  1. A list of roles that are admin roles?, and
  2. A list of users who fall under the admin roles?

In this case, my definition of an admin would be users under the Company Administrator role, or those who would be able to authorize an application (via the auth request URL with format https://login.microsoftonline.com/common/oauth2/authorize?response_type=code&client_id=xxx-xxx&resource=yyy-yyy&redirect_uri=zzz-zzz&prompt=admin_consent)

like image 688
miguelarcilla Avatar asked Jul 23 '15 08:07

miguelarcilla


People also ask

How do I find my Azure AD Admin?

Identifying the global administratorsLog in to the public Azure portal. In the left hand side portal menu select Azure Active Directory. In the Manage section, select Roles and Administrators. In the Roles and administrators blade, scroll down and select Global administrator.

What is replacing Azure AD graph?

All new functionalities will only be available through the Microsoft Graph. Microsoft Graph is also more secure and resilient than Azure AD Graph. Microsoft Graph has all the capabilities that have been available in Azure AD Graph and new APIs like identity protection and authentication methods.

How do I manage local admins on Azure AD joined devices?

Sign in to the Azure portal as a Global Administrator. Browse to Azure Active Directory > Devices > Device settings. Select Manage Additional local administrators on all Azure AD joined devices. Select Add assignments then choose the other administrators you want to add and select Add.


1 Answers

There are a couple of ways you can do this and let's look at the REST API as a starting point.

You can get a list of groups and roles per USER using making a GET request to: https://graph.windows.net/myorganization/users/{user_id}/$links/memberOf?api-version

On success, returns a collection of links to the Group's and DirectoryRole's that this user is a member of

ref: Get a user's group and directory role memberships

To get the membership of a group you would make a GET request to: https://graph.windows.net/myorganization/groups/{object_id}/$links/members?api-version

ref: Get a group's direct members

However per the docs:

No functions or actions may be called on directory roles

ref: https://msdn.microsoft.com/en-us/Library/Azure/Ad/Graph/api/entity-and-complex-type-reference#DirectoryRoleEntity

This has to be done from the USER object. The SDK will reflect this.

IPagedCollection<IDirectoryObject> pagedCollection = retrievedUserFetcher.MemberOf.ExecuteAsync();

The GraphAPI console app has some great examples that should show you how to complete these actions: Program.cs

like image 67
tripdubroot Avatar answered Sep 18 '22 13:09

tripdubroot