我有一个使用 Azure 事件目录授权(使用 ADAL)的 Asp.Net 网站,它返回基本属性,例如用户的显示名称。我想要的是使用 Microsoft Graph API(不是 Azure AD API)获取自定义属性(例如 employeeID)
示例图形 API 查询:
string graphRequest = string.Format(CultureInfo.InvariantCulture,
"{0}{1}/users?api-version={2}&$filter=startswith(userPrincipalName, '{3}')",
graphApiEndpoint,
tenant,
graphApiVersion,
"SearchText.Text");
最佳答案
你正在使用来自 Azure Graph API 的 URI 模式调用 Microsoft Graph。这些是具有不同调用模式的不同 API。
正确的 URI 应该是:
https://graph.microsoft.com/v1.0/users?$filter=startsWith(userPrincipalName, 'string')
默认情况下,/users
只返回一组有限的属性。来自documentation :
By default, only a limited set of properties are returned ( businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname, userPrincipalName ).
To return an alternative property set, you must specify the desired set of user properties using the OData
$select
query parameter. For example, to return displayName, givenName, and postalCode, you would use the add the following to your query$select=displayName,givenName,postalCode
Note: Certain properties cannot be returned within a user collection. The following properties are only supported when retrieving an single user: aboutMe, birthday, hireDate, interests, mySite, pastProjects, preferredName, responsibilities, schools, skills, mailboxSettings
换句话说,如果您需要默认属性以外的东西,您需要明确请求您想要的属性集。
基于以上内容,您的示例代码应如下所示:
const string graphApiEndpoint = "https://graph.microsoft.com";
const string graphApiVersion = "v1.0";
const string userProperties = "id,userPrincipalName,displayName,jobTitle,mail,employeeId"
string graphRequest = string.Format(CultureInfo.InvariantCulture,
"{0}/{1}/users?$select={2}&$filter=startswith(userPrincipalName, '{3}')",
graphApiEndpoint,
graphApiVersion,
userProperties,
"SearchText.Text");
关于c# - 使用 Microsoft Graph API(不是 Azure AD API)查询 Azure Active Directory 中的自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52551930/