首页 > 解决方案 > Get information about invitation of B2B user in Microsoft Graph

问题描述

I'm trying to create an application in which I need to know whether user invited to Azure Active Directory accepted an invitation or not. I'm using microsoft graph SDK for C# to get information about users from AAD but I cannot find information about invitation status in the resulting user object. In particular, I want to get this piece of information from Azure: enter image description here

Is there any way to get this info from C# using Microsoft Graph SDK or with direct graph query?

标签: azure-active-directoryazure-ad-b2cmicrosoft-graph-sdks

解决方案


It seems microsoft graph api(v1.0) for get user doesn't have the field to show if the guest accept the inviatation. I checked the document of user properties and didn't find any property which matches "accept invitation". But I found there is a property externalUserState in microsoft graph api(beta version) which can meet your requirements. If you don't mind the stability, you can use the beta version of microsoft graph api. If you will use this api in production environment, I suggest you to use Azure AD graph api. Please refer to the steps below:

As a workaround, we can use Azure AD graph api instead of microsoft graph api. I found there is a property UserState in the response of Azure AD graph api. If we want to request this Azure AD graph api, we need to add the required permissions first. enter image description here enter image description here

Don't forget grant admin consent and then request the access token, please note that when request the access token for Azure AD graph, we need to change the scope from https://graph.microsoft.com/.default to https://graph.windows.net/.default.

enter image description here

Then use the access token to request the Azure AD graph api.

https://graph.windows.net/<tenant id>/users/<object id>?api-version=1.6

Get the response of the api and we can find there is a property userState in it. If the guest has accepted, this property will be "Accepted", if the guest hasn't accepted, this property will be "PendingAcceptance".

Hope it helps~


推荐阅读