@@ -73,24 +73,94 @@ required. The CLI is self-contained.
7373
7474### Login (persistent)
7575
76+ Three login methods are supported. Pick the one that fits your situation:
77+
78+ #### 1. Browser OAuth (default) — recommended for interactive use
79+
80+ Opens your default browser to the Microsoft sign-in page, then captures the
81+ auth code on a local callback. Works with both work/school (AAD) and personal
82+ (MSA) Microsoft accounts. Personal accounts (e.g. ` me@outlook.com ` ) on
83+ ` *.visualstudio.com ` orgs are supported via an ARM-first token-exchange flow.
84+
7685``` bash
77- # Personal Access Token (recommended for CI / headless)
78- ado login --method pat --org myorg --pat mytoken
86+ # Open browser, sign in, get redirected back. Org auto-detected.
87+ ado login
7988
80- # Interactive browser-based OAuth ( auto-detects org on success )
89+ # Hint the org (avoids the auto-detect query )
8190ado login --org myorg
82- # Or just:
83- ado login
91+ ```
92+
93+ What happens:
94+ 1 . ` ado ` opens ` https://login.microsoftonline.com/... ` in your browser
95+ 2 . You sign in with AAD or MSA credentials
96+ 3 . The CLI captures the auth code on a localhost callback
97+ 4 . The CLI exchanges the code for an ARM token, then for an Azure DevOps
98+ access token, and saves the token to ` ~/.ado_cli/config.json `
99+ 5 . Org is auto-detected from the token (or use ` --org ` to pin it)
100+
101+ #### 2. Device code — recommended for SSH / no-browser sessions
102+
103+ For headless terminals, remote boxes, or any machine without a browser
104+ reachable from the same shell. The CLI prints a URL and a code; you visit
105+ the URL in any browser (laptop, phone) and enter the code to authenticate.
84106
85- # Device code (no browser on this machine)
107+ ``` bash
86108ado login --method device --org myorg
109+ ```
87110
88- # Check status
89- ado whoami
111+ Example output:
90112
91- # Remove stored credentials
92- ado logout
93113```
114+ To sign in, use a web browser to open:
115+ https://microsoft.com/devicelogin
116+ And enter the code: ABC123XYZ
117+ ```
118+
119+ The CLI polls the token endpoint every few seconds; once you complete the
120+ sign-in on the other device, the CLI saves the token and you're logged in.
121+
122+ #### 3. Personal Access Token (PAT) — recommended for CI / scripts
123+
124+ Stores a PAT in ` ~/.ado_cli/config.json ` for repeated use. Best for
125+ automation, CI runners, and scripts. See
126+ [ How to create a PAT] ( https://learn.microsoft.com/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate ) .
127+
128+ ``` bash
129+ ado login --method pat --org myorg --pat mytoken
130+ ```
131+
132+ Required scopes for full CLI coverage: ` vso.work ` , ` vso.code ` , ` vso.project ` ,
133+ ` vso.build ` , ` vso.release ` (or "Full access" if you prefer).
134+
135+ #### 4. Environment variables (no login) — recommended for ephemeral CI
136+
137+ Skip ` ado login ` entirely by setting env vars in the runner / shell:
138+
139+ ``` bash
140+ export ADO_ORG=myorg
141+ export ADO_PAT=mytoken
142+ ado projects list
143+ ```
144+
145+ ` ADO_PAT ` is only read from the environment; it is never written to the
146+ config file. ` ADO_ORG ` is also accepted as a CLI flag (` --org myorg ` ).
147+
148+ #### Check status / log out
149+
150+ ``` bash
151+ ado whoami # Show current auth method, org, server
152+ ado logout # Remove ~/.ado_cli/config.json
153+ ```
154+
155+ ### Auth priority order
156+
157+ When you run a command, the CLI resolves credentials in this order:
158+
159+ 1 . ` --pat ` / ` --org ` CLI flags (per-invocation)
160+ 2 . ` ADO_PAT ` / ` ADO_ORG ` env vars (per-session)
161+ 3 . ` ~/.ado_cli/config.json ` (persistent, set via ` ado login ` )
162+
163+ The first source that provides both an org and a token wins.
94164
95165---
96166
0 commit comments