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

Commit 4177d21

Browse files
authored
Merge pull request #16 from Jackson-Woods/auth-and-readme-update
Auth and readme update
2 parents f7903ba + a72ac5e commit 4177d21

File tree

4 files changed

+34
-36
lines changed

4 files changed

+34
-36
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Python authentication samples for Microsoft Graph
22

3-
![language:Python](https://img.shields.io/badge/Language-Python-blue.svg?style=flat-square) ![license:MIT](https://img.shields.io/badge/License-MIT-green.svg?style=flat-square)
3+
![language:Python](https://img.shields.io/badge/Language-Python-blue.svg?style=flat-square) ![license:MIT](https://img.shields.io/badge/License-MIT-green.svg?style=flat-square)
44

55
To make calls to [Microsoft Graph](https://developer.microsoft.com/en-us/graph/), your app must obtain a valid access token from Azure Active Directory (Azure AD), the Microsoft cloud identity service, and the token must be passed in an HTTP header with each call to the Microsoft Graph REST API. You can acquire access tokens via industry-standard [OAuth 2.0](https://tools.ietf.org/html/rfc6749) and [Open ID Connect](http://openid.net/connect/) protocols, and use an [Azure Active Directory v2.0 authentication library](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-libraries) to implement those protocols.
66

@@ -56,15 +56,15 @@ If you're interested in developing your own authentication module, or are curiou
5656

5757
## Running the samples
5858

59-
To install and configure the samples in this repo, see the instructions in [Installing the Python REST samples](https://github.com/microsoftgraph/python-sample-auth/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.
59+
To install and configure the samples in this repo, see the instructions in [Installing the Python authentication samples](https://github.com/microsoftgraph/python-sample-auth/blob/master/installation.md). These samples only require the **User.Read** permission, which is the default, so you don't need to specify additional permissions while registering the application.
6060

6161
After you've completed those steps, follow these steps to run the samples:
6262

6363
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

6565
2. Go to this URL in a browser: [http://localhost:5000](http://localhost:5000). You should see a home page like this:
6666

67-
![home page](static/images/homepage.png)
67+
![home page](static/images/homepage.png)
6868

6969
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:
7070

@@ -90,24 +90,28 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
9090
## Resources
9191

9292
Documentation:
93+
9394
* [Microsoft Graph Dev Center](https://developer.microsoft.com/en-us/graph/)
9495
* [Get started with Microsoft Graph and REST](https://developer.microsoft.com/en-us/graph/docs/concepts/rest)
9596
* [Get access tokens to call Microsoft Graph](https://developer.microsoft.com/en-us/graph/docs/concepts/auth_overview)
9697
* [Authorize access to web applications using OAuth 2.0 and Azure Active Directory](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code)
9798

9899
Samples:
100+
99101
* [Python authentication samples for Microsoft Graph](https://github.com/microsoftgraph/python-sample-auth)
100102
* [Sending mail via Microsoft Graph from Python](https://github.com/microsoftgraph/python-sample-send-mail)
101103
* [Working with paginated Microsoft Graph responses in Python](https://github.com/microsoftgraph/python-sample-pagination)
102104
* [Working with Graph open extensions in Python](https://github.com/microsoftgraph/python-sample-open-extensions)
103105
* [Python console application for Microsoft Graph](https://github.com/microsoftgraph/python-sample-console-app)
104106

105107
Auth libraries:
108+
106109
* [Microsoft ADAL for Python](https://github.com/AzureAD/azure-activedirectory-library-for-python)
107110
* [Flask-Oauthlib](https://flask-oauthlib.readthedocs.io/en/latest/)
108111
* [Requests-Oauthlib](https://media.readthedocs.org/pdf/requests-oauthlib/latest/requests-oauthlib.pdf)
109112
* [Azure Active Directory v2.0 authentication libraries](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-libraries)
110113

111114
Specifications:
115+
112116
* [Oauth 2.0 specification](http://www.rfc-editor.org/rfc/rfc6749.txt)
113117
* [Open ID Connect specifications](http://openid.net/connect/)

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
CLIENT_ID = 'ENTER_YOUR_CLIENT_ID'
8-
CLIENT_SECRET = 'ENTER_YOUR_SECRET'
8+
CLIENT_SECRET = 'ENTER_YOUR_CLIENT_SECRET'
99
REDIRECT_URI = 'http://localhost:5000/login/authorized'
1010

1111
# AUTHORITY_URL ending determines type of account that can be authenticated:

installation.md

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
# Installing the Python REST samples
1+
# Configuring the Python authentication samples
22

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-
* [Sending mail via Microsoft Graph from Python](https://github.com/microsoftgraph/python-sample-send-mail)
7-
* [Working with paginated Microsoft Graph responses in Python](https://github.com/microsoftgraph/python-sample-pagination)
8-
* [Working with Graph open extensions in Python](https://github.com/microsoftgraph/python-sample-open-extensions)
3+
This page covers how to set up Python authentication samples for Microsoft Graph. These instructions apply to the samples in these repos:
94

105
## Prerequisites
116

12-
Before installing the sample:
7+
Before installing the samples:
138

149
* 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.
1510
* 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).
@@ -18,43 +13,42 @@ Before installing the sample:
1813

1914
Follow these steps to install the samples:
2015

21-
1. Clone the repo, using one of these commands:
16+
1. Clone the repo, using this command:
2217
* ```git clone https://github.com/microsoftgraph/python-sample-auth.git```
23-
* ```git clone https://github.com/microsoftgraph/python-sample-pagination.git```
24-
* ```git clone https://github.com/microsoftgraph/python-sample-send-mail.git```
25-
* ```git clone https://github.com/microsoftgraph/python-sample-open-extensions.git```
26-
2718
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.
2819
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```.
2920

3021
## Configuration
3122

32-
To configure the samples, you'll need to register a new application in the Microsoft [Application Registration Portal](https://apps.dev.microsoft.com/).
23+
To configure the samples, you'll need to register a new application in the Azure portal [app registrations page](https://go.microsoft.com/fwlink/?linkid=2083908).
3324

3425
Follow these steps to register a new application:
3526

36-
1. Sign in to the [Application Registration Portal](https://apps.dev.microsoft.com/) using either your personal or work or school account.
27+
1. Sign in to the Azure portal [app registrations page](https://go.microsoft.com/fwlink/?linkid=2083908) using either your personal or work or school account.
3728

38-
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.
29+
2. Choose **New registration** near the top of the page.
3930

40-
3. Enter an application name, and choose **Create**. (Do *not* choose **Guided Setup**.)
31+
3. When the **Register an application** page appears, enter your application's registration information:
32+
* In the **Name** section, enter a meaningful application name that will be displayed to users of the app.
33+
* Change **Supported account types** to **Accounts in any organizational directory and personal Microsoft accounts (e.g. Skype, Xbox, Outlook.com)**.
34+
* Enter `http://localhost:5000/login/authorized` as the **Redirect URI**. The URI type should be **Web**.
4135

42-
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.
36+
4. Select **Register** to create the application.
4337

44-
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.
38+
5. The application's **Overview** page will display. On this page, find the **Application (client) ID** value and record it for later. You'll need it to configure the project.
4539

46-
6. Under **Platforms**, choose **Add platform** > **Web**.
40+
6. Select **Certificates & secrets** under **Manage**.
41+
1. Select the **New client secret** button.
42+
2. Enter a value in **Description**.
43+
3. Select any option for **Expires**.
44+
4. When you click the **Add** button, the key value will be displayed. Copy the key value and save it in a safe location. You'll need it in the next step.
4745

48-
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.
46+
7. This sample only require the default **User.Read** permission, which is pre-selected for a new application registration, you won't need to add any additional permissions.
4947

50-
8. Enter `http://localhost:5000/login/authorized` as the Redirect URL, and then choose **Save**.
51-
52-
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.
48+
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 (Application ID) and Client Secret. Then save the change, and you're ready to run the sample.
5349

5450
## Working with multiple samples
5551

56-
If you're installing multiple Python REST samples, you can re-use the application registration and ```config.py``` file in most cases.
57-
5852
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.
5953

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

requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Flask>=0.12.2
2-
Flask-OAuthlib>=0.9.4
3-
Bottle>=0.12.13
4-
Requests>=2.18.4
5-
requests-oauthlib>=0.8.0
6-
adal>=0.4.7
1+
Flask>=1.0.0
2+
Flask-OAuthlib>=0.9.5
3+
Bottle>=0.12.14
4+
Requests>=2.19.0
5+
requests-oauthlib>=1.0.0
6+
adal>=1.0.0

0 commit comments

Comments
 (0)