通过图表 API 重置密码根本不会更改密码

Reset Password through Graph API doesn't change the Password at all

下面的代码根本不会更改密码

UPDATE(添加了 graphClient 对象的实例化):

string clientId = Configuration["AzureAd:ClientId"];
string tenantId = Configuration["AzureAd:TenantId"];
string authority = Configuration["AzureAd:Authority"]; 

string[] scopes = new string[] { "User.Read", "Directory.AccessAsUser.All", "User.Invite.All" };

IPublicClientApplication app = PublicClientApplicationBuilder.Create(clientId)
    .WithAuthority(authority)
    .WithTenantId(tenantId)
    .Build();

var securePassword = new SecureString();
foreach (char c in user.Password.ToCharArray())  // you should fetch the password
    securePassword.AppendChar(c);  // keystroke by keystroke

var tokens = app.AcquireTokenByUsernamePassword(scopes, user.UserName, securePassword).ExecuteAsync().Result;

graphClient = new GraphServiceClient(
    new DelegateAuthenticationProvider(x =>
    {
        x.Headers.Authorization = new AuthenticationHeaderValue(
            "Bearer", tokens.AccessToken);

        return Task.FromResult(0);
    }));

...

public async Task<ActionResult> ResetPassword([FromBody] JObject data)
{
    try
    {
        await graphClient.Me
        .ChangePassword(data["currentPassword"].ToString(), data["newPassword"].ToString())
        .Request()
        .PostAsync();
...
}

调试时,代码运行流畅,没有任何错误或问题。 通常我应该使用新密码登录。遗憾的是,旧密码是唯一的登录方式。是否有其他要求或我需要解决的其他范围(“Directory.AccessAsUser.All”除外)?

据我所知,我们无法使用 Graph 更改密码 API

  • 不支持的最终用户操作
    • 任何使用 PowerShell 版本 1、版本 2 或 Microsoft Graph API.
    • 重置自己密码的最终用户

在此处阅读更多信息 On-premises password writeback with self-service password reset - Azure Active Directory | Microsoft Docs