gpt4 book ai didi

arrays - 如何使用graph api在azure b2c中创建多个用户?

转载 作者:行者123 更新时间:2023-12-03 01:07:38 26 4
gpt4 key购买 nike

正如标题所示,我希望能够从数据库中获取多个用户并将它们添加到我的 Azure B2C 租户中。我已经使用 B2C 图形客户端成功创建了单个用户。我还想知道是否有人创建了 json 模式来帮助使用 B2C 图形客户端创建用户。

最佳答案

由于您已使用 B2C 图形客户端成功创建用户,因此您可以采用相同的方式发送多创建用户 POST 请求来创建多个用户。例如,您可以将用户从数据库读取到数据表中,然后循环数据表,初始化其中的用户对象并发送创建用户请求。例如引用this code sample ,您可以尝试以下代码来创建用户:

private static void CreateUser()
{

//here you need to loop datatable and assign values
for (int i = 0; i < 2; i++)
{
UserData user = new UserData();
user.accountEnabled = true;
SignInName sn = new SignInName();
sn.type = "emailAddress";
sn.value = "nanyuTest"+i+"@nanyutestb2c.onmicrosoft.com";
user.signInNames = new List<SignInName>();
user.signInNames.Add(sn);
user.creationType = "LocalAccount";
user.displayName = "nan yu";
user.mailNickname = "nanyuTest" + i;
PasswordProfile pf = new PasswordProfile();
pf.password = "P@ssword!";
pf.forceChangePasswordNextLogin = false;
user.passwordProfile = pf;
user.passwordPolicies = "DisablePasswordExpiration";
string json = JsonConvert.SerializeObject(user);
object formatted = JsonConvert.DeserializeObject(client.CreateUser(json).Result);

Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(JsonConvert.SerializeObject(formatted, Formatting.Indented));
}
}

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

public class PasswordProfile
{
public string password { get; set; }
public bool forceChangePasswordNextLogin { get; set; }
}

public class UserData
{
public bool accountEnabled { get; set; }
public List<SignInName> signInNames { get; set; }
public string creationType { get; set; }
public string displayName { get; set; }
public string mailNickname { get; set; }
public PasswordProfile passwordProfile { get; set; }
public string passwordPolicies { get; set; }
public string city { get; set; }
public object country { get; set; }
public object facsimileTelephoneNumber { get; set; }
public string givenName { get; set; }
public object mail { get; set; }
public object mobile { get; set; }
public string postalCode { get; set; }
public object preferredLanguage { get; set; }
public string state { get; set; }
public object streetAddress { get; set; }
public string surname { get; set; }
public object telephoneNumber { get; set; }
}

关于用户实体可选字段的详细信息,您可以在Azure AD Graph API entity reference中找到.

关于arrays - 如何使用graph api在azure b2c中创建多个用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43827759/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com