如何在ASP.NET MVC中获取/设置自定义Azure Active Directory B2C用户属性? [英] How to get/set custom Azure Active Directory B2C user attributes in ASP.NET MVC?

查看:43
本文介绍了如何在ASP.NET MVC中获取/设置自定义Azure Active Directory B2C用户属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Azure Active Directory B2C租户中添加了一个自定义Organization字段作为用户属性,如下所示:

I have added a custom Organization field as a User Attribute in my Azure Active Directory B2C tenant, like so:

我正在使用 Microsoft Graph .NET客户端库来管理Azure中的用户Active Directory B2C,并希望使用类似于以下代码的方式来设置用户的自定义Organization字段和用户的内置Email Addresses字段.

I am using the Microsoft Graph .NET Client Library to manage users in Azure Active Directory B2C and would like to use something similar to the following code to set the user's custom Organization field and the user's built-in Email Addresses field.

await graphClient.Users[user.Id].Request().UpdateAsync(new User()
{
    Email Addresses = new StringCollection("myemail@mydomain.com")
    Organization = "Microsoft"
});

两个问题:

  1. 如何设置内置字段,例如Email Addresses?
  2. 如何设置自定义字段,例如Organization?
  1. How do I set a Built-in field, like the Email Addresses?
  2. How do I set a Custom field, like Organization?

此文档显示了如何创建自定义属性,但没有说明如何使用Graph Client访问或使用该属性.

This documentation shows how to create a custom attribute but does not tell how to access or use that attribute using the Graph Client.

此文档显示了如何有没有更简单的方法?然后,什么graphClient代码可以获取/设置这些自定义用户属性?

Is there an easier way? And what is the graphClient code to then get/set these custom user attributes?

推荐答案

Microsoft Graph API以及Microsoft Graph Client是否支持在Azure AD B2C租户中注册的扩展属性,这有点令人困惑.

It is a bit confusing about whether the Microsoft Graph API, and hence the Microsoft Graph Client, supports the extension properties that are registered with an Azure AD B2C tenant.

当我使用Azure AD Graph API查询用户对象时,将返回自定义属性(例如"CreatedTime").

When I query a user object using the Azure AD Graph API, then the custom attributes (e.g. "CreatedTime") are returned.

https://graph.windows.net/{tenant}/users/{objectId}

返回:

{
    "odata.metadata": "https://graph.windows.net/{tenant}/$metadata#directoryObjects/Microsoft.DirectoryServices.User/@Element",
    "odata.type": "Microsoft.DirectoryServices.User",
    "objectType": "User",
    ...
    "extension_917ef9adff534c858b0a683b6e6ec0f3_CreatedTime": 1518602039
}

当我使用Microsoft Graph API查询同一对象时,不会返回自定义属性.

When I query the same object using the Microsoft Graph API, then the custom attributes aren't returned.

https://graph.microsoft.com/v1.0/users/{id}/extensions

返回:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('{id}')/extensions",
    "value": []
}

除非您收到更好的答案,否则建议您使用Azure AD Graph API,并且可以选择使用 Azure AD Graph客户端,以获取并设置Azure AD B2C用户的扩展属性.

Unless you receive a better answer, then I suggest you use the Azure AD Graph API, and optionally the Azure AD Graph Client, to get and set the extension properties for the Azure AD B2C users.

获取和设置用户扩展属性的示例可以在

Examples of getting and setting the extension properties for users can be found at Announcing Azure AD Graph API Client Library 2.0

这篇关于如何在ASP.NET MVC中获取/设置自定义Azure Active Directory B2C用户属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆