Skip to content

Commit 5368d10

Browse files
author
Vadim
committed
docs: improve auth README with mermaid decision flowchart and flow reference
1 parent 9d6879b commit 5368d10

1 file changed

Lines changed: 56 additions & 11 deletions

File tree

examples/auth/README.md

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,77 @@
11
# Microsoft Graph Authentication
22

3-
GraphClient supports the following authentication flows.
3+
Picking the right authentication flow depends on **who your app runs as** and
4+
**where it runs**. Use the chart below to decide, then jump to the example.
45

5-
| Flow | Method | File | Notes |
6-
|------|--------|------|-------|
7-
| **Client secret** | `with_client_secret(client_id, secret)` | [`with_client_secret.py`](./with_client_secret.py) | App-only, simplest setup |
8-
| **Certificate** | `GraphClient(tenant).with_client_certificate(client_id, thumbprint, key)` | [`with_client_cert.py`](./with_client_cert.py) | App-only, more secure |
9-
| **Interactive** | `with_token_interactive(client_id)` | [`interactive.py`](./interactive.py) | User + MFA compatible |
10-
| **ROPC** | `with_username_and_password(client_id, username, password)` | [`with_user_creds.py`](./with_user_creds.py) | User, no MFA |
11-
| **National cloud** | `AzureEnvironment.USGovernmentHigh` | [`gcc_high.py`](./gcc_high.py) | GCC, DoD, China |
6+
---
7+
8+
## Which flow should I use?
9+
10+
```mermaid
11+
flowchart TD
12+
A[Who will sign in?] --> B[An application / daemon]
13+
A --> C[A user]
14+
15+
B --> D{Where will it run?}
16+
D -->|Production| E[Client certificate\nmore secure]
17+
D -->|Development / simple| F[Client secret\nsimplest setup]
18+
19+
C --> G{User present to interact?}
20+
G -->|Yes| H[Interactive auth\nsupports MFA, SSO]
21+
G -->|No, script or CI| I[ROPC (password grant)\nno MFA, legacy]
22+
23+
E --> J[with_certificate.py]
24+
F --> K[with_client_secret.py]
25+
H --> L[interactive.py]
26+
I --> M[with_user_creds.py]
27+
28+
style A fill:#1a73e8,color:#fff
29+
style B fill:#e8f0fe
30+
style C fill:#e8f0fe
31+
style E fill:#fff3cd
32+
style F fill:#fff3cd
33+
style H fill:#d4edda
34+
style I fill:#f8d7da
35+
```
36+
37+
---
38+
39+
## Flow reference
40+
41+
| Flow | Method | Best for | MFA? | File |
42+
|------|--------|----------|:----:|------|
43+
| **Client secret** | `with_client_secret(client_id, secret)` | Daemons, cron jobs, CI/CD — app-only access || [`with_client_secret.py`](./with_client_secret.py) |
44+
| **Client certificate** | `with_certificate(client_id, thumbprint, key)` | Production daemons — app-only, no shared secret || [`with_client_cert.py`](./with_client_cert.py) |
45+
| **Interactive** | `with_token_interactive(client_id)` | Desktop apps, CLI tools — user signed-in || [`interactive.py`](./interactive.py) |
46+
| **ROPC (password)** | `with_username_and_password(client_id, user, pass)` | Automated scripts — user context, no interactivity || [`with_user_creds.py`](./with_user_creds.py) |
47+
| **National cloud** | `AzureEnvironment.USGovernmentHigh` | GCC High, DoD, China — applies to any flow above | varies | [`gcc_high.py`](./gcc_high.py) |
48+
49+
---
50+
51+
## Quick start
1252

1353
```python
1454
from office365.graph_client import GraphClient
1555

16-
# Client secret (recommended for app-only)
56+
# App-only (daemon / background job) — simplest
1757
client = GraphClient(tenant="contoso.onmicrosoft.com").with_client_secret(
18-
client_id="your_client_id", client_secret="your_secret"
58+
client_id="your_client_id", client_secret=***
1959
)
2060

21-
# Interactive (MFA-compatible)
61+
# User-authenticated (desktop app) — MFA compatible
2262
client = GraphClient(tenant="contoso.onmicrosoft.com").with_token_interactive(
2363
client_id="your_client_id"
2464
)
2565
```
2666

67+
> **Note:** All examples use `tests/` module constants. Replace them with
68+
> your own values from the [Azure Portal](https://portal.azure.com).
69+
> App-only flows need admin consent granted in the portal.
70+
2771
---
2872

2973
## Official docs
3074

3175
- [Microsoft Graph authentication overview](https://learn.microsoft.com/en-us/graph/auth)
3276
- [Microsoft identity platform auth flows](https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows)
77+
- [Choose an auth flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#which-auth-flow-should-i-use)

0 commit comments

Comments
 (0)