0
votes

I am trying to run the sample at:

https://github.com/Azure-Samples/ms-identity-dotnetcore-b2c-account-management

And am receiving this error:

Enter command, then press ENTER: 7 Create a user with the custom attributes 'FavouriteSeason' (string) and 'LovesPets' (boolean) Have you created the custom attributes 'FavouriteSeason' (string) and 'LovesPets' (boolean) in your tenant?

Code: Request_BadRequest Message: One or more property values specified are invalid. Inner error: AdditionalData: date: 2020-06-30T23:24:26 request-id: dad23cee-984b-439c-a943-9e1bc6be4c9b ClientRequestId: dad23cee-984b-439c-a943-9e1bc6be4c9b

I have created the custom attributes and can clear see them in the tenant...it even returns their ids. I've setup the Graph access level appropriately (I believe).

Any ideas? Thank you!

2

2 Answers

0
votes
  1. In Code, you need to update Tenant id, client id, client secret and also give B2cExtensionAppClientId= “your application display name” in appsettings.json

  2. You have to create two custom attributes in the B2C portal

    I. FavouriteSeason (string)

    II. LovesPets (boolean)

  3. Use below code to create the user with the custom attribute

             try
             {
                 //Create user
                 var result = await graphClient.Users
                 .Request()
                 .AddAsync(new User
                 {
                     GivenName = "Casey",
                     Surname = "Jensen",
                     DisplayName = "Casey Jensen",
                     Identities = new List<ObjectIdentity>
                     {
                         new ObjectIdentity()
                         {
                             SignInType = "emailAddress",
                             Issuer ="AADCxPb2c.onmicrosoft.com",
    
    
                             IssuerAssignedId = "x@AADCxPb2c.onmicrosoft.com",
                         }
                     },
                     PasswordProfile = new PasswordProfile()
                     {
                         Password = b2c_ms_graph.Helpers.PasswordHelper.GenerateNewPassword(4, 8, 4)
                     },
                     PasswordPolicies = "DisablePasswordExpiration",
                     AdditionalData = extensionInstance
    
    
                 }) ;
                 Console.WriteLine(result);
                 string userId = result.Id;
                 Console.WriteLine(result.Id);
                 Console.WriteLine($"Created the new user. Now get the created user with object ID '{userId}'...");
    
0
votes

Can find it on your registered App on Azure AD B2C:

  1. Click on "API Permissions" on left panel.

  2. Then Chose "APIs my organization uses".

  3. You can find the value under name "b2c-extensions-app. Do not modify. Used by AADB2C for storing user data.".