Handle "Forgot your password" / "Reset password" in Azure B2C Activity Directory "SignInSignUp" policy
When you use Azure B2C Activity Directory "SignInSignUp" policy in your application, then you will see below screen shot signin /signup pop up window.
If you click on "Forgot your password?", and the login is failure at this code "await PublicClientApp.AcquireTokenAsync(Scopes, GetUserByPolicy(PublicClientApp.Users, PolicySignUpSignIn), UIBehavior.SelectAccount, string.Empty, null, Authority);".
You can catch this error and the error message should contains "AADB2C90118", and then you can handle this error to invoke "Reset Password Service" with following code:
AuthenticationResult authResult= await PublicClientApp.AcquireTokenAsync(Scopes, GetUserByPolicy(PublicClientApp.Users, PolicySignUpSignIn), UIBehavior.SelectAccount, string.Empty, null, AuthorityResetPassword);You can retrieve user name and "id_token" from "authResult" from above code. Refer to Azure B2C sample project "https://github.com/Azure-Samples/active-directory-b2c-dotnet-uwp.git".
Tips: you don't have to create a Web API as the sample did to handle the policy invocation, and just use above code to execute is fine. The "Scopes" variable is defined as below:
string[] Scopes = { "" };
Comments
Post a Comment