Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions django-web-app/.env.sample.b2c

This file was deleted.

34 changes: 12 additions & 22 deletions django-web-app/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Integrating Microsoft Entra ID with a Python web application written in Django

This is a multi-purpose [Django](https://www.djangoproject.com/) web app sample.
Write your app like this once, and the same implementation will support 4x2=8 scenarios.
The same implementation supports Microsoft Entra ID, External ID, and External ID with a custom domain.

| | Microsoft Entra ID | External ID | External ID with Custom Domain | Azure AD B2C |
|----------------|--------------------|-------------|--------------------------------|--------------|
| Web App Sign-In & Sign-Out | ✓ | ✓ | ✓ | ✓ |
| Web App Calls a web API | ✓ | ✓ | ✓ | ✓ |
| | Microsoft Entra ID | External ID | External ID with Custom Domain |
|----------------|--------------------|-------------|--------------------------------|
| Web App Sign-In & Sign-Out | ✓ | ✓ | ✓ |
| Web App Calls a web API | ✓ | ✓ | ✓ |


![Topology](static/topology.png)
Expand Down Expand Up @@ -34,7 +34,6 @@ Write your app like this once, and the same implementation will support 4x2=8 sc
<th>Microsoft Entra ID</th>
<th>Microsoft Entra External ID</th>
<th>Microsoft Entra External ID with Custom Domain</th>
<th>Azure AD B2C</th>
</tr>

<tr>
Expand All @@ -54,12 +53,6 @@ Follow only the page 1 of this [Tutorial: Prepare your customer tenant ...](http

Coming soon.

</td>
<td>

Following only the step 1 and 2 (including 2.1 and 2.2) of this
[Configure authentication in a sample Python web app by using Azure AD B2C](https://learn.microsoft.com/azure/active-directory-b2c/configure-authentication-sample-python-web-app?tabs=linux)

</td>
</tr>

Expand All @@ -82,17 +75,11 @@ as `.env` and then modify `.env` with your app's settings.
Copy this [External ID with Custom Domain template](.env.sample.external-id-custom-domain)
as `.env` and then modify `.env` with your app's settings.

</td>
<td>

Copy this [Azure AD B2C template](.env.sample.b2c)
as `.env` and then modify `.env` with your app's settings.

</td>
</tr>

<tr>
<td colspan=4>
<td colspan=3>

Do not reverse the order of the configuration steps above.
If you put your app credentials into the template and then copy it into `.env`,
Expand All @@ -103,7 +90,7 @@ you risk accidentally committing your templates with credentials into Version Co

<tr>
<th>Web App Sign In & Sign Out</th>
<td colspan=4>
<td colspan=3>

With the basic configuration above,
you can now browse to the index page of this sample to try the sign-in/sign-out experience.
Expand All @@ -113,7 +100,7 @@ you can now browse to the index page of this sample to try the sign-in/sign-out

<tr>
<th>Web App Calls a web API</th>
<td colspan=4>
<td colspan=3>

Add the web API's *endpoint* into your `.env` file.
Also add the *scopes* it needs, separated by space.
Expand All @@ -137,7 +124,7 @@ Deploy to
[Azure App Service](https://azure.microsoft.com/en-us/products/app-service)

</th>
<td colspan=4>
<td colspan=3>

* 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),
but replace its sample app (which does not do user sign-in) with this web app.
Expand Down Expand Up @@ -174,3 +161,6 @@ For more information, see the
or contact [[email protected]](mailto:[email protected])
with any additional questions or comments.

## Appendix: Archived Azure AD B2C scenario

Azure AD B2C support has been removed from the active Django sample and is no longer maintained. The last version remains available for reference in the [`django-web-app`](https://github.com/bgavrilMS/ms-identity-docs-code-python/tree/archive/azure-ad-b2c/django-web-app) directory on the `archive/azure-ad-b2c` branch. The Microsoft Entra External ID scenarios documented above remain supported.
4 changes: 0 additions & 4 deletions django-web-app/mysite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
redirect_uri=os.getenv('REDIRECT_URI'),
authority=os.getenv('AUTHORITY'),
oidc_authority=os.getenv('OIDC_AUTHORITY'),
b2c_tenant_name=os.getenv('B2C_TENANT_NAME'),
b2c_signup_signin_user_flow=os.getenv('SIGNUPSIGNIN_USER_FLOW'),
b2c_edit_profile_user_flow=os.getenv('EDITPROFILE_USER_FLOW'),
b2c_reset_password_user_flow=os.getenv('RESETPASSWORD_USER_FLOW'),
)

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand Down
2 changes: 0 additions & 2 deletions django-web-app/mysite/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
def index(request, *, context):
return render(request, 'index.html', dict(
user=context['user'],
edit_profile_url=settings.AUTH.get_edit_profile_url(),
api_endpoint=os.getenv("ENDPOINT"),
title=f"Microsoft Entra ID Django Web App Sample v{__version__}",
))
Expand All @@ -29,4 +28,3 @@ def call_api(request, *, context):
"title": "Result of API call",
"content": json.dumps(api_result, indent=4),
})

5 changes: 0 additions & 5 deletions django-web-app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ <h2>Welcome {{ user.name }}!</h2>
<li><a href='/call_api'>Call an API</a></li>
{% endif %}

{% if edit_profile_url %}
<li><a href='{{ edit_profile_url }}'>Edit Profile</a></li>
{% endif %}

<li><a href="{% url 'identity.logout' %}">Logout</a></li>
</ul>
</body>
</html>

31 changes: 0 additions & 31 deletions flask-web-app/.env.sample.b2c

This file was deleted.

35 changes: 13 additions & 22 deletions flask-web-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ urlFragment: ms-identity-python-webapp
# Integrating Microsoft Entra ID with a Python web application written in Flask

This is a multi-purpose [Flask](https://flask.palletsprojects.com/en/3.0.x/) web app sample.
Write your app like this once, and the same implementation will support 4x2=8 scenarios.
The same implementation supports Microsoft Entra ID, External ID, and External ID with a custom domain.

| | Microsoft Entra ID | External ID | External ID with Custom Domain | Azure Active Directory B2C |
|----------------|--------------------|-------------|--------------------------------|--------------|
| Web App Sign-In & Sign-Out | ✓ | ✓ | ✓ | ✓ |
| Web App Calls a web API | ✓ | ✓ | ✓ | ✓ |
| | Microsoft Entra ID | External ID | External ID with Custom Domain |
|----------------|--------------------|-------------|--------------------------------|
| Web App Sign-In & Sign-Out | ✓ | ✓ | ✓ |
| Web App Calls a web API | ✓ | ✓ | ✓ |

![Topology](https://raw.githubusercontent.com/Azure-Samples/ms-identity-python-webapp-django/main/static/topology.png)

Expand All @@ -41,7 +41,6 @@ Write your app like this once, and the same implementation will support 4x2=8 sc
<th>Microsoft Entra ID</th>
<th>Microsoft Entra External ID</th>
<th>Microsoft Entra External ID with Custom Domain</th>
<th>Azure Active Directory B2C</th>
</tr>

<tr>
Expand All @@ -61,12 +60,6 @@ Follow only the page 1 of this [Tutorial: Prepare your customer tenant ...](http

Coming soon.

</td>
<td>

Following only the step 1 and 2 (including 2.1 and 2.2) of this
[Configure authentication in a sample Python web app by using Azure Active Directory B2C](https://learn.microsoft.com/azure/active-directory-b2c/configure-authentication-sample-python-web-app?tabs=linux)

</td>
</tr>

Expand All @@ -89,17 +82,11 @@ as `.env` and then modify `.env` with your app's settings.
Copy this [External ID with Custom Domain template](.env.sample.external-id-custom-domain)
as `.env` and then modify `.env` with your app's settings.

</td>
<td>

Copy this [Azure Active Directory B2C template](.env.sample.b2c)
as `.env` and then modify `.env` with your app's settings.

</td>
</tr>

<tr>
<td colspan=4>
<td colspan=3>

Do not reverse the order of the configuration steps above.
If you put your app credentials into the template and then copy it into `.env`,
Expand All @@ -110,7 +97,7 @@ you risk accidentally committing your templates with credentials into Version Co

<tr>
<th>Web App Sign In & Sign Out</th>
<td colspan=4>
<td colspan=3>

With the basic configuration above,
you can now browse to the index page of this sample to try the sign-in/sign-out experience.
Expand All @@ -120,7 +107,7 @@ you can now browse to the index page of this sample to try the sign-in/sign-out

<tr>
<th>Web App Calls a web API</th>
<td colspan=4>
<td colspan=3>

Add the web API's *endpoint* into your `.env` file.
Also add the *scopes* it needs, separated by space.
Expand All @@ -144,7 +131,7 @@ Deploy to
[Azure App Service](https://azure.microsoft.com/en-us/products/app-service)

</th>
<td colspan=4>
<td colspan=3>

* 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),
but replace its sample app (which does not do user sign-in) with this web app.
Expand Down Expand Up @@ -178,3 +165,7 @@ If you find a bug in the sample, please raise the issue on [GitHub Issues](../..
If you'd like to contribute to this sample, see [CONTRIBUTING.MD](/CONTRIBUTING.md).

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information, see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

## Appendix: Archived Azure AD B2C scenario

Azure AD B2C support has been removed from the active Flask sample and is no longer maintained. The last version remains available for reference in the [`flask-web-app`](https://github.com/bgavrilMS/ms-identity-docs-code-python/tree/archive/azure-ad-b2c/flask-web-app) directory on the `archive/azure-ad-b2c` branch. The Microsoft Entra External ID scenarios documented above remain supported.
6 changes: 0 additions & 6 deletions flask-web-app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
client_credential=os.getenv("CLIENT_SECRET"),
redirect_uri=os.getenv("REDIRECT_URI"),
oidc_authority=os.getenv("OIDC_AUTHORITY"),
b2c_tenant_name=os.getenv('B2C_TENANT_NAME'),
b2c_signup_signin_user_flow=os.getenv('SIGNUPSIGNIN_USER_FLOW'),
b2c_edit_profile_user_flow=os.getenv('EDITPROFILE_USER_FLOW'),
b2c_reset_password_user_flow=os.getenv('RESETPASSWORD_USER_FLOW'),
)

@app.route("/")
Expand All @@ -27,7 +23,6 @@ def index(*, context):
return render_template(
'index.html',
user=context['user'],
edit_profile_url=auth.get_edit_profile_url(),
api_endpoint=os.getenv("ENDPOINT"),
title=f"Flask Web App Sample v{__version__}",
)
Expand All @@ -41,4 +36,3 @@ def call_downstream_api(*, context):
timeout=30,
).json() if context.get('access_token') else "Did you forget to set the SCOPE environment variable?"
return render_template('display.html', title="API Response", result=api_result)

4 changes: 0 additions & 4 deletions flask-web-app/templates/auth_error.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
<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>
Expand Down
5 changes: 0 additions & 5 deletions flask-web-app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ <h2>Welcome {{ user.get("name") }}!</h2>
<li><a href='/call_api'>Call an API</a></li>
{% endif %}

{% if edit_profile_url %}
<li><a href='{{edit_profile_url}}'>Edit Profile</a></li>
{% endif %}

<li><a href="{{ url_for('identity.logout') }}">Logout</a></li>
</ul>

<hr>
<footer style="text-align: right">{{ title }}</footer>
</body>
</html>

5 changes: 0 additions & 5 deletions flask-web-app/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ <h1>Microsoft Identity Python Web App</h1>
<ul><li><a href='{{ auth_uri }}'>Sign In</a></li></ul>
{% endif %}

{% if config.get("B2C_RESET_PASSWORD_AUTHORITY") %}
<a href='{{Auth(session={}, authority=config["B2C_RESET_PASSWORD_AUTHORITY"], client_id=config["CLIENT_ID"]).log_in(redirect_uri=url_for("auth_response", _external=True))["auth_uri"]}}'>Reset Password</a>
{% endif %}

<hr>
<footer style="text-align: right">Microsoft identity platform Web App Sample {{ version }}</footer>
</body>
</html>