You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: revise and expand authentication documentation for clarity
- Rewrite and expand introduction for greater clarity about CLI usage and token handling
- Add a new overview section detailing automatic browser launch, local server callback, and token storage/reuse
- Enhance security documentation, specifying defaults and mitigations for PKCE, state parameter, TLS, and token file permissions
- Introduce explicit prerequisites and a sample `.env.example` file for easier setup
- Make configuration options more prominent, clarifying precedence among flags, environment variables, and defaults
- Add detailed sample terminal output for both first and subsequent authentication runs
- Improve explanation of client modes, including a clear table for use case selection
- Expand token lifecycle information, including a visual decision tree to show reuse, refresh, and re-auth flow
- Clarify multi-client token storage and recommend adding token files to `.gitignore`
- Replace a list of security practices with a mitigation table for easier reference
- Add section dividers throughout for improved readability and navigation
Signed-off-by: appleboy <appleboy.tw@gmail.com>
[](https://github.com/go-authgate/oauth-cli/actions/workflows/testing.yml)
A command-line tool that demonstrates the **OAuth 2.0 Authorization Code Flow** (RFC 6749 §4.1) with **PKCE** (RFC 7636) against an AuthGate server.
6
+
A CLI tool that authenticates with an AuthGate server by opening your browser, then manages OAuth 2.0 tokens locally — no manual code copying required.
7
7
8
-
Unlike the Device Code Flow (which shows a user code to enter manually), this flow opens a browser window and receives the authorization code via a local HTTP callback server.
8
+
**What it does:**
9
9
10
-
## Which Client Mode Should I Use?
10
+
- Opens your browser at the AuthGate authorization page automatically
11
+
- Spins up a local HTTP server to receive the OAuth callback
12
+
- Exchanges the authorization code for tokens and saves them to disk
13
+
- On subsequent runs, reuses valid tokens or refreshes them silently
@@ -76,8 +169,12 @@ go run . -client-id=550e8400-... \
76
169
-redirect-uri=http://localhost:9000/callback
77
170
```
78
171
172
+
---
173
+
79
174
## How It Works
80
175
176
+
The CLI acts as an OAuth 2.0 client: it builds an authorization URL, opens the browser, then waits on a local HTTP server for the callback carrying the authorization code. Once received, it exchanges the code for tokens and saves them locally.
177
+
81
178
```mermaid
82
179
sequenceDiagram
83
180
participant CLI as CLI Tool
@@ -107,15 +204,35 @@ sequenceDiagram
107
204
108
205
PKCE (Proof Key for Code Exchange) is used for all clients — including confidential ones — for defence in depth. The CLI generates a fresh `code_verifier` and `code_challenge` on every authorization attempt.
109
206
110
-
### Token Lifecycle
207
+
---
208
+
209
+
## Token Lifecycle
210
+
211
+
On every run the CLI follows this decision tree:
212
+
213
+
```
214
+
Load token from disk
215
+
│
216
+
├─ Not found ──────────────► Full Authorization Code Flow
217
+
│
218
+
├─ Found, still valid ─────► Use immediately
219
+
│
220
+
└─ Found, expired
221
+
│
222
+
├─ Refresh succeeds ► Use refreshed token
223
+
│
224
+
└─ Refresh fails ──► Full Authorization Code Flow
225
+
```
111
226
112
227
-**Reuse**: Valid tokens are loaded from disk and used immediately.
113
228
-**Refresh**: Expired access tokens are refreshed silently using the stored refresh token.
114
229
-**Re-auth**: If the refresh token is also expired or invalid, the full Authorization Code Flow restarts.
115
230
231
+
---
232
+
116
233
## Token Storage
117
234
118
-
Tokens are saved to `.authgate-tokens.json` (configurable). The file supports multiple client IDs:
235
+
Tokens are saved to `.authgate-tokens.json` (configurable). The file supports multiple client IDs so you can authenticate against several clients without conflicts:
119
236
120
237
```json
121
238
{
@@ -133,13 +250,21 @@ Tokens are saved to `.authgate-tokens.json` (configurable). The file supports mu
133
250
134
251
The file is written with `0600` permissions and uses atomic rename to prevent corruption.
135
252
253
+
> **Tip:** Add `.authgate-tokens.json` to your `.gitignore` to avoid accidentally committing tokens.
0 commit comments