Skip to content

Commit

Permalink
Add ResetPassword behavior, and refactor based on latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
rayluo committed Nov 7, 2019
1 parent e2a819f commit 1ef77e2
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions README_B2C.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down
8 changes: 0 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions app_config_b2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down
5 changes: 5 additions & 0 deletions templates/auth_error.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<html lang="en">
<head>
<meta charset="UTF-8">

{% if config.get("B2C_RESET_PASSWORD_AUTHORITY") and "AADB2C90118" in result.get("error_description") %}
<!-- See also https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-reference-policies#linking-user-flows -->
<meta http-equiv="refresh" content='0;{{_build_auth_url(authority=config["B2C_RESET_PASSWORD_AUTHORITY"])}}'>
{% endif %}
</head>
<body>
<h2>Login Failure</h2>
Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2>Welcome {{ user.get("name") }}!</h2>
{% endif %}

{% if config.get("B2C_PROFILE_AUTHORITY") %}
<li><a href='/edit_profile'>Edit Profile</a></li>
<li><a href='{{_build_auth_url(authority=config["B2C_PROFILE_AUTHORITY"])}}'>Edit Profile</a></li>
{% endif %}

<li><a href="/logout">Logout</a></li>
Expand Down
4 changes: 4 additions & 0 deletions templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ <h1>Microsoft Identity Python Web App</h1>

<li><a href='{{ auth_url }}'>Sign In</a></li>

{% if config.get("B2C_RESET_PASSWORD_AUTHORITY") %}
<li><a href='{{_build_auth_url(authority=config["B2C_RESET_PASSWORD_AUTHORITY"])}}'>Reset Password</a></li>
{% endif %}

<hr>
<footer style="text-align: right">Powered by MSAL Python {{ version }}</footer>
</body>
Expand Down

0 comments on commit 1ef77e2

Please sign in to comment.