azure - 通过 Web API 而不是 Graph API 重置 Azure AD 密码

标签 azure asp.net-core asp.net-web-api azure-active-directory microsoft-graph-api

无法使用 Graph API 更改密码

Unsupported end-user operations
    Any end user resetting their own password by using PowerShell version 1, version 2, or the Microsoft Graph API.

https://learn.microsoft.com/en-us/azure/active-directory/authentication/concept-sspr-writeback#unsupported-writeback-operations

在阅读上述内容之前,我尝试使用以下代码更改密码:

实例化GraphServiceClient

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();
...
}

允许用户重置密码的步骤是什么(以编程方式/Azure 门户)?是否有其他方法可以在不使用 Graph API 的情况下更改密码?

最佳答案

我的解决方案是配置 Azure AD Connect 的帐户权限

我必须在 Azure AD Connect 中启用密码写回;-)

关于azure - 通过 Web API 而不是 Graph API 重置 Azure AD 密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68175600/

相关文章:

Azure 服务总线示例 "No connection could be made because the target machine actively refused it"

azure - 您如何决定 Azure 中最合适的大数据处理技术堆栈?

azure - Azure DevOps 中的 "Build after the previous execution has succeeded"

c# - 如何在容器中配置 dbcontext?

c# - 通过 Serilog 在 Azure 上记录 ASP.NET Core

c# - EF Core 1.1 到 WebApi Core - 添加迁移失败

c# - 尝试通过来自数据库触发器的 Web 请求执行 "EXECUTE Master.dbo.xp_CmdShell"命令以在本地创建文本文件时发生错误

c# - 如何从 Azure 移动服务获取请求返回所有行?

asp.net-web-api - 如何在 MVC4 Web API 的自定义绑定(bind)器中调用默认模型绑定(bind)?

azure - Azure Active Directory 中供应用程序使用的角色和权限