在 Azure AD B2C(gmail 等)中使用其他邮件提供商创建用户

Create user with other mail provider in Azure AD B2C (gmail,etc...)

我使用 Microsoft Graph API PHP SDK 在我的 Azure Active Directory B2C 中添加用户。我设法创建了 userPrincipalName 的用户,例如 name@mytenantid.onmicrosoft.com

我无法添加具有 GMail 地址的用户,例如 john.doe@gmail.com

我尝试添加 signInNames 集合,但收到以下响应:

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error:
POST https://graph.microsoft.com/v1.0/users resulted in a 400 Bad Request
response: 
   { "error": { 
       "code": "Request_BadRequest", 
       "message": "Invalid property 'signInNames'.", 
       "innerError": (truncated...)

这是我的 JSON 请求正文:

{
    "accountEnabled": true,
    "displayName": "John Doe",
    "userPrincipalName": "john@doe.fr",
    "creationType": "LocalAccount",  
    "passwordProfile" : {
        "forceChangePasswordNextSignIn": true,
        "password": "P@!ssWor?D"
    },
    "signInNames": [
        {
            "type": "emailAddress",
            "value": "john@doe.fr"
        }
     ]
}

你搞糊涂了Microsoft Graph API with the Azure AD Graph API。这是两个不同的 API。虽然它们共享很多功能,但对这些 API 的调用不可互换。

Microsoft Graph API 中的 User object 不支持 signInNames 属性。这就是它返回该错误的原因。

Microsoft Graph API 目前不支持本地帐户用户。

如果有人仍然遇到同样的问题,在 MS Graph Api 中你可以使用“identities”而不是“signInNames”,你的 JSON 看起来像

{
   "accountEnabled":true,
   "displayName":"John Doe",
   "userPrincipalName":"john@doe.fr",
   "creationType":"LocalAccount",
   "passwordProfile":{
      "forceChangePasswordNextSignIn":true,
      "password":"P@!ssWor?D"
   },
   "identities":[
      {
         "signInType":"emailAddress",
         "issuer":"<your tenant domain name>",
         "issuerAssignedId":"john@doe.fr"
      }
   ]
}