无法在Azure AD B2C属性中通过图形API创建用户



目前正在尝试通过图形API在Azure AD B2C中创建用户,但不断得到以下错误:(我没有删除" there is none…"之间的属性名称)

Code: Request_ResourceNotFound
Message: Resource '' does not exist or one of its queried reference-property objects are not present.
Inner error:
AdditionalData:
date: 2021-10-12T11:22:34
request-id: f45d65b3-61b1-492c-b6cb-fc43bb3805dd
client-request-id: f45d65b3-61b1-492c-b6cb-fc43bb3805dd
ClientRequestId: f45d65b3-61b1-492c-b6cb-fc43bb3805dd
下面的代码用于创建用户
IDictionary<string, object> extensionInstance = new Dictionary<string, object>();
extensionInstance.Add($"extension_{AadB2CConfiguration.ExtensionsID}_GUID", guid);
new User
{
DisplayName = username,
AccountEnabled = true,
Identities = new List<ObjectIdentity>
{
new ObjectIdentity()
{
SignInType = valueSignInType,
Issuer = AadB2CConfiguration.TenantId,
IssuerAssignedId = username,
}
},
PasswordPolicies = valuePasswordPolicies,
PasswordProfile = new PasswordProfile()
{
Password = password,
ForceChangePasswordNextSignIn = false,
}
,AdditionalData = extensionInstance
};

GraphClient方法
public static Microsoft.Graph.GraphServiceClient GraphClient
{
get
{
var app = ConfidentialClientApplicationBuilder.Create(AadB2CConfiguration.ClientId)
.WithClientSecret(AadB2CConfiguration.ClientSecret)
.WithAuthority(AadB2CConfiguration.AadB2cGraphAuthority)
.Build();
string[] scopes = new string[] { AadB2CConfiguration.GraphScope };
var token = app.AcquireTokenForClient(scopes).ExecuteAsync().Result;
Microsoft.Graph.GraphServiceClient graphClient = new Microsoft.Graph.GraphServiceClient(AadB2CConfiguration.GraphBaseUrl, new Microsoft.Graph.DelegateAuthenticationProvider(async (requestMessage) =>
{
requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", token.AccessToken);
}));
return graphClient;
}
用户将通过GraphClient 创建
User result = await GraphClient.Users.Request().AddAsync(newUser);
return ResponseMessage(result);

如何查找不存在的属性?

检查AadB2CConfiguration.ExtensionsID是否正确,它应该是删除-后创建GUID扩展属性的应用程序(客户端)ID。

如果它是错误的,那么Graph无法找到应用程序,那么您将得到错误Resource '' does not exist or one of its queried reference-property objects are not present.

最新更新