c# - Microsoft Graph API 更改用户密码返回错误权限不足,无法完成操作
问题描述
当我尝试更改 Azure AD 用户密码时,我不断收到此错误:"code": "Authorization_RequestDenied", "message": "Insufficient privileges to complete the operation."
我添加了所有需要的权限,并使用 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);
我也尝试了这两个链接中的所有内容,但没有任何帮助:
解决方案
推荐阅读
- php - 如何从php文件中的字符串中删除方括号?
- javascript - 如何向对象添加元素键和值?
- python - 将对象转换为 datetime64[ns]
- umbraco - Umbraco Parse 错误与 Google AMP 样式样板播放
- python - 使用 `pip install -e .` 通过 `console_scripts` 安装的 Python 可执行脚本可以在路径中找到,但不能在 `pip install ` 中找到。
- azure - 有没有办法在发布管理中使用相同的应用服务部署多个项目?
- angular - Angular - 需要在导出类的内部/外部定义哪些变量?
- html - 使用引导程序如何并排排列两个文本框
- tensorflow - tensorflow的会话运行接口是可重入的吗?
- c# - 如何使 WT41N0 扫描仪不扫描条形码或将回车符传递给 C# 中的 messageBox