Skip to content

Commit

Permalink
Suggestions to deploy branch (#98)
Browse files Browse the repository at this point in the history
* Pamelas suggestions

* Update requirements.txt

Co-authored-by: Ray Luo <[email protected]>

* Update templates/login.html

Co-authored-by: Ray Luo <[email protected]>

* Ul changes, back button back

* Update templates/login.html

Co-authored-by: Ray Luo <[email protected]>

---------

Co-authored-by: Ray Luo <[email protected]>
  • Loading branch information
pamelafox and rayluo authored Mar 28, 2023
1 parent c57bb4e commit 24fb1d7
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 28 deletions.
6 changes: 2 additions & 4 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Note: If you are using Azure App Service, go to your app's Configuration,
# and then set the following values into your app's "Application settings".

FLASK_DEBUG=True
CLIENT_ID=<client id>
CLIENT_SECRET=<client secret>
# Expects a full tenant name such as "contoso.onmicrosoft.com", or its GUID
# Or leave it undefined if you are building a multi-tenant app
#TENANT_ID=<tenant id>
CLIENT_ID=<client id>
CLIENT_SECRET=<client secret>
8 changes: 3 additions & 5 deletions .env.sample.b2c
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Note: If you are using Azure App Service, go to your app's Configuration,
# and then set the following values into your app's "Application settings".

FLASK_DEBUG=True
# Expects the display name such as "contoso"
TENANT_NAME=<tenant name>
CLIENT_ID=<client id>
CLIENT_SECRET=<client secret>
# Expects the display name such as "contoso"
TENANT_NAME=<tenant name>
SIGNUPSIGNIN_USER_FLOW=B2C_1_profile_editing
EDITPROFILE_USER_FLOW=B2C_1_reset_password
RESETPASSWORD_USER_FLOW=B2C_1_signupsignin1
RESETPASSWORD_USER_FLOW=B2C_1_signupsignin1
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ Here we will describe how to deploy it to
will be automatically created with the shape as `your_app_name\$your_app_name`.
But your actual git username is only the `$your_app_name` part.

* Do not forget to setup
[several environment variables](https://github.com/Azure-Samples/ms-identity-python-webapp/blob/master/.env.sample)
needed by this sample.
Otherwise your website will usually render a blank "Internal Error" page
(Flask's debug mode output does not seem to be relayed by App Service).
* [Configure your app's settings](https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal#configure-app-settings) to define [these environment variables](https://github.com/Azure-Samples/ms-identity-python-webapp/blob/master/.env.sample).


## Contributing
Expand Down
5 changes: 1 addition & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ def index():
if not (app.config["CLIENT_ID"] and app.config["CLIENT_SECRET"]):
# This check is not strictly necessary.
# You can remove this check from your production code.
return """Almost there. Did you forget to set up
<a target=_blank
href="https://github.com/Azure-Samples/ms-identity-python-webapp/blob/master/.env.sample">
necessary environment variables</a> for your deployment?"""
return render_template('config_error.html')
if not auth.get_user():
return redirect(url_for("login"))
return render_template('index.html', user=auth.get_user(), version=identity.__version__)
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Flask>=2
# Our how-to docs will use --debug parameter which is only available in Flask 2.2+
Flask>=2.2
# If Flask-Session is not maintained in future, Flask-Session2 should work as well
Flask-Session>=0.3.2,<0.5
werkzeug>=2
Expand Down
3 changes: 1 addition & 2 deletions templates/auth_error.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<html lang="en">
<head>
<meta charset="UTF-8">

{% if config.get("B2C_RESET_PASSWORD_AUTHORITY") and "AADB2C90118" in result.get("error_description") %} <!-- This will be reached when user forgot their password -->
<!-- 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;{{config.get("B2C_RESET_PASSWORD_AUTHORITY")}}?client_id={{config.get("CLIENT_ID")}}'>
{% endif %}
<title>Microsoft Identity Python Web App: Error</title>
</head>
<body>
<h2>Login Failure</h2>
Expand All @@ -18,4 +18,3 @@ <h2>Login Failure</h2>
<a href="{{ url_for('index') }}">Homepage</a>
</body>
</html>

18 changes: 18 additions & 0 deletions templates/config_error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Microsoft Identity Python Web App: Error</title>
</head>
<body>
<h2>Config Missing</h2>
<p>
Almost there. Did you forget to set up
<a target=_blank
href="https://learn.microsoft.com/azure/active-directory/develop/web-app-quickstart?pivots=devlang-python#step-5-configure-the-sample-app">
necessary environment variables</a> for your deployment?
</p>
<hr>
<a href="{{ url_for('index') }}">Homepage</a>
</body>
</html>
1 change: 1 addition & 0 deletions templates/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Microsoft Identity Python Web App: API</title>
</head>
<body>
<a href="javascript:window.history.go(-1)">Back</a> <!-- Displayed on top of a potentially large JSON response, so it will remain visible -->
Expand Down
4 changes: 4 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Microsoft Identity Python Web App: Index</title>
</head>
<body>
<h1>Microsoft Identity Python Web App</h1>
<h2>Welcome {{ user.get("name") }}!</h2>

<ul>
{% if config.get("ENDPOINT") %}
<li><a href='/call_downstream_api'>Call a downstream API</a></li>
{% endif %}
Expand All @@ -16,6 +18,8 @@ <h2>Welcome {{ user.get("name") }}!</h2>
{% endif %}

<li><a href="/logout">Logout</a></li>
</ul>

<hr>
<footer style="text-align: right">Powered by Identity Web {{ version }}</footer>
</body>
Expand Down
15 changes: 8 additions & 7 deletions templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Microsoft Identity Python Web App: Login</title>
</head>
<body>
<h1>Microsoft Identity Python Web App</h1>

{% if user_code %}
<ol>
<li>To sign in, type <b>{{ user_code }}</b> into
<a href='{{ auth_uri }}' target=_blank>{{ auth_uri }}</a>
to authenticate.
</li>
<li>And then <a href="{{ url_for('auth_response') }}">proceed</a>.</li>
<li>To sign in, type <b>{{ user_code }}</b> into
<a href='{{ auth_uri }}' target=_blank>{{ auth_uri }}</a>
to authenticate.
</li>
<li>And then <a href="{{ url_for('auth_response') }}">proceed</a>.</li>
</ol>
{% else %}
<li><a href='{{ auth_uri }}'>Sign In</a></li>
<ul><li><a href='{{ auth_uri }}'>Sign In</a></li></ul>
{% endif %}

{% if config.get("B2C_RESET_PASSWORD_AUTHORITY") %}
<li><a href="{{config.get('B2C_RESET_PASSWORD_AUTHORITY')}}?client_id={{config.get('CLIENT_ID')}}">Reset Password</a></li>
<a href="{{config.get('B2C_RESET_PASSWORD_AUTHORITY')}}?client_id={{config.get('CLIENT_ID')}}">Reset Password</a>
{% endif %}

<hr>
Expand Down

0 comments on commit 24fb1d7

Please sign in to comment.