【发布时间】:2018-12-19 10:51:14
【问题描述】:
从 Angular 前端和 webapi 作为后端,我正在尝试使用 Graph API 更改密码功能,但出现以下错误:
{"odata.error":{"code":"Authorization_RequestDenied","message":{"lang":"en","value":"访问更改密码操作被拒绝。"} }}
下面是我的代码:
private async void ChangePasswordPostRequest(ChangePasswordModel changePasswordModel){
AuthenticationResult result = await authContext.AcquireTokenAsync(ApplicationConstants.aadGraphResourceId, credential);
HttpClient http = new HttpClient();
string url = ApplicationConstants.aadGraphEndpoint + tenant + "/users/" + "c55f7d4d-f81d-4338-bec7-145225366565" + "/changePassword?" + ApplicationConstants.aadGraphVersion;
HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("POST"), url);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
request.Content = new StringContent(JsonConvert.SerializeObject(new ChangePasswordPostModel() { currentPassword = changePasswordModel.CurrentPassword, newPassword = changePasswordModel.NewPassword }), Encoding.UTF8, "application/json");
HttpResponseMessage response = await http.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
string error = await response.Content.ReadAsStringAsync();
object formatted = JsonConvert.DeserializeObject(error);
}
}
我坚持这一点,任何帮助将不胜感激。提前致谢。
【问题讨论】:
-
IIRC 密码重置需要应用程序的大量权限,如果使用客户端凭据(正如您似乎正在做的那样)。您为您的应用授予了哪些应用权限?您是否也尝试过 MS Graph API:developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/…?
-
感谢@juunas 的回复。我已经在 AD B2C 中授予了所有委派和应用程序权限,但我没有尝试 MS Graph API,因为所有用户管理操作都是使用 Graph API 完成的。为了更改密码,我点击了这个链接:msdn.microsoft.com/en-us/library/azure/ad/graph/api/…
-
如果您只使用客户端 ID 和密码(看起来像您一样)进行呼叫,则需要 应用程序权限。
-
我已经交叉检查,发现所有应用程序权限都分配给了应用程序。
标签: azure azure-ad-b2c