繁体   English   中英

使用 Azure AD B2C GraphClient 在 Javascript/Typescript 中针对用户设置 AdditionalData

[英]Use Azure AD B2C GraphClient to set AdditionalData against User in Javascript/Typescript

就像问这个问题的人一样,我有一个管理 Azure AD B2C 用户的应用程序。 我正在尝试与那个人做同样的事情,即添加一个具有自定义属性的用户。 不同之处在于我正在尝试在 Javascript/Typescript 中执行此操作,但我没有任何运气。 我正在努力转换的代码是 Dictionary object:

AdditionalData = new Dictionary<string, object>
{
    {"OtherEmail", externalUser.Email},
}

在没有“AdditionalData”属性的情况下创建其他用户没有问题,但是当我将该属性添加到我尝试执行的代码中时,我收到以下错误:

{"message": "A value without a type name was found and no expected type is available. When the model is specified, each value in the payload must have a type which can be either specified in the payload, explicitly by the caller or implicitly inferred from the parent value."}

这是我创建用户的代码:

  const batchIDAttributeName = CreateCustomAttribute("AttName"); //extension_<b2c extension client id>_AttName

  const user = {
    givenName: 'John',
    surname: 'Doe',
    displayName: 'John Doe',
    identities: [
      {
        signInType: "userName",
        issuer: <my tenant>,
        issuerAssignedId: 'JDoe',
      },
    ],
    passwordProfile: {
      password: 'password',
      forceChangePasswordNextSignIn: false,
    },
    additionalData: {
      [batchIDAttributeName]: 201522154
    },
    passwordPolicies: "DisablePasswordExpiration,DisableStrongPassword",
    accountEnabled: true,
    mail: "",
  };

  var result = await client.api("/users").post(user);

我也试过:

additionalData: {
  key: [batchIDAttributeName],
  value: 201522154
}

任何帮助表示赞赏。 我敢肯定,我不可能离得那么远。

创建具有自定义属性的用户时,您不需要添加additionalData数据。

HTTP

POST https://graph.microsoft.com/v1.0/users

{
    "accountEnabled": true,
    "displayName": "Adele Vance",
    "mailNickname": "AdeleV",
    "userPrincipalName": "AdeleV@<b2c-tenant-name>.onmicrosoft.com",
    "passwordProfile": {
        "forceChangePasswordNextSignIn": true,
        "password": "xWwvJ]6NMw+bWH-d"
    },
    "extension_<b2c-extensions-app client id without the dashes '-'>_AttName": "123456"
}

JavaScriptMS Graph 示例

// create Users from Graph
async function createUsers(): Promise<any> {

    const client = createAuthenticatedClient();

    const user = {
        accountEnabled: true,
        displayName: "Adele Vance3",
        mailNickname: "AdeleV3",
        userPrincipalName: "AdeleV3@<b2c-tenant-name>.onmicrosoft.com",
        "passwordProfile" : {
          forceChangePasswordNextSignIn: true,
          password: "xWwvJ]6NMw+bWH-d"
        },
        "extension_xxxxxxxxxxxxxxxxxx_AttName": "123456"
      };
      
    const request = await client.api("/users")
        .post(user)
        .catch((error) => {

            console.log(error);

        });

    console.log(request.value);

}

createUsers();

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM