Home > Net >  Cant create user over Graph API in Azure AD B2C property not present
Cant create user over Graph API in Azure AD B2C property not present

Time:10-14

Currently trying to create a user in a Azure AD B2C over the Graph API but keep getting following error: (I did not delete the property name between the '' 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

Following Code is used to create the User

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 Method

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;
            }

The User will then be created via the GraphClient

User result = await GraphClient.Users.Request().AddAsync(newUser);
return ResponseMessage(result);

How can I find out which property is not present?

CodePudding user response:

Check that AadB2CConfiguration.ExtensionsID is correct, it should be the application (client) ID of the application the GUID extension property was created against with the - removed.

If it's wrong, and so Graph can't find the application, then you'll get the error Resource '' does not exist or one of its queried reference-property objects are not present.

  • Related