Documentation
¶
Index ¶
- func RegisterCallbackRoutes(manager *swagger.RouteManager, handler *Handler)
- func RegisterRoutes(router *swagger.RouteGroup, authMiddleware gin.HandlerFunc, handler *Handler)
- type CallbackServerManager
- type Handler
- func (h *Handler) AuthorizeOAuth(c *gin.Context)
- func (h *Handler) CancelOAuthSession(c *gin.Context)
- func (h *Handler) CreateProviderFromToken(token *oauth2.Token, providerType oauth2.ProviderType, ...) (string, error)
- func (h *Handler) DeleteOAuthProvider(c *gin.Context)
- func (h *Handler) GetOAuthProvider(c *gin.Context)
- func (h *Handler) GetOAuthSessionStatus(c *gin.Context)
- func (h *Handler) GetOAuthToken(c *gin.Context)
- func (h *Handler) GetSessionManager() *SessionManager
- func (h *Handler) ListOAuthProviders(c *gin.Context)
- func (h *Handler) ListOAuthTokens(c *gin.Context)
- func (h *Handler) OAuthCallback(c *gin.Context)
- func (h *Handler) RefreshOAuthToken(c *gin.Context)
- func (h *Handler) RevokeOAuthToken(c *gin.Context)
- func (h *Handler) SetCallbackServerManager(csm CallbackServerManager)
- func (h *Handler) UpdateOAuthProvider(c *gin.Context)
- type OAuthAuthorizeRequest
- type OAuthAuthorizeResponse
- type OAuthCallbackDataResponse
- type OAuthCancelRequest
- type OAuthDeviceCodeResponse
- type OAuthErrorResponse
- type OAuthMessageResponse
- type OAuthProviderDataResponse
- type OAuthProviderInfo
- type OAuthProvidersResponse
- type OAuthRefreshTokenRequest
- type OAuthRefreshTokenResponse
- type OAuthSessionStatusResponse
- type OAuthTokenResponse
- type OAuthTokensResponse
- type OAuthUpdateProviderRequest
- type OAuthUpdateProviderResponse
- type Session
- type SessionManager
- func (sm *SessionManager) CancelSession(sessionID string) bool
- func (sm *SessionManager) CompleteSession(sessionID, providerUUID string)
- func (sm *SessionManager) CreateSession(provider, userID, redirect, responseType, name, proxyURL string) string
- func (sm *SessionManager) FailSession(sessionID, errMsg string)
- func (sm *SessionManager) GetSession(sessionID string) *Session
- func (sm *SessionManager) GetStatus(sessionID string) SessionStatus
- type SessionStatus
- type TokenInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterCallbackRoutes ¶
func RegisterCallbackRoutes(manager *swagger.RouteManager, handler *Handler)
RegisterCallbackRoutes registers unauthenticated callback routes These must be registered outside the authenticated API group
func RegisterRoutes ¶
func RegisterRoutes(router *swagger.RouteGroup, authMiddleware gin.HandlerFunc, handler *Handler)
RegisterRoutes registers OAuth API routes with swagger documentation
Types ¶
type CallbackServerManager ¶
type CallbackServerManager interface {
StartDynamicCallbackServer(sessionID string, port int) error
StopDynamicCallbackServer(sessionID string)
}
CallbackServerManager manages dynamic callback servers for OAuth
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles OAuth-related HTTP requests
func NewHandler ¶
NewHandler creates a new OAuth handler
func (*Handler) AuthorizeOAuth ¶
AuthorizeOAuth initiates OAuth authorization flow POST /api/v1/oauth/authorize
func (*Handler) CancelOAuthSession ¶
CancelOAuthSession cancels an in-progress OAuth session POST /api/v1/oauth/cancel
func (*Handler) CreateProviderFromToken ¶
func (h *Handler) CreateProviderFromToken(token *oauth2.Token, providerType oauth2.ProviderType, customName, sessionID string) (string, error)
CreateProviderFromToken is exported for use by the server's root OAuth callback
func (*Handler) DeleteOAuthProvider ¶
DeleteOAuthProvider deletes an OAuth provider configuration DELETE /api/v1/oauth/providers/:type
func (*Handler) GetOAuthProvider ¶
GetOAuthProvider returns a specific OAuth provider configuration GET /api/v1/oauth/providers/:type
func (*Handler) GetOAuthSessionStatus ¶
GetOAuthSessionStatus returns the status of an OAuth session GET /api/v1/oauth/status?session_id=xxx
func (*Handler) GetOAuthToken ¶
GetOAuthToken returns the OAuth token for a user and provider GET /api/v1/oauth/token?provider_uuid=xxx OR ?provider=xxx&user_id=xxx (deprecated)
func (*Handler) GetSessionManager ¶
func (h *Handler) GetSessionManager() *SessionManager
GetSessionManager returns the session manager (used for testing)
func (*Handler) ListOAuthProviders ¶
ListOAuthProviders returns all available OAuth providers GET /api/v1/oauth/providers
func (*Handler) ListOAuthTokens ¶
ListOAuthTokens lists all OAuth tokens for a user GET /api/v1/oauth/tokens?user_id=xxx (deprecated parameter, now lists all if not provided)
func (*Handler) OAuthCallback ¶
OAuthCallback handles OAuth callback from providers GET /oauth/callback and /callback
func (*Handler) RefreshOAuthToken ¶
RefreshOAuthToken refreshes an OAuth token using refresh token POST /api/v1/oauth/refresh
func (*Handler) RevokeOAuthToken ¶
RevokeOAuthToken revokes an OAuth token DELETE /api/v1/oauth/token?provider_uuid=xxx OR ?provider=xxx&user_id=xxx (deprecated)
func (*Handler) SetCallbackServerManager ¶
func (h *Handler) SetCallbackServerManager(csm CallbackServerManager)
SetCallbackServerManager sets the callback server manager (called by Server)
func (*Handler) UpdateOAuthProvider ¶
UpdateOAuthProvider updates an OAuth provider configuration PUT /api/v1/oauth/providers/:type
type OAuthAuthorizeRequest ¶
type OAuthAuthorizeRequest struct {
Provider string `json:"provider" binding:"required" description:"OAuth provider type" example:"anthropic"`
UserID string `json:"user_id" description:"User ID for the OAuth flow" example:"user123"`
Redirect string `json:"redirect" description:"URL to redirect after OAuth completion" example:"http://localhost:3000/callback"`
ResponseType string `json:"response_type" description:"Response type: 'redirect' or 'json'" example:"json"`
Name string `json:"name" description:"Custom name for the provider (optional, auto-generated if empty)" example:"my-claude-account"`
ProxyURL string `` /* 158-byte string literal not displayed */
}
OAuthAuthorizeRequest represents the request to initiate OAuth flow
type OAuthAuthorizeResponse ¶
type OAuthAuthorizeResponse struct {
Success bool `json:"success" example:"true"`
Message string `json:"message,omitempty" example:"Authorization initiated"`
Data struct {
AuthURL string `json:"auth_url,omitempty" example:"https://claude.ai/oauth/authorize?..."`
State string `json:"state,omitempty" example:"random_state_string"`
SessionID string `json:"session_id,omitempty" example:"abc123def456"` // For status tracking
// Device code flow fields
DeviceCode string `json:"device_code,omitempty" example:"MN-12345678-abcdef"`
UserCode string `json:"user_code,omitempty" example:"ABCD-EFGH"`
VerificationURI string `json:"verification_uri,omitempty" example:"https://chat.qwen.ai/activate"`
VerificationURIComplete string `json:"verification_uri_complete,omitempty" example:"https://chat.qwen.ai/activate?user_code=ABCD-EFGH"`
ExpiresIn int64 `json:"expires_in,omitempty" example:"1800"`
Interval int64 `json:"interval,omitempty" example:"5"`
Provider string `json:"provider,omitempty" example:"qwen_code"`
} `json:"data"`
}
OAuthAuthorizeResponse represents the response for OAuth authorization initiation
type OAuthCallbackDataResponse ¶
type OAuthCallbackDataResponse struct {
Success bool `json:"success" example:"true"`
AccessToken string `json:"access_token,omitempty" example:"sk-ant-..."`
RefreshToken string `json:"refresh_token,omitempty" example:"refresh_..."`
TokenType string `json:"token_type,omitempty" example:"Bearer"`
ExpiresAt string `json:"expires_at,omitempty" example:"2024-01-01T12:00:00Z"`
Provider string `json:"provider,omitempty" example:"anthropic"`
}
OAuthCallbackDataResponse represents the OAuth callback response with token data
type OAuthCancelRequest ¶
type OAuthCancelRequest struct {
SessionID string `json:"session_id" binding:"required" description:"Session ID to cancel" example:"abc123def456"`
}
OAuthCancelRequest represents the request to cancel an OAuth session
type OAuthDeviceCodeResponse ¶
type OAuthDeviceCodeResponse struct {
Success bool `json:"success" example:"true"`
Message string `json:"message,omitempty" example:"Device code flow initiated"`
Data struct {
DeviceCode string `json:"device_code" example:"MN-12345678-abcdef"`
UserCode string `json:"user_code" example:"ABCD-EFGH"`
VerificationURI string `json:"verification_uri" example:"https://chat.qwen.ai/activate"`
VerificationURIComplete string `json:"verification_uri_complete,omitempty" example:"https://chat.qwen.ai/activate?user_code=ABCD-EFGH"`
ExpiresIn int64 `json:"expires_in" example:"1800"`
Interval int64 `json:"interval" example:"5"`
Provider string `json:"provider" example:"qwen_code"`
} `json:"data"`
}
OAuthDeviceCodeResponse represents the response for device code flow initiation
type OAuthErrorResponse ¶
type OAuthErrorResponse struct {
Success bool `json:"success" example:"false"`
Error string `json:"error" example:"Error message"`
}
OAuthErrorResponse represents a standard error response
type OAuthMessageResponse ¶
type OAuthMessageResponse struct {
Success bool `json:"success" example:"true"`
Message string `json:"message" example:"Operation successful"`
}
OAuthMessageResponse represents a simple success message response
type OAuthProviderDataResponse ¶
type OAuthProviderDataResponse struct {
Success bool `json:"success" example:"true"`
Data OAuthProviderInfo `json:"data"`
}
OAuthProviderDataResponse represents a single provider data response
type OAuthProviderInfo ¶
type OAuthProviderInfo struct {
Type string `json:"type" example:"anthropic"`
DisplayName string `json:"display_name" example:"Anthropic Claude"`
AuthURL string `json:"auth_url,omitempty" example:"https://claude.ai/oauth/authorize"`
Scopes []string `json:"scopes,omitempty" example:"api"`
Configured bool `json:"configured" example:"true"`
}
OAuthProviderInfo represents OAuth provider information
type OAuthProvidersResponse ¶
type OAuthProvidersResponse struct {
Success bool `json:"success" example:"true"`
Data []OAuthProviderInfo `json:"data"`
}
OAuthProvidersResponse represents the response for listing OAuth providers
type OAuthRefreshTokenRequest ¶
type OAuthRefreshTokenRequest struct {
ProviderUUID string `` /* 135-byte string literal not displayed */
}
OAuthRefreshTokenRequest represents the request to refresh an OAuth token
type OAuthRefreshTokenResponse ¶
type OAuthRefreshTokenResponse struct {
Success bool `json:"success" example:"true"`
Message string `json:"message,omitempty" example:"Token refreshed successfully"`
Data struct {
ProviderUUID string `json:"provider_uuid" example:"550e8400-e29b-41d4-a716-446655440000"`
AccessToken string `json:"access_token" example:"sk-ant-..."`
RefreshToken string `json:"refresh_token,omitempty" example:"refresh_..."`
TokenType string `json:"token_type" example:"Bearer"`
ExpiresAt string `json:"expires_at,omitempty" example:"2024-01-01T12:00:00Z"`
ProviderType string `json:"provider_type" example:"claude_code"`
} `json:"data"`
}
OAuthRefreshTokenResponse represents the response for refreshing an OAuth token
type OAuthSessionStatusResponse ¶
type OAuthSessionStatusResponse struct {
Success bool `json:"success" example:"true"`
Data struct {
SessionID string `json:"session_id" example:"abc123def456"`
Status string `json:"status" example:"success"`
ProviderUUID string `json:"provider_uuid,omitempty" example:"550e8400-e29b-41d4-a716-446655440000"`
Error string `json:"error,omitempty" example:"Authorization failed"`
} `json:"data"`
}
OAuthSessionStatusResponse represents the session status check response
type OAuthTokenResponse ¶
type OAuthTokenResponse struct {
Success bool `json:"success" example:"true"`
Data struct {
AccessToken string `json:"access_token" example:"sk-ant-..."`
RefreshToken string `json:"refresh_token,omitempty" example:"refresh_..."`
TokenType string `json:"token_type" example:"Bearer"`
ExpiresAt string `json:"expires_at,omitempty" example:"2024-01-01T12:00:00Z"`
Provider string `json:"provider" example:"anthropic"`
Valid bool `json:"valid" example:"true"`
} `json:"data"`
}
OAuthTokenResponse represents the OAuth token response
type OAuthTokensResponse ¶
type OAuthTokensResponse struct {
Success bool `json:"success" example:"true"`
Data []TokenInfo `json:"data"`
}
OAuthTokensResponse represents the response for listing all user tokens
type OAuthUpdateProviderRequest ¶
type OAuthUpdateProviderRequest struct {
ClientID string `json:"client_id" binding:"required" description:"OAuth client ID" example:"your_client_id"`
ClientSecret string `json:"client_secret" description:"OAuth client secret" example:"your_client_secret"`
RedirectURL string `json:"redirect_url" description:"OAuth redirect URI" example:"http://localhost:12580/oauth/callback"`
}
OAuthUpdateProviderRequest represents the request to update OAuth provider config
type OAuthUpdateProviderResponse ¶
type OAuthUpdateProviderResponse struct {
Success bool `json:"success" example:"true"`
Message string `json:"message" example:"Provider configuration updated"`
Type string `json:"type,omitempty" example:"anthropic"`
}
OAuthUpdateProviderResponse represents the response for updating provider config
type Session ¶
type Session struct {
SessionID string
Provider string
UserID string
Redirect string
ResponseType string
Name string
ProxyURL string
Status string // "pending", "success", "failed", "cancelled"
ProviderUUID string
Error string
CreatedAt time.Time
ExpiresAt time.Time
}
Session represents an OAuth session state
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager manages OAuth session state
func NewSessionManager ¶
func NewSessionManager() *SessionManager
NewSessionManager creates a new session manager
func (*SessionManager) CancelSession ¶
func (sm *SessionManager) CancelSession(sessionID string) bool
CancelSession cancels a session
func (*SessionManager) CompleteSession ¶
func (sm *SessionManager) CompleteSession(sessionID, providerUUID string)
CompleteSession marks session as complete
func (*SessionManager) CreateSession ¶
func (sm *SessionManager) CreateSession(provider, userID, redirect, responseType, name, proxyURL string) string
CreateSession creates a new OAuth session
func (*SessionManager) FailSession ¶
func (sm *SessionManager) FailSession(sessionID, errMsg string)
FailSession marks session as failed
func (*SessionManager) GetSession ¶
func (sm *SessionManager) GetSession(sessionID string) *Session
GetSession retrieves a session
func (*SessionManager) GetStatus ¶
func (sm *SessionManager) GetStatus(sessionID string) SessionStatus
GetStatus returns session status