使用Microsoft Graph更改Azure AD的密码

我计划使用Azure AD Graph API,但随后在Microsoft文档中注意到有关使用Microsoft Graph API的建议。

是否提供了更改用户密码的文档?

string result = Task.Run(async() => { return await GetAccessToken(); }).GetAwaiter().GetResult(); var graphserviceClient = new GraphServiceClient( new DelegateAuthenticationProvider( (requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", result); return Task.FromResult(0); })); var changePasswordRequest = graphserviceClient.Me.ChangePassword("oldpassword", "newpassword"); 

但是我认为这还不够。 有可用的文件吗?

您可以更新passwordProfile属性以更改当前用户的密码。 请参考以下代码:

 await graphClient.Me.Request().UpdateAsync(new User { PasswordProfile = new PasswordProfile { Password = "YourPassword", ForceChangePasswordNextSignIn = false }, }); 

根据文档 ,执行此API需要以下范围之一: User.ReadWrite User.ReadWrite.All Directory.ReadWrite.All

编辑: 文档已使用以下注释进行更新:

更新passwordProfile属性时,需要以下范围: Directory.AccessAsUser.All