Skip to content
This repository was archived by the owner on Mar 7, 2020. It is now read-only.

Commit 3fe6314

Browse files
author
Doug Mahugh
committed
extract installation.md
1 parent 624feec commit 3fe6314

File tree

2 files changed

+70
-53
lines changed

2 files changed

+70
-53
lines changed

README.md

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This repo includes examples of four different approaches you can use to authenti
88

99
* [Sample architecture](#sample-architecture)
1010
* [Python auth options](#python-auth-options)
11-
* [Using the samples](#using-the-samples)
11+
* [Running the samples](#running-the-samples)
1212
* [Contributing](#contributing)
1313
* [Resources](#resources)
1414

@@ -54,26 +54,25 @@ If you're using [Requests](http://docs.python-requests.org/en/master/), the most
5454

5555
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.
5656

57-
## Using the samples
57+
## Running the samples
5858

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.
6060

61-
### Prerequisites
61+
After you've completed those steps, follow these steps to run the samples:
6262

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```.
6464

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:
6766

68-
### Installation
67+
![home page](static/images/homepage.png)
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:
6970

70-
Follow these steps to install the samples:
71+
![sample output](static/images/graphcall.png)
7172

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
7574

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.
7776

7877
| Sample | Auth Library | Dependencies |
7978
| ------ | ------------ | ------------ |
@@ -82,46 +81,6 @@ Following the above steps will install all the dependencies for all four options
8281
| [sample_requests.py](https://github.com/microsoftgraph/python-sample-auth/blob/master/sample_requests.py) | [Requests-OAuthlib](https://github.com/requests/requests-oauthlib) | <ul><li>requests</li><li>requests-oauthlib</li><li>bottle</li></ul> |
8382
| [sample_graphrest.py](https://github.com/microsoftgraph/python-sample-auth/blob/master/sample_graphrest.py) | [graphrest module](https://github.com/microsoftgraph/python-sample-auth/blob/master/graphrest.py) | <ul><li>requests</li><li>bottle</li></ul> |
8483

85-
### Configuration
86-
87-
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-
![home page](static/images/homepage.png)
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-
![sample output](static/images/graphcall.png)
124-
12584
## Contributing
12685

12786
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 &mdash; please log an [issue](https://github.com/microsoftgraph/python-sample-auth/issues) and let us know!

installation.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Installing the Python REST samples
2+
3+
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).
14+
15+
## Installation
16+
17+
Follow these steps to install the samples:
18+
19+
1. Clone the repo, using one of these commands:
20+
21+
```git clone https://github.com/microsoftgraph/python-sample-auth.git```
22+
23+
```git clone https://github.com/microsoftgraph/python-sample-pagination.git```
24+
25+
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

Comments
 (0)