【发布时间】:2020-10-17 11:23:07
【问题描述】:
我已经克隆了 MS Identity DotNetCore B2C Account Management 代码示例并为我的 B2C 租户配置了它。 get user 和 delete user 命令都可以工作。但是,当我尝试使用命令 [5] Update user password 时遇到此错误:
Code: Authorization_RequestDenied Message: Insufficient privileges to complete the operation.
this Microsoft support issue for Office 365 的描述似乎与我遇到的重叠。这意味着管理员帐户的级别高于应用程序可以触及的级别,因为该应用程序不是 AD 中的管理员。
那么,应用程序可以管理普通的非管理员用户,但不能管理管理员帐户?我理解正确吗。如果是这样,有没有办法提升我注册的应用程序的权限,以便更新管理员和非管理员帐户的密码?
对示例的唯一更改是在 appsettings.json 中,并且需要对 "TenantId"、"AppId" 和 "ClientSecret" 的值进行预期的自定义。
我已经注册了一个应用程序并为 Graph API 授予了以下权限:
- AuditLog.ReadAll
- Directory.ReadWriteAll
- UserManageIdentities.All
- User.ReadWrite.All
这是尝试更新用户密码的代码:
public static async Task SetPasswordByUserId(GraphServiceClient graphClient)
{
Console.Write("Enter user object ID: ");
string userId = Console.ReadLine();
Console.Write("Enter new password: ");
string password = Console.ReadLine();
Console.WriteLine($"Looking for user with object ID '{userId}'...");
var user = new User
{
PasswordPolicies = "DisablePasswordExpiration,DisableStrongPassword",
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = false,
Password = password,
}
};
try
{
// Update user by object ID
await graphClient.Users[userId]
.Request()
.UpdateAsync(user);
Console.WriteLine($"User with object ID '{userId}' successfully updated.");
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.Message);
Console.ResetColor();
}
}
【问题讨论】:
标签: c# azure .net-core microsoft-graph-api azure-ad-b2c