Azure AD B2C更新用户登录名称导致错误

时间:2019-06-17 14:16:12

标签: c# azure azure-ad-b2c azure-ad-graph-api

当我尝试更新SignInNames的列表时,出现错误消息: Resource <EMAIL ADDRESS> does not exist or one of its queried reference-property objects are not present

var currentUser = await GetUserByUserNameAsync(userId); // this gets the user
var signinNames = currentUser.SignInNames.ToList();
signinNames.Add(new SignInName
{
   Type = "emailAddress",
   Value = newEmailaddress
});
var data = new B2CChangeEmailAddressData()
{
    SignInNames = signinNames
};
var response = await _graphApi.SendAsync(new HttpMethod("PATCH"), $"users/{userId}", null, data);

然后返回错误。 我使用类似的代码来更新密码,效果很好。我在俯视什么吗?

1 个答案:

答案 0 :(得分:0)

所以,我所做的是:

  • 我通过用户的登录名(电子邮件地址)吸引了用户
  • 我尝试使用登录名来编辑用户

第一个可能,但第二个不可能。我必须使用ObjectId更新用户。因此代码应为:

var currentUser = await GetUserByUserNameAsync(userId);
var path = $"users/{currentUser.ObjectId}";
var signinNames = new List<SignInName>();
signinNames.Add(new SignInName
{
     Type = "emailAddress",
     Value = newEmailaddress
});
var data = new B2CChangeEmailAddressData()
{
     SignInNames = signinNames
};

var response = await _graphApi.SendAsync(new HttpMethod("PATCH"), path, null, data);