From 1ef77e284f65e8ba8476156f530d1784d2851b3b Mon Sep 17 00:00:00 2001 From: Ray Luo Date: Wed, 6 Nov 2019 11:26:50 -0800 Subject: [PATCH] Add ResetPassword behavior, and refactor based on latest master --- README_B2C.md | 1 + app.py | 8 -------- app_config_b2c.py | 3 +++ templates/auth_error.html | 5 +++++ templates/index.html | 2 +- templates/login.html | 4 ++++ 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README_B2C.md b/README_B2C.md index ee386e1..8a18121 100644 --- a/README_B2C.md +++ b/README_B2C.md @@ -96,6 +96,7 @@ In the steps below, "ClientID" is the same as "Application ID" or "AppId". * Replace the value of `CLIENT_SECRET` with the key that you recorded. * Replace the value of `signupsignin_user_flow` with `b2c_1_signupsignin1`. * Replace the value of `editprofile_user_flow` with `b2c_1_profileediting1`. + * Replace the value of `resetpassword_user_flow` with `b2c_1_passwordreset1`. * Replace the value of `REDIRECT_PATH` with the path part you set up in **Reply URL**. For example, `/getAToken`. It will be used by this sample app to form an absolute URL which matches your full **Reply URL**. diff --git a/app.py b/app.py index 62feab3..06ee84d 100644 --- a/app.py +++ b/app.py @@ -50,14 +50,6 @@ def logout(): app_config.AUTHORITY + "/oauth2/v2.0/logout" + "?post_logout_redirect_uri=" + url_for("index", _external=True)) -# This page is only used in B2C scenario -@app.route("/edit_profile") -def edit_profile(): - app = _build_msal_app(authority=app_config.B2C_PROFILE_AUTHORITY) - return redirect(app.get_authorization_request_url([], - state=str(uuid.uuid4()), - redirect_uri=url_for("authorized", _external=True))) - @app.route("/graphcall") def graphcall(): token = _get_token_from_cache(app_config.SCOPE) diff --git a/app_config_b2c.py b/app_config_b2c.py index 386cd1f..01e1dbc 100644 --- a/app_config_b2c.py +++ b/app_config_b2c.py @@ -3,6 +3,7 @@ b2c_tenant = "fabrikamb2c" signupsignin_user_flow = "b2c_1_signupsignin1" editprofile_user_flow = "b2c_1_profileediting1" +resetpassword_user_flow = "b2c_1_passwordreset1" authority_template = "https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/{user_flow}" CLIENT_SECRET = "Enter_the_Client_Secret_Here" # Our Quickstart uses this placeholder @@ -17,6 +18,8 @@ tenant=b2c_tenant, user_flow=signupsignin_user_flow) B2C_PROFILE_AUTHORITY = authority_template.format( tenant=b2c_tenant, user_flow=editprofile_user_flow) +B2C_RESET_PASSWORD_AUTHORITY = authority_template.format( + tenant=b2c_tenant, user_flow=resetpassword_user_flow) CLIENT_ID = "Enter_the_Application_Id_here" diff --git a/templates/auth_error.html b/templates/auth_error.html index aab8ec7..2207965 100644 --- a/templates/auth_error.html +++ b/templates/auth_error.html @@ -2,6 +2,11 @@ + + {% if config.get("B2C_RESET_PASSWORD_AUTHORITY") and "AADB2C90118" in result.get("error_description") %} + + + {% endif %}

Login Failure

diff --git a/templates/index.html b/templates/index.html index ff28ad5..1211594 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,7 +12,7 @@

Welcome {{ user.get("name") }}!

{% endif %} {% if config.get("B2C_PROFILE_AUTHORITY") %} -
  • Edit Profile
  • +
  • Edit Profile
  • {% endif %}
  • Logout
  • diff --git a/templates/login.html b/templates/login.html index 135d1b9..b3647a7 100644 --- a/templates/login.html +++ b/templates/login.html @@ -8,6 +8,10 @@

    Microsoft Identity Python Web App

  • Sign In
  • + {% if config.get("B2C_RESET_PASSWORD_AUTHORITY") %} +
  • Reset Password
  • + {% endif %} +