从 API 调用 Microsoft Graph 时 Azure AD B2C 重置密码选项

标签 azure azure-active-directory microsoft-graph-api azure-ad-b2c microsoft-graph-sdks

有没有办法从仅授予 Microsoft Graph 应用程序权限的 B2C 应用重置 B2C 用户的密码?

我们有一个场景, Multi-Tenancy 应用程序中有非电子邮件用户,我们需要允许管理员重置密码。为了提供用户管理功能,我们有一个使用 .net Microsoft.Graph SDK 的应用服务。重置用户密码的唯一方法似乎是使用 resestPassword ,但这不能由应用程序调用。

据我所知,我们唯一的选择是为此任务设置一个用户并将其详细信息存储在 Azure Key Vault 中,然后让应用程序以该用户身份登录以调用端点。

如果可能的话,我真的很想避免这种方法,而且这似乎是一种常见的情况,所以我希望有更好的方法?

最佳答案

我尝试在我的环境中重现相同的结果,并得到如下结果:

Note that: As per the MsDoc, currently it is not possible to reset password for users with granting only Application permissions.

使用应用程序权限重置用户密码将导致以下错误:

POST https://graph.microsoft.com/v1.0/users/UserID/authentication/passwordMethods/28c10230-6103-485e-b985-444c60001490/resetPassword 
Content-type: application/json
 {
 "newPassword": "xxxx"
  }

enter image description here

或者,我创建了一个 Azure AD 应用程序并授予了以下 API 权限:

enter image description here

向服务主体授予用户管理员角色,如下所示:

enter image description here

现在使用以下参数通过客户端凭据流程生成访问 token :

GET https://login.microsoftonline.com/TenantID/oauth2/v2.0/token

client_id:ClientID
client_secret:ClientSecret
scope:https://graph.microsoft.com/.default
grant_type:client_credentials

enter image description here

使用上面生成的 token ,尝试使用以下查询重置密码:

PATCH https://graph.microsoft.com/v1.0/users/{id}
Content-type: application/json

{
  "passwordProfile": {
      "password": "xxxx"
  }
}

enter image description here

您可以根据您的要求使用forceChangePasswordNextSignIn参数。

引用文献:

Azure Reset Password using Graph API by CarlZhao-MSFT

Reset a user's password in ADB2C using MS Graph API by kh_Ro

关于从 API 调用 Microsoft Graph 时 Azure AD B2C 重置密码选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75204968/

相关文章:

javascript - Azure Functions Node.js 自定义入口点

azure - 我如何知道对我的机器人的请求源自 Teams?

java - 如何获取作为本地域名同步到 Azure AD 的 Windows 域 FQDN?

onedrive - 如何获取 office365 onedrive 中包含的所有项目

azure - 应用服务因未知原因不可用

c# - 如何使用反射重构重复代码

c# - 在 ASP.net MVC 中划分大任务的最佳实践

azure-active-directory - Authorization_IdentityNotFound 第一次请求 Microsoft Graph API,

c# - 无法使用 Microsoft Graph API 创建事件

c# - 如何使用 .Net Client SDK 从 Microsoft Graph 获取我所属的管理员角色?