【发布时间】:2021-07-19 21:59:16
【问题描述】:
无法使用 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.
在阅读上述内容之前,我尝试使用以下代码更改密码:
实例化 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 的情况下更改密码?
【问题讨论】:
-
我可以使用graph api更改密码。
-
您使用graph api修改密码时有没有报错?
标签: azure asp.net-core asp.net-web-api azure-active-directory microsoft-graph-api