Graph API request returning “One or more propertie

2019-05-31 02:41发布

I am trying to execute B2C user creation on our company's Azure Directory. As reference, I use this site from Microsoft, and the .DotNet example in it.

https://azure.microsoft.com/en-us/documentation/articles/active-directory-b2c-devquickstarts-graph-dotnet/

I thoroughly follow the example, and I get to the point where I get authenticated, and I am able to extract the AD users in the directory. Here is the sample request I generated.

GET https ://graph.windows.net/mycompany/users?api-version=beta

But when I get to the part of creating a sample user in the directory, I get the error response "One or more properties contains invalid values".

POST https ://graph.windows.net/mycompany/users?api-version=beta

Here is the payload, I used, which is the exact same payload used in the site's example for user creation. This is in JSON format.

{"accountEnabled": true,"alternativeSignInNamesInfo": [{"type": "emailAddress", "value": "joeconsumer@gmail.com"}],"creationType": "NameCoexistence", "displayName": "Joe Consumer", "mailNickname": "joec","passwordProfile": {"password": "P@ssword!","forceChangePasswordNextLogin": false},"passwordPolicies": "DisablePasswordExpiration"}

This payload conforms with the requirements based on the User Creation requirements from Microsoft, also, it is the exact same payload in the site's example, which is why it is strange that I am receiving the a message that one of the properties has invalid values. The worse thing is, the response does not explicitly state which value is the source of the problem.

Any help would be appreciated.

3条回答
手持菜刀,她持情操
2楼-- · 2019-05-31 03:19

I got this error when trying to create a user with a sign in name where the type was set to userName and the value was actually an email address. I thought username would allow any arbitrary string, but apparently if you want to use an email as a username the type must be set to emailAddress before it will pass Microsoft's validation.

public class SignInNames
{
    public string type { get; set; }
    public string value { get; set; }

    public SignInNames(string userName)
    {
        // Type must be 'emailAddress' (or 'userName')
        if (!string.IsNullOrWhiteSpace(userName) && userName.Contains("@"))
            this.type = "emailAddress";
        else
            this.type = "userName";

        // The user email address
        this.value = userName;
    }
}
查看更多
时光不老,我们不散
3楼-- · 2019-05-31 03:32

I don't think this is possible on your company's Active Directory, you need to create a seperate B2C Active Directory.

Follow this tutorial to create a B2C directory: https://azure.microsoft.com/en-us/documentation/articles/active-directory-b2c-get-started/

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-05-31 03:32

Do you have B2C tenant created and it has application that is created in Azure AD.

Can you please try this payload, it works fine for me.

{
  "accountEnabled": true,
  "signInNames": [
    {
      "type": "emailAddress",
      "value": "joeconsumers6@gmail.com"
    }
  ],
  "creationType": "LocalAccount",
  "displayName": "karthikeyan",
  "mailNickname": "karthikeyan",
  "passwordProfile": {
    "password": "cads2016!",
    "forceChangePasswordNextLogin": false
  },
  "passwordPolicies": "DisablePasswordExpiration",
  "city": "San Diego",
  "country": null,
  "facsimileTelephoneNumber": null,
  "givenName": "Joe",
  "mail": null,
  "mobile": null,
  "otherMails": [],
  "postalCode": "92130",
  "preferredLanguage": null,
  "state": "California",
  "streetAddress": null,
  "surname": "Consumer",
  "telephoneNumber": null,

}
查看更多
登录 后发表回答