在我的Azure B2C目录中,我创建了一个名为EmployeeId
的自定义属性。我正在使用Microsoft Graph库创建用户。我遵循了此GitHub Example中的示例。
我的实际用户创建代码如下:
public async Task InsertEmployee(Employee employee)
{
IDictionary<string, object> extensionInstance = new Dictionary<string, object>();
extensionInstance.Add("EmployeeId", employee.EmployeeId.ToString());
var user = new B2cUserModel
{
DisplayName = $"{employee.EmployeeFirstName} {employee.EmployeeLastName}",
GivenName = employee.EmployeeFirstName,
Surname = employee.EmployeeLastName,
Password = employee.Password,
Identities = new List<ObjectIdentity> {
new ObjectIdentity {
SignInType = "emailAddress",
IssuerAssignedId = employee.EmployeeEmail
}
},
EmployeeId = employee.EmployeeId.ToString()
AdditionalData = extensionInstance
};
user.SetB2CProfile(_domain);
await _client.Users.Request().AddAsync(user);
}
}
但是每当我通过代码或通过user_flow检索用户详细信息时,EmployeeId始终为null。有人可以发现我在做什么错吗?
答案 0 :(得分:0)
Azure B2C中的自定义属性以以下格式存储在Graph中:extension_{client id of WebApp-GraphAPI-DirectoryExtensions}_{custom attribute}
。参见参考文献here。
您可以在 Azure Portal -> 应用程序注册中找到WebApp-GraphAPI-DirectoryExtensions Azure AD应用程序的客户端ID。
因此,在这种情况下,您应该使用:
extensionInstance.Add("extension_{client id of WebApp-GraphAPI-DirectoryExtensions}_EmployeeId", employee.EmployeeId.ToString());