如何在 ASP.NET MVC 中获取/设置自定义 Azure Active Directory B2C 用户属性?

How to get/set custom Azure Active Directory B2C user attributes in ASP.NET MVC?(如何在 ASP.NET MVC 中获取/设置自定义 Azure Active Directory B2C 用户属性?)
本文介绍了如何在 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. 如何设置内置字段,例如 电子邮件地址?
  2. 如何设置自定义字段,例如 Organization?

本文档显示 如何创建自定义属性,但不告诉如何使用图形客户端访问或使用该属性.

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

本文档展示了如何创建自定义属性并编辑依赖方 (RP) 文件.

有没有更简单的方法?然后获取/设置这些自定义用户属性的 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 客户端是否支持向 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.

获取和设置用户扩展属性的示例可以在 宣布 Azure AD Graph API 客户端库 2.0

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 用户属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to MOQ an Indexed property(如何最小起订量索引属性)
Mocking generic methods in Moq without specifying T(在 Moq 中模拟泛型方法而不指定 T)
How Moles Isolation framework is implemented?(Moles Isolation 框架是如何实现的?)
Difference between Dependency Injection and Mocking Framework (Ninject vs RhinoMocks or Moq)(依赖注入和模拟框架之间的区别(Ninject vs RhinoMocks 或 Moq))
How to mock Controller.User using moq(如何使用 moq 模拟 Controller.User)
How do I mock a class without an interface?(如何模拟没有接口的类?)