Documentation
¶
Overview ¶
Package oauthas is GraphNest's OAuth 2.1 authorization server for MCP clients: dynamic public-client registration, PKCE authorization code flow gated by an explicit consent page, and rotating refresh tokens whose access tokens authenticate the /mcp endpoint as the granting user.
Index ¶
- Constants
- func HasAccessTokenShape(token string) bool
- type GitHubAccess
- type GitHubTokenSource
- type ProviderTokens
- func (p *ProviderTokens) Available(requestHash [32]byte, subject string) bool
- func (p *ProviderTokens) DeleteForCode(codeHash [32]byte)
- func (p *ProviderTokens) Deposit(_ context.Context, requestHash [32]byte, subject, providerToken string)
- func (p *ProviderTokens) TokenForCode(codeHash [32]byte) (string, bool)
- func (p *ProviderTokens) Transfer(requestHash [32]byte, subject string, codeHash [32]byte) bool
- type Sealer
- type Server
- type SessionAuthenticator
Constants ¶
const ( // Lifetimes. Access tokens are short so revocation and GitHub-derived // access changes propagate within the hour; the grant itself is capped. AccessTokenTTL = time.Hour GrantTTL = 30 * 24 * time.Hour RequestCookie = "__Host-graphnest_oauth_req" ResumePath = "/oauth/authorize/resume" MCPPath = "/mcp" ProtectedResourceMetadataPath = "/.well-known/oauth-protected-resource" )
const ( OperationClientRegistered = audit.OperationOAuthClientRegistered OperationConsentGranted = audit.OperationOAuthConsentGranted OperationConsentDenied = audit.OperationOAuthConsentDenied OperationGrantCreated = audit.OperationOAuthGrantCreated OperationGrantRefreshed = audit.OperationOAuthGrantRefreshed OperationGrantRevoked = audit.OperationOAuthGrantRevoked OperationGrantReplay = audit.OperationOAuthGrantReplay )
Audit operations recorded by the authorization server.
const ( AccessTokenPrefix = "gno_" RefreshTokenPrefix = "gnr_" CodePrefix = "gnac_" ClientIDPrefix = "gnc_" )
Token prefixes let the bearer authenticator route a token to the right table without a lookup and keep the kinds visually distinct in logs.
Variables ¶
This section is empty.
Functions ¶
func HasAccessTokenShape ¶
HasAccessTokenShape reports whether a bearer credential is an OAuth access token, so the bearer path can pick an authenticator without a lookup.
Types ¶
type GitHubAccess ¶
type GitHubAccess interface {
AccessibleRepositories(ctx context.Context, accessToken string) ([]int64, error)
}
GitHubAccess re-derives a user's repository access from GitHub with the user's own token; it is nil when GitHub-derived access is not configured.
type GitHubTokenSource ¶
type GitHubTokenSource interface {
Available(requestHash [32]byte, subject string) bool
Transfer(requestHash [32]byte, subject string, codeHash [32]byte) bool
TokenForCode(codeHash [32]byte) (string, bool)
DeleteForCode(codeHash [32]byte)
}
GitHubTokenSource is the hand-off from the login that completed a pending authorization to the code exchange: consent moves the identity provider's token from the browser session to the authorization code, exchange removes it after the authorization code commits.
type ProviderTokens ¶
type ProviderTokens struct {
// contains filtered or unexported fields
}
ProviderTokens is the in-memory hand-off between a browser login that continues an MCP authorization and the code exchange that follows it. Login deposits the identity provider's user token under the pending request; consent moves it to the authorization code; exchange takes it and seals it into the grant. Entries expire with the authorization request, so nothing outlives the flow and nothing is ever written to disk in plaintext.
ponytail: a process-local map. A multi-replica deployment needs the login and the exchange to hit the same replica, or a shared sealed store.
func NewProviderTokens ¶
func NewProviderTokens(now func() time.Time) *ProviderTokens
func (*ProviderTokens) Available ¶
func (p *ProviderTokens) Available(requestHash [32]byte, subject string) bool
Available checks a pending handoff without consuming it.
func (*ProviderTokens) DeleteForCode ¶
func (p *ProviderTokens) DeleteForCode(codeHash [32]byte)
DeleteForCode removes the token after its authorization code is consumed.
func (*ProviderTokens) Deposit ¶
func (p *ProviderTokens) Deposit(_ context.Context, requestHash [32]byte, subject, providerToken string)
Deposit implements browserflow.ProviderTokenSink. The validated login binds its provider token and trusted GraphNest subject to one pending request.
func (*ProviderTokens) TokenForCode ¶
func (p *ProviderTokens) TokenForCode(codeHash [32]byte) (string, bool)
TokenForCode returns the token attached to a live authorization code.
type Sealer ¶
type Sealer struct {
// contains filtered or unexported fields
}
Sealer encrypts GitHub user tokens at rest with AES-256-GCM. The grant ID is authenticated additional data so a ciphertext cannot be moved between rows.
type Server ¶
type Server struct {
Origin string
LoginPath string
GitHubLoginPath string
Store authn.OAuthStore
Sessions SessionAuthenticator
Sealer *Sealer
GitHub GitHubAccess
GitHubTokens GitHubTokenSource
Audit audit.Recorder
Now func() time.Time
Rand io.Reader
// UserName renders the consent page; nil falls back to the subject.
UserName func(context.Context, authn.Principal) string
// Limiter must enforce shared budgets before registration or token requests.
Limiter authn.OAuthRequestLimiter
}
Server is the authorization server. All URLs derive from Origin.