oauth

package
v1.261112.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: MPL-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OAuthOptions added in v0.260507.1

func OAuthOptions(proxyURL, baseURL string) []oauth.Option

func OAuthOptionsForSession added in v0.260507.1

func OAuthOptionsForSession(manager *oauth.Manager, sessionID, baseURL string) []oauth.Option

func SafeTokenPreview added in v0.260507.1

func SafeTokenPreview(token string) string

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

func NewHandler(oauthManager *oauth.Manager, cfg *config.Config) *Handler

NewHandler creates a new OAuth handler

func (*Handler) AuthorizeOAuth

func (h *Handler) AuthorizeOAuth(c *gin.Context)

AuthorizeOAuth initiates OAuth authorization flow POST /api/v1/oauth/authorize

func (*Handler) CancelOAuthSession

func (h *Handler) CancelOAuthSession(c *gin.Context)

CancelOAuthSession cancels an in-progress OAuth session POST /api/v1/oauth/cancel

func (*Handler) CreateProviderFromToken

func (h *Handler) CreateProviderFromToken(token *oauth.Token, issuer ai.Issuer, customName, sessionID string) (string, error)

CreateProviderFromToken is exported for use by the server's root OAuth callback

func (*Handler) DeleteOAuthProvider

func (h *Handler) DeleteOAuthProvider(c *gin.Context)

DeleteOAuthProvider deletes an OAuth provider configuration DELETE /api/v1/oauth/providers/:type

func (*Handler) GetOAuthProvider

func (h *Handler) GetOAuthProvider(c *gin.Context)

GetOAuthProvider returns a specific OAuth provider configuration GET /api/v1/oauth/providers/:type

func (*Handler) GetOAuthSessionStatus

func (h *Handler) GetOAuthSessionStatus(c *gin.Context)

GetOAuthSessionStatus returns the status of an OAuth session GET /api/v1/oauth/status?session_id=xxx

func (*Handler) GetOAuthToken

func (h *Handler) GetOAuthToken(c *gin.Context)

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) ListOAuthProviders

func (h *Handler) ListOAuthProviders(c *gin.Context)

ListOAuthProviders returns all available OAuth providers GET /api/v1/oauth/providers

func (*Handler) ListOAuthTokens

func (h *Handler) ListOAuthTokens(c *gin.Context)

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

func (h *Handler) OAuthCallback(c *gin.Context)

OAuthCallback handles OAuth callback from providers GET /oauth/callback and /callback

func (*Handler) RefreshOAuthToken

func (h *Handler) RefreshOAuthToken(c *gin.Context)

RefreshOAuthToken refreshes an OAuth token using refresh token POST /api/v1/oauth/refresh

func (*Handler) RegisterRoutes added in v1.261002.1

func (h *Handler) RegisterRoutes(rt *module.Routes)

RegisterRoutes registers the authenticated OAuth API routes on the V1 group (which already carries user auth) and the unauthenticated provider callback routes on the engine.

func (*Handler) RevokeOAuthToken

func (h *Handler) RevokeOAuthToken(c *gin.Context)

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

func (h *Handler) UpdateOAuthProvider(c *gin.Context)

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 */
	// ProviderUUID, when set, re-authenticates an existing OAuth provider and
	// overwrites its credentials in place (same UUID) instead of creating a new
	// provider. The provider's issuer must match the requested provider type.
	ProviderUUID string `` /* 178-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

type SessionStatus

type SessionStatus struct {
	SessionID    string `json:"session_id"`
	Status       string `json:"status"`
	ProviderUUID string `json:"provider_uuid,omitempty"`
	Error        string `json:"error,omitempty"`
}

SessionStatus represents the status of an OAuth session

type TokenInfo

type TokenInfo struct {
	Provider  string `json:"provider" example:"anthropic"`
	Valid     bool   `json:"valid" example:"true"`
	ExpiresAt string `json:"expires_at,omitempty" example:"2024-01-01T12:00:00Z"`
}

TokenInfo represents OAuth token information

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL