|
| 1 | +# How to run the completed project |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +To run the completed project in this folder, you need the following: |
| 6 | + |
| 7 | +- [Python](https://www.python.org/) and [pip](https://pip.pypa.io/en/stable/) installed on your development machine. (**Note:** This tutorial was written with Python version 3.10.4 and pip version 20.0.2. The steps in this guide may work with other versions, but that has not been tested.) |
| 8 | +- A Microsoft work or school account with the **Global administrator** role. |
| 9 | + |
| 10 | +If you don't have a Microsoft account, you can [sign up for the Microsoft 365 Developer Program](https://developer.microsoft.com/microsoft-365/dev-program) to get a free Microsoft 365 subscription. |
| 11 | + |
| 12 | +## Register an application |
| 13 | + |
| 14 | +You can register an application using the Azure Active Directory admin center, or by using the [Microsoft Graph PowerShell SDK](https://learn.microsoft.com/graph/powershell/get-started). |
| 15 | + |
| 16 | +### Azure Active Directory admin center |
| 17 | + |
| 18 | +1. Open a browser and navigate to the [Azure Active Directory admin center](https://aad.portal.azure.com) and login using a **personal account** (aka: Microsoft Account) or **Work or School Account**. |
| 19 | + |
| 20 | +1. Select **Azure Active Directory** in the left-hand navigation, then select **App registrations** under **Manage**. |
| 21 | + |
| 22 | +1. Select **New registration**. Enter a name for your application, for example, `Python Graph Tutorial`. |
| 23 | + |
| 24 | +1. Set **Supported account types** to **Accounts in this organizational directory only**. |
| 25 | + |
| 26 | +1. Leave **Redirect URI** empty. |
| 27 | + |
| 28 | +1. Select **Register**. On the application's **Overview** page, copy the value of the **Application (client) ID** and **Directory (tenant) ID** and save them, you will need these values in the next step. |
| 29 | + |
| 30 | +1. Select **API permissions** under **Manage**. |
| 31 | + |
| 32 | +1. Remove the default **User.Read** permission under **Configured permissions** by selecting the ellipses (**...**) in its row and selecting **Remove permission**. |
| 33 | + |
| 34 | +1. Select **Add a permission**, then **Microsoft Graph**. |
| 35 | + |
| 36 | +1. Select **Application permissions**. |
| 37 | + |
| 38 | +1. Select **User.Read.All**, then select **Add permissions**. |
| 39 | + |
| 40 | +1. Select **Grant admin consent for...**, then select **Yes** to provide admin consent for the selected permission. |
| 41 | + |
| 42 | +1. Select **Certificates and secrets** under **Manage**, then select **New client secret**. |
| 43 | + |
| 44 | +1. Enter a description, choose a duration, and select **Add**. |
| 45 | + |
| 46 | +1. Copy the secret from the **Value** column, you will need it in the next steps. |
| 47 | + |
| 48 | +### PowerShell |
| 49 | + |
| 50 | +To use PowerShell, you'll need the Microsoft Graph PowerShell SDK. If you do not have it, see [Install the Microsoft Graph PowerShell SDK](https://learn.microsoft.com/graph/powershell/installation) for installation instructions. |
| 51 | + |
| 52 | +1. Open PowerShell and run the [RegisterAppForAppOnlyAuth.ps1](RegisterAppForAppOnlyAuth.ps1) file with the following command. |
| 53 | + |
| 54 | + ```powershell |
| 55 | + .\RegisterAppForAppOnlyAuth.ps1 -AppName "Python App-Only Graph Tutorial" -GraphScopes "User.Read.All" |
| 56 | + ``` |
| 57 | +
|
| 58 | +1. Copy the **Client ID**, **Tenant ID**, and **Client secret** values from the script output. You will need these values in the next step. |
| 59 | +
|
| 60 | + ```powershell |
| 61 | + SUCCESS |
| 62 | + Client ID: ae2386e6-799e-4f75-b191-855d7e691c75 |
| 63 | + Tenant ID: 5927c10a-91bd-4408-9c70-c50bce922b71 |
| 64 | + Client secret: ... |
| 65 | + Secret expires: 10/28/2024 5:01:45 PM |
| 66 | + ``` |
| 67 | +
|
| 68 | +## Configure the sample |
| 69 | +
|
| 70 | +1. Update the values in [config.cfg](./graphtutorial/config.cfg) according to the following table. |
| 71 | +
|
| 72 | + | Setting | Value | |
| 73 | + |---------|-------| |
| 74 | + | `clientId` | The client ID of your app registration | |
| 75 | + | `clientSecret` | The client secret of your app registration | |
| 76 | + | `tenantId` | The tenant ID of your organization | |
| 77 | +
|
| 78 | +## Build and run the sample |
| 79 | +
|
| 80 | +In your command-line interface (CLI), navigate to the project directory and run the following command. |
| 81 | +
|
| 82 | +```Shell |
| 83 | +python3 -m pip install -r requirements.txt |
| 84 | +python3 main.py |
| 85 | +``` |
0 commit comments