-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: implement OAuth device flow authentication #1649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
d322e26
63545b8
4e68d8f
6b631f8
4a1c61e
b99bcea
810ec95
2b89711
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,321 @@ | ||||||||||||||||||
| # OAuth Device Flow Authentication Design | ||||||||||||||||||
|
|
||||||||||||||||||
| ## Overview | ||||||||||||||||||
|
|
||||||||||||||||||
| This document describes the implementation of OAuth Device Flow authentication for the GitHub MCP Server's stdio transport. The design enables users to authenticate without pre-configuring tokens, making setup significantly simpler. | ||||||||||||||||||
|
|
||||||||||||||||||
| ## Problem Statement | ||||||||||||||||||
|
|
||||||||||||||||||
| Currently, users must: | ||||||||||||||||||
| 1. Generate a Personal Access Token (PAT) manually on GitHub | ||||||||||||||||||
| 2. Configure the token in their MCP host's configuration (often in plain text) | ||||||||||||||||||
| 3. Manage token rotation manually | ||||||||||||||||||
|
|
||||||||||||||||||
| This creates friction for new users and security concerns around token storage. | ||||||||||||||||||
|
|
||||||||||||||||||
| ## Proposed Solution | ||||||||||||||||||
|
|
||||||||||||||||||
| When the server starts without a `GITHUB_PERSONAL_ACCESS_TOKEN`, instead of failing, it starts in "unauthenticated mode" with only authentication tools available. Users authenticate through MCP tool calls: | ||||||||||||||||||
|
|
||||||||||||||||||
| 1. **`auth_login`** - Initiates device flow, returns verification URL and user code | ||||||||||||||||||
| 2. **`auth_verify`** - Completes the flow after user authorizes in browser | ||||||||||||||||||
|
|
||||||||||||||||||
| Once authenticated, the token is held in memory for the session and all regular tools become available. | ||||||||||||||||||
|
|
||||||||||||||||||
| ## User Experience | ||||||||||||||||||
|
|
||||||||||||||||||
| ### Before (Current) | ||||||||||||||||||
| ```jsonc | ||||||||||||||||||
| { | ||||||||||||||||||
| "githubz": { | ||||||||||||||||||
|
||||||||||||||||||
| "githubz": { | |
| "github": { |
Outdated
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user flow documented here shows a two-step process with auth_verify, but the actual implementation uses a single auth_login tool that blocks and polls. This discrepancy between design documentation and implementation could confuse developers. The documentation should reflect that auth_login is a single blocking call that handles the entire flow.
Outdated
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The state machine diagram includes a "PENDING_AUTH" state, but in the actual auth.go implementation, the state is called "AuthStatePending" (not "PENDING_AUTH"). The diagram should use the actual constant names for accuracy, or the constants should match the design document.
Outdated
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation claims default scopes "match gh CLI minimal scopes" but lists far more scopes than just the three mentioned (repo, read:org, gist). The actual DefaultOAuthScopes in auth.go includes 11 scopes. Either the documentation should list all scopes accurately or the claim about matching gh CLI should be verified and updated.
| Default OAuth App scopes (matching `gh` CLI minimal scopes): | |
| - `repo` - Full control of private repositories | |
| - `read:org` - Read org membership | |
| - `gist` - Create gists | |
| Default OAuth App scopes: | |
| - The authoritative list of scopes is defined in `DefaultOAuthScopes` in `pkg/github/auth.go`. | |
| - These scopes form a superset of the `gh` CLI minimal scopes (`repo`, `read:org`, `gist`) to support all GitHub MCP tools while still following least-privilege principles. |
Outdated
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation refers to the file as "pkg/github/auth_state.go" but the actual implementation is in "pkg/github/auth.go". The filename in the documentation should be corrected to match the actual implementation.
| #### 1. Auth State Manager (`pkg/github/auth_state.go`) | |
| #### 1. Auth State Manager (`pkg/github/auth.go`) |
Outdated
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Auth Tools section documents both auth_login and auth_verify as separate tools, but the implementation only has auth_login which handles the complete flow. This section should be updated to show only auth_login and document that it's a blocking call that handles both initiation and completion.
Outdated
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Security Considerations section mentions "PKCE - Use PKCE extension for additional security (if supported)" but the implementation in auth.go doesn't actually implement PKCE. This security consideration should either be marked as a future enhancement/TODO, or the documentation should be updated to remove this claim since it's not currently implemented.
| 4. **PKCE** - Use PKCE extension for additional security (if supported) | |
| 4. **PKCE (future enhancement)** - Plan to add PKCE extension for additional security in a future implementation |
Outdated
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Implementation Plan references "pkg/github/auth_state.go" but the actual file is "pkg/github/auth.go". This should be corrected to reflect the actual filename used in the implementation.
| 1. Add `pkg/github/auth_state.go` - Auth state management | |
| 1. Add `pkg/github/auth.go` - Auth state management |
Outdated
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sequence diagram shows two separate tool calls (auth_login and auth_verify), but the actual implementation has auth_login as a single blocking call that polls internally. The diagram should be updated to show auth_login doing the polling loop internally rather than requiring a second auth_verify call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation comment mentions "auth_verify" tool but based on the code in auth_tools.go, there is only an "auth_login" tool that handles both initiation and completion of the flow. The design document should be updated to reflect the actual implementation where polling happens within the single auth_login tool call.