Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Microsoft Graph API change user password返回错误:权限不足,无法完成操作_C#_Azure_Http_Azure Active Directory - Fatal编程技术网

C# Microsoft Graph API change user password返回错误:权限不足,无法完成操作

C# Microsoft Graph API change user password返回错误:权限不足,无法完成操作,c#,azure,http,azure-active-directory,C#,Azure,Http,Azure Active Directory,当我试图更改Azure AD用户密码时,我不断收到以下错误:“code”:“Authorization\u RequestDenied”,“message”:“权限不足,无法完成操作。” 我添加了所有需要的权限,并使用OAuth 2.0 ROPC进行授权。这是授权请求: var client = new RestClient("https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token"); client.Ti

当我试图更改Azure AD用户密码时,我不断收到以下错误:
“code”:“Authorization\u RequestDenied”,“message”:“权限不足,无法完成操作。”

我添加了所有需要的权限,并使用OAuth 2.0 ROPC进行授权。这是授权请求:

var client = new RestClient("https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("client_id", "clientID");
request.AddParameter("scope", "user.read openid profile offline_access");
request.AddParameter("client_secret", "xxxxxxxxxxxxx");
request.AddParameter("username", "userr@xxxxxxx.onmicrosoft.com");
request.AddParameter("password", "xxxxxxxxx");
request.AddParameter("grant_type", "password");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
这是用户更新请求:

var client = new RestClient("https://graph.microsoft.com/v1.0/{userId}");
client.Timeout = -1;
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "Bearer tokenFromAuthorization");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "\r\n{\r\n      \"passwordProfile\" : {\r\n      \"password\": \"xxxxxxxxxx\",\r\n      \"forceChangePasswordNextSignIn\": false\r\n    }\r\n}\r\n\r\n\r\n",  ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
此外,我尝试了这两个链接的所有内容,但都无济于事:

  • 权限屏幕截图:
    您的api错误,请尝试将其更改为
    https://graph.microsoft.com/v1.0/me
    ,请参阅:api。如果使用此api修改用户密码,则必须具有
    用户管理员
    全局管理员
    的角色


    如果希望普通用户角色能够更改自己的密码,则可以使用
    /changePassword
    端点。我以前已经回答过,您可以将其用作参考。

    用于解析令牌并提供屏幕截图。您授予了哪些权限?更新
    密码配置文件
    属性时,需要以下权限:
    目录.accessUser.All
    。如果您想更改另一个用户的密码,您必须是
    用户管理员
    全局管理员
    。请尝试并告诉我结果。谢谢。