You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 7, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+12-53Lines changed: 12 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ This repo includes examples of four different approaches you can use to authenti
8
8
9
9
*[Sample architecture](#sample-architecture)
10
10
*[Python auth options](#python-auth-options)
11
-
*[Using the samples](#using-the-samples)
11
+
*[Running the samples](#running-the-samples)
12
12
*[Contributing](#contributing)
13
13
*[Resources](#resources)
14
14
@@ -54,26 +54,25 @@ If you're using [Requests](http://docs.python-requests.org/en/master/), the most
54
54
55
55
If you're interested in developing your own authentication module, or are curious about the details of implementing OAuth 2.0 authentication for a web application, the [sample_graphrest.py](https://github.com/microsoftgraph/python-sample-auth/blob/master/sample_graphrest.py) sample provides an example of authenticating with [graphrest](https://github.com/microsoftgraph/python-sample-auth/blob/master/graphrest.py), a custom auth library written in Python. Note that this sample uses the [Bottle](https://bottlepy.org/docs/dev/) web framework, although it is relatively easy to port it to Flask or any other web framework that supports redirects and provides access to request query parameters.
56
56
57
-
## Using the samples
57
+
## Running the samples
58
58
59
-
The following instructions take you through the steps required to install, configure, and run the samples.
59
+
To install and configure the samples in this repo, see the instructions in [Installing the Python REST samples](blob/master/installation.md). These samples only require **User.Read** permission, which is the default, so you don't need to specify additional permissions while registering the application.
60
60
61
-
### Prerequisites
61
+
After you've completed those steps, follow these steps to run the samples:
62
62
63
-
Before installing the sample:
63
+
1. To start a sample, run the command ```python <progname>``` in the root folder of the cloned repo. For example, to run the ADAL sample, use this command: ```python sample_adal.py```.
64
64
65
-
* Install Python from [https://www.python.org/](https://www.python.org/). We've tested the code with Python 3.6.2, but any Python 3.x version should work fine. If your code base is running under Python 2.7, you may find it helpful to use the [3to2](https://pypi.python.org/pypi/3to2) tools to port the code to Python 2.7.
66
-
* To register your application for access to Microsoft Graph, you'll need either a [Microsoft account](https://www.outlook.com) or an [Office 365 for business account](https://msdn.microsoft.com/en-us/office/office365/howto/setup-development-environment#bk_Office365Account). If you don't have one of these, you can create a Microsoft account for free at [outlook.com](https://www.outlook.com).
65
+
2. Go to this URL in a browser: [http://localhost:5000](http://localhost:5000). You should see a home page like this:
67
66
68
-
### Installation
67
+

68
+
69
+
3. Choose **Connect**, and then select your Microsoft account or Office 365 account and follow the instructions to log on. The first time you log on to the app under a particular identity, you will be prompted to consent to the permissions that the app is requesting. Choose **Accept**, which gives the application permission to read your profile information. You'll then see the following screen, which shows that the app has successfully authenticated and is able to read your profile information from Microsoft Graph:
69
70
70
-
Follow these steps to install the samples:
71
+

71
72
72
-
1. Clone this repo: ```git clone https://github.com/microsoftgraph/python-sample-auth.git```.
73
-
2. Create and activate a virtual environment (optional). If you're new to Python virtual environments, [Miniconda](https://conda.io/miniconda.html) is a great place to start.
74
-
3. In the root folder of your cloned repo, install the dependencies for the sample as listed in [requirements.txt](https://github.com/microsoftgraph/python-sample-auth/blob/master/requirements.txt) with this command: ```pip install -r requirements.txt```.
73
+
### Python package dependencies
75
74
76
-
Following the above steps will install all the dependencies for all four options. If you only plan to use one of the options, the following table lists the Python package dependencies for each sample.
75
+
The requirements.txt file for this repo includes all of the packages for all of the auth samples. If you only plan to use one of the samples, you may prefer to only install the packages required for that sample. The following table lists the Python package dependencies for each sample.
77
76
78
77
| Sample | Auth Library | Dependencies |
79
78
| ------ | ------------ | ------------ |
@@ -82,46 +81,6 @@ Following the above steps will install all the dependencies for all four options
To configure the samples, you'll need to register a new application in the Microsoft [Application Registration Portal](https://apps.dev.microsoft.com/). You only need to do this once, and then any Microsoft identity can be used to run any of the samples.
88
-
89
-
Follow these steps to register a new application:
90
-
91
-
1. Sign in to the [Application Registration Portal](https://apps.dev.microsoft.com/) using either your personal or work or school account.
92
-
93
-
2. Under **My applications**, choose **Add an app**. If you're using an Office 365 account and see two categories listed (Converged or Azure AD only), choose **Add an app** for the Converged applications section.
94
-
95
-
3. Enter an application name, and choose **Create**. (Do *not* choose **Guided Setup**.)
96
-
97
-
4. Next you'll see the registration page for your app. Copy and save the **Application Id** field.You will need it later to complete the configuration process.
98
-
99
-
5. Under **Application Secrets**, choose **Generate New Password**. A new password will be displayed in the **New password generated** dialog. Copy this password. You will need it later to complete the configuration process.
100
-
101
-
6. Under **Platforms**, choose **Add platform** > **Web**.
102
-
103
-
7. Enter `http://localhost:5000/login/authorized` as the Redirect URL, and then choose **Save**.
104
-
105
-
As the final step in configuring the sample, modify the [config.py](https://github.com/microsoftgraph/python-sample-auth/blob/master/config.py) file in the root folder of your cloned repo, and follow the instructions to enter your Client ID and Client Secret (which are referred to as Application Id and Password in the app registration portal). Then save the change, and you're ready to run the samples.
106
-
107
-
### Running the samples
108
-
109
-
To run one of the samples, run the command ```python <progname>``` in the root folder of the cloned repo. For example, to run the ADAL sample, use this command: ```python sample_adal.py```.
110
-
111
-
Then go to this URL in a browser: [http://localhost:5000](http://localhost:5000)
112
-
113
-
You should see a home page like this:
114
-
115
-

116
-
117
-
Choose **Connect**, and then select your Microsoft account or Office 365 account and follow the instructions to log on.
118
-
119
-
The first time you log on to the app under a particular identity, you will be prompted to consent to the permissions that the app is requesting. Choose **Accept**, which gives the application permission to read your profile information.
120
-
121
-
You'll then see the following screen, which shows that the app has successfully read your profile information from Microsoft Graph:
122
-
123
-

124
-
125
84
## Contributing
126
85
127
86
These samples are open source, released under the [MIT License](https://github.com/microsoftgraph/python-sample-auth/blob/master/LICENSE). Issues (including feature requests and/or questions about this sample) and [pull requests](https://github.com/microsoftgraph/python-sample-auth/pulls) are welcome. If there's another Python sample you'd like to see for Microsoft Graph, we're interested in that feedback as well — please log an [issue](https://github.com/microsoftgraph/python-sample-auth/issues) and let us know!
This page covers how to install Python REST samples for Microsoft Graph. These instructions apply to the samples in these repos:
4
+
5
+
*[Python authentication samples for Microsoft Graph](https://github.com/microsoftgraph/python-sample-auth)
6
+
*[Working with paginated Microsoft Graph responses in Python](https://github.com/microsoftgraph/python-sample-pagination)
7
+
8
+
## Prerequisites
9
+
10
+
Before installing the sample:
11
+
12
+
* Install Python from [https://www.python.org/](https://www.python.org/). We've tested the code with Python 3.6, but any Python 3.x version should work. If your code base is running under Python 2.7, you may find it helpful to use the [3to2](https://pypi.python.org/pypi/3to2) tools to port the code to Python 2.7.
13
+
* To register your application for access to Microsoft Graph, you'll need either a [Microsoft account](https://www.outlook.com) or an [Office 365 for business account](https://msdn.microsoft.com/en-us/office/office365/howto/setup-development-environment#bk_Office365Account). If you don't have one of these, you can create a Microsoft account for free at [outlook.com](https://www.outlook.com).
2. Create and activate a virtual environment (optional). If you're new to Python virtual environments, [Miniconda](https://conda.io/miniconda.html) is a great place to start.
26
+
3. In the root folder of your cloned repo, install the dependencies for the sample as listed in the ```requirements.txt``` file with this command: ```pip install -r requirements.txt```.
27
+
28
+
## Configuration
29
+
30
+
To configure the samples, you'll need to register a new application in the Microsoft [Application Registration Portal](https://apps.dev.microsoft.com/).
31
+
32
+
Follow these steps to register a new application:
33
+
34
+
1. Sign in to the [Application Registration Portal](https://apps.dev.microsoft.com/) using either your personal or work or school account.
35
+
36
+
2. Under **My applications**, choose **Add an app**. If you're using an Office 365 account and see two categories listed (Converged or Azure AD only), choose **Add an app** for the Converged applications section.
37
+
38
+
3. Enter an application name, and choose **Create**. (Do *not* choose **Guided Setup**.)
39
+
40
+
4. Next you'll see the registration page for your app. Copy and save the **Application Id** field.You will need it later to complete the configuration process.
41
+
42
+
5. Under **Application Secrets**, choose **Generate New Password**. A new password will be displayed in the **New password generated** dialog. Copy this password. You will need it later to complete the configuration process.
43
+
44
+
6. Under **Platforms**, choose **Add platform** > **Web**.
45
+
46
+
7. Under **Delegated Permissions**, add the permissions/scopes required for the sample, as covered in the sample's README. For example, the [send mail](https://github.com/microsoftgraph/python-sample-send-mail) sample requires **Mail.Read** permission. Some samples (such as the [auth samples](https://github.com/microsoftgraph/python-sample-auth)) only require the default **User.Read** permission, which is pre-selected for a new application registration, so for those you won't need to add any permissions.
47
+
48
+
8. Enter `http://localhost:5000/login/authorized` as the Redirect URL, and then choose **Save**.
49
+
50
+
As the final step in configuring the sample, modify the ```config.py``` file in the root folder of your cloned repo, and follow the instructions to enter your Client ID and Client Secret (which are referred to as Application Id and Password in the app registration portal). Then save the change, and you're ready to run the samples as covered in each sample's README.
51
+
52
+
## Working with multiple samples
53
+
54
+
If you're installing multiple Python REST samples, you can re-use the application registration and ```config.py``` file in most cases.
55
+
56
+
Samples that use Microsoft ADAL for authentication require that all required permissions/scopes are added to the application in the Application Registration Portal. So if you're using ADAL for multiple samples, you can either register a separate app for each sample, or add all required permissions to a single registered application.
57
+
58
+
Samples using the other auth options can take advantage of _incremental consent_, which means you don't need to add permissions to the application registration. You can edit the ```SCOPES``` setting in the ```config.py``` file to add any permissions required for each sample, and the user will be prompted to consent to these permissions with they log in to the sample app.
0 commit comments