How to reset password using Microsoft Graph Client

2020-07-30 01:29发布

问题:

How can a user reset his password using Microsoft Graph client. I am not able to find the right way to do it. Thanks.

回答1:

Tom is correct about this the Delegate Scope Directory.AccessAsUser.All allowing the signed-in user to change their password. The standard User.ReadWrite can update most properties, but it cannot update the user's password.

It is, however, a supported operation. The SDK includes the PasswordProfile class you need to pass into Graph. The syntax would look something like this:

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


回答2:

How can a user reset his password using Microsoft Graph client

Unfortuntly, it seems that we can't reset password with Microsoft Graph client currently. According to the Microsoft graph update user API, we required to use the delegated permission type: Directory.AccessAsUser.All.

When updating the passwordProfile property, the following permission is required: Directory.AccessAsUser.All.

Delegated permissions are used by apps that have a signed-in user present. For these apps either the user or an administrator consents to the permissions that the app requests and the app is delegated permission to act as the signed-in user when making calls to Microsoft Graph.