Commit 39b60d6
Implement OAuth with URL elicitation and lazy authentication
Complete implementation of OAuth 2.1 authentication with MCP URL elicitation support:
**Core Features:**
- OAuth Manager with URL elicitation integration
- Lazy authentication (OAuth triggered on first tool call)
- Automatic flow selection (PKCE for native, device for Docker)
- Callback server cleanup after OAuth completion
- PKCE → Device flow fallback on failures
**URL Elicitation Integration:**
- PKCE flow: Browser auto-open with URL elicitation fallback
- Device flow: Always uses URL elicitation (no stderr)
- Returns mcp.URLElicitationRequiredError for client UI integration
- Background polling for token completion
- Automatic retry after authentication completes
**Architecture:**
- internal/oauth/manager.go: OAuth state management with elicitation
- Authentication middleware in server.go triggers OAuth on tool calls
- Dynamic scope computation based on enabled tools
- Zero-config ready (server starts without token)
**Flow Selection:**
- Docker without port → Device flow (automatic)
- Native binary → PKCE flow (browser opens)
- Docker with --oauth-callback-port → PKCE flow
- PKCE failure → Device flow fallback
**Security:**
- PKCE S256 for code exchange
- Device flow OAuth 2.0 standard
- State parameter prevents CSRF
- ReadHeaderTimeout prevents Slowloris
- Callback server closes after completion (frees port)
- Tokens never persisted
All tests pass ✓
Linting passes ✓
Builds successfully ✓
Co-authored-by: SamMorrowDrums <[email protected]>1 parent 88c632b commit 39b60d6
File tree
4 files changed
+371
-19
lines changed- cmd/github-mcp-server
- internal
- ghmcp
- oauth
4 files changed
+371
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | | - | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | | - | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | | - | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 54 | + | |
| 55 | + | |
63 | 56 | | |
64 | | - | |
65 | | - | |
66 | 57 | | |
67 | | - | |
68 | | - | |
69 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
70 | 61 | | |
71 | 62 | | |
72 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
73 | 69 | | |
74 | 70 | | |
75 | 71 | | |
| |||
106 | 102 | | |
107 | 103 | | |
108 | 104 | | |
| 105 | + | |
109 | 106 | | |
110 | 107 | | |
111 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
305 | 313 | | |
306 | 314 | | |
307 | 315 | | |
| |||
405 | 413 | | |
406 | 414 | | |
407 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
408 | 421 | | |
409 | 422 | | |
410 | 423 | | |
| |||
699 | 712 | | |
700 | 713 | | |
701 | 714 | | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
0 commit comments