Skip to content

Commit 9acfb49

Browse files
authored
Merge pull request #50 from microsoftgraph/app-only-split
App only split
2 parents 71c7938 + 7c085f3 commit 9acfb49

32 files changed

+1568
-519
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.github/ISSUE_TEMPLATE/ask-a-question.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ assignees: ''
1010
Thank you for taking an interest in Microsoft Graph development! Please feel free to ask a question here, but keep in mind the following:
1111

1212
- 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.
13-
- Questions should be asked on [Microsoft Q&A](https://docs.microsoft.com/answers/products/graph).
13+
- Questions should be asked on [Microsoft Q&A](https://learn.microsoft.com/answers/products/graph).
1414
- Issues with Microsoft Graph itself should be handled through [support](https://developer.microsoft.com/graph/support).

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ assignees: ''
1010
**Where did you get the code?**
1111
- [ ] Downloaded from GitHub
1212
- [ ] Downloaded from the [Microsoft Graph quick start tool](https://developer.microsoft.com/graph/quick-start)
13-
- [ ] Followed the tutorial from [Microsoft Graph tutorials](https://docs.microsoft.com/graph/tutorials)
13+
- [ ] Followed the tutorial from [Microsoft Graph tutorials](https://learn.microsoft.com/graph/tutorials)
1414

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

3636
**Dependency versions**
3737
- Authentication library (MSAL, etc.) version:
38-
- Graph library (Graph SDK, REST library, etc.) version:
38+
- Graph library (Graph SDK, REST library, etc.) version:
3939

4040
**Additional context**
4141
Add any other context about the problem here.

.github/dependabot.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
version: 2
77
updates:
88
- package-ecosystem: "pip" # See documentation for possible values
9-
directory: "/demo/graphtutorial" # Location of package manifests
9+
directory: "/user-auth/graphtutorial" # Location of package manifests
1010
schedule:
1111
interval: "weekly"
12+
- package-ecosystem: "pip" # See documentation for possible values
13+
directory: "/app-auth/graphapponlytutorial" # Location of package manifests
14+
schedule:
15+
interval: "weekly"

.github/workflows/pylint.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
name: Pylint
22

3-
on: [push]
3+
on:
4+
push:
5+
branches: [ main, live ]
6+
pull_request:
7+
branches: [ main, live ]
48

59
jobs:
610
build:
7-
defaults:
8-
run:
9-
working-directory: demo/graphtutorial
1011

1112
runs-on: ubuntu-latest
1213
strategy:
1314
matrix:
1415
python-version: ["3.8", "3.9", "3.10"]
16+
1517
steps:
1618
- uses: actions/checkout@v3
1719
- name: Set up Python ${{ matrix.python-version }}
1820
uses: actions/setup-python@v3
1921
with:
2022
python-version: ${{ matrix.python-version }}
21-
- name: Install dependencies
23+
- name: Install dependencies (user auth)
24+
working-directory: user-auth/graphtutorial
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -r requirements.txt
28+
pip install pylint
29+
- name: Analyzing the code with pylint (user auth)
30+
working-directory: user-auth/graphtutorial
31+
run: |
32+
pylint $(git ls-files '*.py')
33+
- name: Install dependencies (app auth)
34+
working-directory: app-auth/graphapponlytutorial
2235
run: |
2336
python -m pip install --upgrade pip
2437
pip install -r requirements.txt
2538
pip install pylint
26-
- name: Analysing the code with pylint
39+
- name: Analyzing the code with pylint (app auth)
40+
working-directory: app-auth/graphapponlytutorial
2741
run: |
2842
pylint $(git ls-files '*.py')

.vscode/launch.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@
88
"name": "Python: main",
99
"type": "python",
1010
"request": "launch",
11-
"program": "${workspaceFolder}/demo/graphtutorial/main.py",
12-
"cwd": "${workspaceFolder}/demo/graphtutorial",
11+
"program": "${workspaceFolder}/user-auth/graphtutorial/main.py",
12+
"cwd": "${workspaceFolder}/user-auth/graphtutorial",
13+
"console": "integratedTerminal",
14+
"justMyCode": true
15+
},
16+
{
17+
"name": "Python: main (app-only)",
18+
"type": "python",
19+
"request": "launch",
20+
"program": "${workspaceFolder}/app-auth/graphapponlytutorial/main.py",
21+
"cwd": "${workspaceFolder}/app-auth/graphapponlytutorial",
1322
"console": "integratedTerminal",
1423
"justMyCode": true
1524
}

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"cSpell.words": [
3+
"graphapponlytutorial",
4+
"graphtutorial",
5+
"Pylint"
6+
]
7+
}

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
[![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)
44

5-
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).
5+
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).
66

77
## Running the sample
88

9-
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.
9+
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.
10+
11+
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.
1012

1113
## Code of conduct
1214

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

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

app-auth/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

Comments
 (0)