Quantcast
Channel: Azure Active Directory forum
Viewing all articles
Browse latest Browse all 16000

Optimize call to get the Azure AD directory object name

$
0
0
I am trying to get the Azure AD directory object name from object Id. Currently, I have the below code which uses the Graph Client library. However, it involves atleast 2 calls to Graph API. Is it possible to optimize it to 1 call?

string objectName;
ActiveDirectoryClient client = GetActiveDirectoryClient();
IDirectoryObject dirObj = await client.DirectoryObjects.GetByObjectId(objectId).ExecuteAsync();

// IDirectoryObject does not have a Name property so having to check the object type and make a second call
if (dirObj.ObjectType == "User")
{
    IUser user = await client.Users.GetByObjectId(objectId).ExecuteAsync();
    objectName = user.UserPrincipalName;
}
else if (dirObj.ObjectType == "ServicePrincipal")
{
    IServicePrincipal principal = await client.ServicePrincipals.GetByObjectId(objectId).ExecuteAsync();
    objectName =  principal.DisplayName;
}

Viewing all articles
Browse latest Browse all 16000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>