有没有办法从仅授予 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"
}
或者,我创建了一个 Azure AD 应用程序并授予了以下 API 权限:
向服务主体授予用户管理员角色,如下所示:
现在使用以下参数通过客户端凭据流程生成访问 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
使用上面生成的 token ,尝试使用以下查询重置密码:
PATCH https://graph.microsoft.com/v1.0/users/{id}
Content-type: application/json
{
"passwordProfile": {
"password": "xxxx"
}
}
您可以根据您的要求使用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/