var client = graph.GetGraphClient();
try
{
//get existing user
var user = await GetGraphUser(userId, cancellationToken);
//Ensure the PasswordProfile exists before attempting to update the password
if (user.PasswordProfile == null)
{
user.PasswordProfile = new PasswordProfile
{
Password = newPassword,
ForceChangePasswordNextSignIn = true
};
}
else
{
// Update the password if PasswordProfile is present
user.PasswordProfile.Password = newPassword;
user.PasswordProfile.ForceChangePasswordNextSignIn = true;
}
await client.Users[userId].PatchAsync(user, cancellationToken: cancellationToken);
}
catch (Microsoft.Graph.Models.ODataErrors.ODataError ex)
{
GraphExceptionsHandler.Handle(ex);
}
这是我的代码,我想使用图形客户端重置 entraId 中用户的密码。但我收到错误“权限不足”。我尝试了很多权限
如果您代表用户进行身份验证,则登录用户必须至少具有 用户管理员 角色才能更改密码。