【问题标题】:Microsoft Graph Api - updating PasswordProfile not working when nullMicrosoft Graph Api - 更新 PasswordProfile 在 null 时不起作用
【发布时间】:2021-10-25 19:25:02
【问题描述】:

我有一个 b2c 环境设置并链接到一个允许用户注册的应用程序。

我想按计划运行的过程之一是更新用户的 PasswordProfile,以便在某些情况下我可以强制用户在下次尝试登录时更改密码。

据记录 (https://docs.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=csharp#permissions),我已添加并同意访问 Microsoft Graph 的应用程序的Directory.AccessAsUser.All(委托)权限。

请求:

https://graph.microsoft.com/v1.0/users/{userId}
{
  "passwordProfile": {
    "forceChangePasswordNextSignIn": true
  }
}

当我在 C# 代码或 Postman 中运行它时,它会返回以下错误消息:

"error": {
    "code": "Authorization_RequestDenied",
    "message": "Insufficient privileges to complete the operation.",
    ...

但是,我已经能够通过 https://developer.microsoft.com/en-us/graph/graph-explorer 运行相同的请求,在那里我能够更新用户的 PasswordProfile。

奇怪的是,如果我随后返回 C# 代码或 Postman,并对我在 Graph Explorer 中更新的 SAME 用户运行相同的操作,它现在可以工作了。

因此,我似乎设置了正确的权限,但我只能在 PasswordProfile 尚未为空时更新它。但是,当通过 B2C 屏幕注册时创建用户时,此时 PasswordProfile 设置为 null。

以前有人遇到过这种情况吗?或者能够重现这个?

【问题讨论】:

  • 请分享您如何在 C# 和 Postman 中获取访问令牌的详细信息,并公开错误详细信息,包括请求 ID 和时间戳。我认为是令牌中没有添加权限。

标签: microsoft-graph-api


【解决方案1】:

我需要将应用程序添加为“全局管理员”,详见此处接受的答案:

https://docs.microsoft.com/en-us/answers/questions/9024/error-while-updating-the-password-profile.html

【讨论】:

    猜你喜欢
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    相关资源
    最近更新 更多