Skip to content

Commit 984a301

Browse files
committed
Polishing for App Service
1 parent 27d6dfd commit 984a301

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

.env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Note: If you are using Azure App Service, go to your app's Configuration,
2+
# and then set the following values into your app's "Application settings".
3+
14
FLASK_DEBUG=True
25
# Expects a full tenant id such as "contoso.onmicrosoft.com", or its GUID
36
# Or leave it undefined if you are building a multi-tenant app

.env.sample.b2c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Note: If you are using Azure App Service, go to your app's Configuration,
2+
# and then set the following values into your app's "Application settings".
3+
14
FLASK_DEBUG=True
25
# Expects the display name such as "contoso"
36
TENANT_NAME=<tenant name>

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,28 @@ To get started with this sample, you have two options:
1717
[Quickstart: Add sign-in with Microsoft to a Python web app](https://docs.microsoft.com/azure/active-directory/develop/web-app-quickstart?pivots=devlang-python).
1818
* Use PowerShell scripts that automatically create the Azure AD applications and related objects (passwords, permissions, dependencies) for you, and then modify the configuration files. Follow the steps in the [App Creation Scripts README](./AppCreationScripts/AppCreationScripts.md).
1919

20+
# Deployment
21+
22+
Once you finish testing this web app locally, you can deploy it to your production.
23+
You may choose any web app hosting services you want.
24+
Here we will describe how to deploy it to
25+
[Azure App Service](https://azure.microsoft.com/en-us/products/app-service).
26+
27+
* Follow the ["Quickstart: Deploy a Python (Django or Flask) web app to Azure App Service"](https://learn.microsoft.com/en-us/azure/app-service/quickstart-python),
28+
but replace its sample app (which does not do user sign-in) with this web app.
29+
30+
* In particular, if you choose to ["deploy using Local Git" in "step 3 - Deploy your application code to Azure"](https://learn.microsoft.com/en-us/azure/app-service/quickstart-python?tabs=flask%2Cwindows%2Cazure-cli%2Clocal-git-deploy%2Cdeploy-instructions-azportal%2Cterminal-bash%2Cdeploy-instructions-zip-azcli#3---deploy-your-application-code-to-azure),
31+
an [application-scope credential](https://learn.microsoft.com/en-us/azure/app-service/deploy-configure-credentials?tabs=portal#appscope)
32+
will be automatically created with the shape as `your_app_name\$your_app_name`.
33+
But your actual git username is only the `$your_app_name` part.
34+
35+
* Do not forget to setup
36+
[several environment variables](https://github.com/Azure-Samples/ms-identity-python-webapp/blob/master/.env.sample)
37+
needed by this sample.
38+
Otherwise your website will usually render a blank "Internal Error" page
39+
(Flask's debug mode output does not seem to be relayed by App Service).
40+
41+
2042
## Contributing
2143

2244
If you find a bug in the sample, please raise the issue on [GitHub Issues](../../issues).

app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ def logout():
4848

4949
@app.route("/")
5050
def index():
51+
if not (app.config["CLIENT_ID"] and app.config["CLIENT_SECRET"]):
52+
# This check is not strictly necessary.
53+
# You can remove this check from your production code.
54+
return """Almost there. Did you forget to set up
55+
<a target=_blank
56+
href="https://github.com/Azure-Samples/ms-identity-python-webapp/blob/master/.env.sample">
57+
necessary environment variables</a> for your deployment?"""
5158
if not auth.get_user():
5259
return redirect(url_for("login"))
5360
return render_template('index.html', user=auth.get_user(), version=identity.__version__)

0 commit comments

Comments
 (0)