簡體   English   中英

無法通過 Azure AD B2C 屬性中的 Graph API 創建用戶不存在

[英]Cant create user over Graph API in Azure AD B2C property not present

目前正在嘗試通過 Graph API 在 Azure AD B2C 中創建用戶,但不斷收到以下錯誤:(我沒有刪除 '' 之間的屬性名稱,沒有...)

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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM