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.
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.
6
6
@@ -56,15 +56,15 @@ If you're interested in developing your own authentication module, or are curiou
56
56
57
57
## Running the samples
58
58
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.
60
60
61
61
After you've completed those steps, follow these steps to run the samples:
62
62
63
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
65
2. Go to this URL in a browser: [http://localhost:5000](http://localhost:5000). You should see a home page like this:
66
66
67
-

67
+

68
68
69
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:
70
70
@@ -90,24 +90,28 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
90
90
## Resources
91
91
92
92
Documentation:
93
+
93
94
*[Microsoft Graph Dev Center](https://developer.microsoft.com/en-us/graph/)
94
95
*[Get started with Microsoft Graph and REST](https://developer.microsoft.com/en-us/graph/docs/concepts/rest)
95
96
*[Get access tokens to call Microsoft Graph](https://developer.microsoft.com/en-us/graph/docs/concepts/auth_overview)
96
97
*[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)
97
98
98
99
Samples:
100
+
99
101
*[Python authentication samples for Microsoft Graph](https://github.com/microsoftgraph/python-sample-auth)
100
102
*[Sending mail via Microsoft Graph from Python](https://github.com/microsoftgraph/python-sample-send-mail)
101
103
*[Working with paginated Microsoft Graph responses in Python](https://github.com/microsoftgraph/python-sample-pagination)
102
104
*[Working with Graph open extensions in Python](https://github.com/microsoftgraph/python-sample-open-extensions)
103
105
*[Python console application for Microsoft Graph](https://github.com/microsoftgraph/python-sample-console-app)
104
106
105
107
Auth libraries:
108
+
106
109
*[Microsoft ADAL for Python](https://github.com/AzureAD/azure-activedirectory-library-for-python)
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:
9
4
10
5
## Prerequisites
11
6
12
-
Before installing the sample:
7
+
Before installing the samples:
13
8
14
9
* 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.
15
10
* 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.
28
19
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```.
29
20
30
21
## Configuration
31
22
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).
33
24
34
25
Follow these steps to register a new application:
35
26
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.
37
28
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.
39
30
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**.
41
35
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.
43
37
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.
45
39
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.
47
45
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 sampleonly require the default **User.Read** permission, which is pre-selected for a new application registration, you won't need to add any additional permissions.
49
47
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.
53
49
54
50
## Working with multiple samples
55
51
56
-
If you're installing multiple Python REST samples, you can re-use the application registration and ```config.py``` file in most cases.
57
-
58
52
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.
59
53
60
54
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