gpt4 book ai didi

microsoft-graph-api - Microsoft Graph API - 更新密码 - 权限不足,无法完成操作

转载 作者:行者123 更新时间:2023-12-01 12:18:55 24 4
gpt4 key购买 nike

我正在尝试通过 Microsoft Graph API 更新用户,我可以更新 DisplayName但是 PasswordProfile我收到一个错误:

Insufficient privileges to complete the operation.

以下是我在 http://jwt.io 处解码 JWT token 时与 token 关联的角色:

"roles": [
"User.ReadWrite.All",
"Directory.ReadWrite.All",
"Group.ReadWrite.All"
],

基于 the documentation似乎这些权限就足够了。

这是我的代码(取自控制台应用程序),我能够通过 Fiddler 找出调用失败, UpdateAsync不会抛出异常。

try
{
var userId = "9a5413cd-85ff-4ad1-ab2f-b443941abd8e";
var token = GetToken().Result;
System.Console.Write($"Token: {token}");

var newPassword = "TwDx5zgHxe51DZZ";
GraphServiceClient graphClient = GetAuthenticatedClient(token);

// This works -- Updating Display name
graphClient.Users[userId].Request().UpdateAsync(new User
{
DisplayName = "NewDisplayName"
});

// This does not work - Updating password
graphClient.Users[userId].Request().UpdateAsync(new User
{
PasswordProfile = new PasswordProfile
{
Password = newPassword,
ForceChangePasswordNextSignIn = true
}
});
System.Console.WriteLine("---Update Complete---");
}
catch (Exception e)
{
System.Console.WriteLine(e);
}

获取token的方法:

public async Task<string> GetToken()
{
// Constants
var tenant = "dev-mytenantmydomaincom";
var resource = "https://graph.microsoft.com/";
var clientID = "XXXXXXXX-87ef-494d-b921-cf8956006b0e";
var secret = "zgkzas2THJLiD5XXXXXX";

// Ceremony
var authority = $"https://login.microsoftonline.com/{tenant}";
var authContext = new AuthenticationContext(authority);
var credentials = new ClientCredential(clientID, secret);
var authResult = await authContext.AcquireTokenAsync(resource, credentials);
return authResult.AccessToken;
}

以下是 Fiddler 的完整回复:

HTTP/1.1 403 Forbidden
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: application/json
request-id: 6edcf194-7705-4cd7-8144-767925cc9ee4
client-request-id: 6edcf194-7705-4cd7-8144-767925cc9ee4
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"East US","Slice":"SliceB","ScaleUnit":"001","Host":"AGSFE_IN_27","ADSiteName":"EST"}}
Duration: 69.2849
Date: Thu, 31 Aug 2017 13:15:34 GMT

{
"error": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
"innerError": {
"request-id": "6edcf194-7705-4cd7-8144-767925cc9ee4",
"date": "2017-08-31T13:15:34"
}
}
}

最佳答案

密码是一个特别敏感的数据集,因此对它们具有一些独特的权限。来自 documentation :

When updating the passwordProfile property, the following scope is required: Directory.AccessAsUser.All.



Directory.AccessAsUser.All是需要管理员的委托(delegate)权限。换句话说,它允许某个全局管理员更改其他其他用户的 passwordProfile .

如果您希望允许最终用户自己更改密码,还可以使用 ChangePassword SDK中的方法:

await graphClient.Me.ChangePassword("current-pwd, "new-pwd").Request().PostAsync();

注意:这也需要管理员同意 DirectoryAccessAsUser.All在用户执行之前)

请记住 DirectoryAccessAsUser.All是“委托(delegate)”而不是“应用程序”权限范围。这意味着它仅受 Authorization Code 支持。和 Implicit流动;它不适用于使用 Client Credentials 的守护程序/服务场景流动。

如果您考虑能够随意更改用户密码的非交互式应用程序可能实现的潜在攻击,那么这种限制的原因就很清楚了。

关于microsoft-graph-api - Microsoft Graph API - 更新密码 - 权限不足,无法完成操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45982912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com