|
1 |
| ---- |
2 |
| -services: active-directory-b2c |
3 |
| -platforms: python |
4 |
| -author: navyasric |
5 |
| ---- |
| 1 | +# This sample has been archived |
6 | 2 |
|
7 |
| -# Sign in Azure AD B2C Users using Python-Flask Open Source Libraries |
8 |
| - |
9 |
| -> [!NOTE] |
10 |
| -> This sample is using a 3rd party library that has been tested for compatibility in basic scenarios with the Azure AD B2C. Microsoft does not provide fixes for these libraries and has not done a review of these libraries. Issues and feature requests should be directed to the library's open-source project. Please see this [document](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-libraries) for more information. |
11 |
| -> |
12 |
| -> |
13 |
| -
|
14 |
| -This sample demonstrates how to use a 3rd party Python-Flask library ([flask-oauthlib](https://github.com/lepture/flask-oauthlib)) to do oAuth 2.0 against Azure AD B2C. It then validates the access token using another 3rd party library ([python-jose](https://github.com/mpdavis/python-jose)). |
15 |
| - |
16 |
| - |
17 |
| -## How To Run This Sample |
18 |
| - |
19 |
| -Getting started is simple! To run this sample you will need to install Flask, flask-oauthlib and python-jose using pip if you don't already have it. If you do, make sure to update Flask. |
20 |
| - |
21 |
| -``` |
22 |
| -sudo pip install Flask |
23 |
| -sudo pip install oauthlib |
24 |
| -sudo pip install python-jose |
25 |
| -``` |
26 |
| - |
27 |
| -### Step 1: Clone or download this repository |
28 |
| - |
29 |
| -From your shell or command line: |
30 |
| - |
31 |
| -`git clone https://github.com/Azure-Samples/active-directory-python-flask-web-b2c.git` |
32 |
| - |
33 |
| -### Step 2: Run the sample using our sample tenant |
34 |
| - |
35 |
| -If you'd like to see the sample working immediately, you can simply run the app as-is without any code changes. The default configuration for this application performs sign-in & sign-up using our sample B2C tenant, `fabrikamb2c.onmicrosoft.com`. It uses a [policy](https://azure.microsoft.com/documentation/articles/active-directory-b2c-reference-policies) named `b2c_1_susi`. Sign up for the app using any of the available account types, and try signing in again with the same account. |
36 |
| - |
37 |
| -Run this sample with the following by setting your flask environment variable and running the sample in the terminal. |
38 |
| - |
39 |
| -``` |
40 |
| -$ export FLASK_APP=b2cflaskapp.py && flask run |
41 |
| -``` |
42 |
| - |
43 |
| -You can then navigate to `http://localhost:5000`. |
44 |
| - |
45 |
| -### Step 3: Get your own Azure AD B2C tenant |
46 |
| - |
47 |
| -You can also modify the sample to use your own Azure AD B2C tenant. First, you'll need to create an Azure AD B2C tenant by following [these instructions](https://azure.microsoft.com/documentation/articles/active-directory-b2c-get-started). |
48 |
| - |
49 |
| -### Step 4: Create your own policies |
50 |
| - |
51 |
| -This sample uses a sign-up and sign-in policy. Create your own policy by following [the instructions here](https://azure.microsoft.com/documentation/articles/active-directory-b2c-reference-policies). You may choose to include as many or as few identity providers as you wish; our sample policies use Facebook, Google, and email-based local accounts. |
52 |
| - |
53 |
| -If you already have existing policies in your B2C tenant, feel free to re-use those. No need to create new ones just for this sample. |
54 |
| - |
55 |
| -### Step 5: Create your own application |
56 |
| - |
57 |
| -Now you need to create your own appliation in your B2C tenant, so that your app has its own client ID. You can do so following [the generic instructions here](https://azure.microsoft.com/documentation/articles/active-directory-b2c-app-registration). Be sure to include the following information in your app registration: |
58 |
| - |
59 |
| -- Enable the **Web App/Web API** setting for your application. |
60 |
| -- Add a redirect_uri for your app. For this sample, it should be in the form of: `https://yourwebsite/login/authorized`. The OAuth library |
61 |
| -- Copy the client ID generated for your application, so you can use it in the next step. |
62 |
| -- Generate a client secret for your application. |
63 |
| - |
64 |
| -### Step 6: Configure the sample to use your B2C tenant |
65 |
| - |
66 |
| -Now you can replace the app's default configuration with your own. Open the `b2cflaskapp.py` file and replace the following values with the ones you created in the previous steps. |
67 |
| - |
68 |
| -```python |
69 |
| -tenant_id = 'fabrikamb2c.onmicrosoft.com' |
70 |
| -client_id = 'fdb91ff5-5ce6-41f3-bdbd-8267c817015d' |
71 |
| -client_secret = 'YOUR_SECRET' |
72 |
| -policy_name = 'b2c_1_susi' |
73 |
| -``` |
74 |
| -## Questions and Issues |
75 |
| - |
76 |
| -Please file any questions or problems with the sample as a github issue. You can also post on StackOverflow with the tag ```azure-ad-b2c```. For oAuth2.0 library issues, please see note above. |
77 |
| - |
78 |
| -This sample was tested with Python 2.7.10, Flask 0.11.1, Flask-OAuthlib 0.9.3 and python-jose 1.3.2 |
79 |
| - |
80 |
| -## Acknowledgements |
81 |
| - |
82 |
| -The flask & django libraries are built ontop of the core python oauthlib. |
83 |
| - |
84 |
| -[flask-oauthlib](https://github.com/lepture/flask-oauthlib) |
85 |
| - |
86 |
| -[python-jose](https://github.com/mpdavis/python-jose) |
87 |
| - |
88 |
| -[oauthlib](https://github.com/idan/oauthlib) |
89 |
| - |
90 |
| -[django-oauth-toolkit](https://github.com/evonove/django-oauth-toolkit) |
| 3 | +If you really wish to view the archived sample, please switch to the [archive](https://github.com/Azure-Samples/active-directory-b2c-python-flask-webapp/tree/archive) branch. This code is no longer maintained and functionality is not guaranteed. |
0 commit comments