![](/img/trans.png)
[英]Blazor WASM using Azure AD B2C fails calling Microsoft.Graph api
[英]Azure AD B2C reset password options when calling Microsoft Graph from an API
有什么方法可以從僅授予 Microsoft Graph 應用程序權限的 b2c 應用程序重置 B2C 用戶的密碼?
我們有一個場景,在多租戶應用程序中有非 email 用戶,我們需要允許管理員重置密碼。 為了提供用戶管理功能,我們有一個應用程序服務,它使用 .net Microsoft.Graph SDK。似乎重置用戶密碼的唯一方法是使用resestPassword ,但這不能被應用程序調用。
據我所知,對我們開放的唯一選項是為此任務設置一個用戶並將其詳細信息存儲在 Azure Key vault 中,然后讓應用以用戶身份登錄以調用端點。
如果可能的話,我真的很想避免這種方法,這似乎是一種常見的情況,所以我希望有更好的方法?
您好,您可以使用更新用戶來重置 B2C 用戶的密碼。
PATCH https://graph.microsoft.com/v1.0/users/{id}
Content-type: application/json
{
"passwordProfile": {
"forceChangePasswordNextSignIn": false,
"password": "xWwvJ]6NMw+bWH-d"
}
}
更多信息: https://learn.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=http#permissions
我試圖在我的環境中重現相同的內容並得到如下結果:
請注意:根據MsDoc ,目前無法為僅授予應用程序權限的用戶重置密碼。
重置具有應用程序權限的用戶密碼將導致以下錯誤:
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 權限:
將用戶管理員角色授予服務主體,如下所示:
現在使用以下參數通過客戶端憑證流生成訪問令牌:
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
使用上面生成的令牌,嘗試使用以下查詢重置密碼:
PATCH https://graph.microsoft.com/v1.0/users/{id}
Content-type: application/json
{
"passwordProfile": {
"password": "xxxx"
}
}
您可以根據需要使用forceChangePasswordNextSignIn
參數。
參考:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.