Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/ask-a-question.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ assignees: ''
Thank you for taking an interest in Microsoft Graph development! Please feel free to ask a question here, but keep in mind the following:

- This is not an official Microsoft support channel, and our ability to respond to questions here is limited. Questions about Graph, or questions about adding a new feature to the sample, will be answered on a best-effort basis.
- Questions should be asked on [Microsoft Q&A](https://docs.microsoft.com/answers/products/graph).
- Questions should be asked on [Microsoft Q&A](https://learn.microsoft.com/answers/products/graph).
- Issues with Microsoft Graph itself should be handled through [support](https://developer.microsoft.com/graph/support).
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ assignees: ''
**Where did you get the code?**
- [ ] Downloaded from GitHub
- [ ] Downloaded from the [Microsoft Graph quick start tool](https://developer.microsoft.com/graph/quick-start)
- [ ] Followed the tutorial from [Microsoft Graph tutorials](https://docs.microsoft.com/graph/tutorials)
- [ ] Followed the tutorial from [Microsoft Graph tutorials](https://learn.microsoft.com/graph/tutorials)

**Describe the bug**
A clear and concise description of what the bug is.
Expand All @@ -35,7 +35,7 @@ If applicable, add screenshots to help explain your problem.

**Dependency versions**
- Authentication library (MSAL, etc.) version:
- Graph library (Graph SDK, REST library, etc.) version:
- Graph library (Graph SDK, REST library, etc.) version:

**Additional context**
Add any other context about the problem here.
6 changes: 5 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/demo/graphtutorial" # Location of package manifests
directory: "/user-auth/graphtutorial" # Location of package manifests
schedule:
interval: "weekly"
- package-ecosystem: "pip" # See documentation for possible values
directory: "/app-auth/graphapponlytutorial" # Location of package manifests
schedule:
interval: "weekly"
26 changes: 20 additions & 6 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
name: Pylint

on: [push]
on:
push:
branches: [ main, live ]
pull_request:
branches: [ main, live ]

jobs:
build:
defaults:
run:
working-directory: demo/graphtutorial

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install dependencies (user auth)
working-directory: user-auth/graphtutorial
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint
- name: Analyzing the code with pylint (user auth)
working-directory: user-auth/graphtutorial
run: |
pylint $(git ls-files '*.py')
- name: Install dependencies (app auth)
working-directory: app-auth/graphapponlytutorial
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint
- name: Analysing the code with pylint
- name: Analyzing the code with pylint (app auth)
working-directory: app-auth/graphapponlytutorial
run: |
pylint $(git ls-files '*.py')
13 changes: 11 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@
"name": "Python: main",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/demo/graphtutorial/main.py",
"cwd": "${workspaceFolder}/demo/graphtutorial",
"program": "${workspaceFolder}/user-auth/graphtutorial/main.py",
"cwd": "${workspaceFolder}/user-auth/graphtutorial",
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "Python: main (app-only)",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/app-auth/graphapponlytutorial/main.py",
"cwd": "${workspaceFolder}/app-auth/graphapponlytutorial",
"console": "integratedTerminal",
"justMyCode": true
}
Expand Down
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"cSpell.words": [
"graphapponlytutorial",
"graphtutorial",
"Pylint"
]
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

[![Pylint](https://github.com/microsoftgraph/msgraph-training-python/actions/workflows/pylint.yml/badge.svg)](https://github.com/microsoftgraph/msgraph-training-python/actions/workflows/pylint.yml)

This sample will introduce you to working with the Microsoft Graph SDK to access data in Microsoft 365 from Python applications. This code is the result of completing the [Python Microsoft Graph tutorial](https://docs.microsoft.com/graph/tutorials/python).
This sample will introduce you to working with the Microsoft Graph SDK to access data in Microsoft 365 from Python applications. This code is the result of completing the [Python Microsoft Graph tutorial](https://learn.microsoft.com/graph/tutorials/python) and the [Python Microsoft Graph app-only tutorial](https://learn.microsoft.com/graph/tutorials/python-app-only).

## Running the sample

The code for this sample is in the [demo](demo) folder. Instructions to configure and run the sample can be found in the [README](demo/README.md) in that folder.
The code for the delegated user authentication sample is in the [user-auth](user-auth) folder. Instructions to configure and run the sample can be found in the [README](user-auth/README.md) in that folder.

The code for the app-only authentication sample is in the [app-auth](app-auth) folder. Instructions to configure and run the sample can be found in the [README](app-auth/README.md) in that folder.

## Code of conduct

Expand All @@ -15,4 +17,3 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
## Disclaimer

**THIS CODE IS PROVIDED _AS IS_ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**

85 changes: 85 additions & 0 deletions app-auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# How to run the completed project

## Prerequisites

To run the completed project in this folder, you need the following:

- [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.)
- A Microsoft work or school account with the **Global administrator** role.

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.

## Register an application

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

### Azure Active Directory admin center

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

1. Select **Azure Active Directory** in the left-hand navigation, then select **App registrations** under **Manage**.

1. Select **New registration**. Enter a name for your application, for example, `Python Graph Tutorial`.

1. Set **Supported account types** to **Accounts in this organizational directory only**.

1. Leave **Redirect URI** empty.

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.

1. Select **API permissions** under **Manage**.

1. Remove the default **User.Read** permission under **Configured permissions** by selecting the ellipses (**...**) in its row and selecting **Remove permission**.

1. Select **Add a permission**, then **Microsoft Graph**.

1. Select **Application permissions**.

1. Select **User.Read.All**, then select **Add permissions**.

1. Select **Grant admin consent for...**, then select **Yes** to provide admin consent for the selected permission.

1. Select **Certificates and secrets** under **Manage**, then select **New client secret**.

1. Enter a description, choose a duration, and select **Add**.

1. Copy the secret from the **Value** column, you will need it in the next steps.

### PowerShell

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.

1. Open PowerShell and run the [RegisterAppForAppOnlyAuth.ps1](RegisterAppForAppOnlyAuth.ps1) file with the following command.

```powershell
.\RegisterAppForAppOnlyAuth.ps1 -AppName "Python App-Only Graph Tutorial" -GraphScopes "User.Read.All"
```

1. Copy the **Client ID**, **Tenant ID**, and **Client secret** values from the script output. You will need these values in the next step.

```powershell
SUCCESS
Client ID: ae2386e6-799e-4f75-b191-855d7e691c75
Tenant ID: 5927c10a-91bd-4408-9c70-c50bce922b71
Client secret: ...
Secret expires: 10/28/2024 5:01:45 PM
```

## Configure the sample

1. Update the values in [config.cfg](./graphtutorial/config.cfg) according to the following table.

| Setting | Value |
|---------|-------|
| `clientId` | The client ID of your app registration |
| `clientSecret` | The client secret of your app registration |
| `tenantId` | The tenant ID of your organization |

## Build and run the sample

In your command-line interface (CLI), navigate to the project directory and run the following command.

```Shell
python3 -m pip install -r requirements.txt
python3 main.py
```
Loading