oauth

package
v0.1.147 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSessionTTL = 10 * time.Minute
)

Variables

View Source
var (
	ErrProviderNotFound      = errors.New("provider not found")
	ErrIntegrationNotFound   = errors.New("integration not found")
	ErrProviderNotConfigured = errors.New("provider not configured")
)
View Source
var (
	ErrSessionNotFound = errors.New("session not found")
	ErrSessionExpired  = errors.New("session expired")
	ErrStorageFailed   = errors.New("storage operation failed")
)

Functions

func AnnotateCredentials added in v0.1.71

func AnnotateCredentials(integrationType string, creds *types.IntegrationCredentials, grantedScopes []string) *types.IntegrationCredentials

func MergeCredentialMetadata added in v0.1.71

func MergeCredentialMetadata(target, source *types.IntegrationCredentials) *types.IntegrationCredentials

MergeCredentialMetadata copies all Extra keys from source to target when missing. This keeps persisted metadata (capabilities, scopes, cloud_id, etc.) stable across token refreshes.

func NeedsRefresh

func NeedsRefresh(creds *types.IntegrationCredentials) bool

NeedsRefresh returns true if credentials are expired or about to expire.

func NormalizeScopes added in v0.1.71

func NormalizeScopes(scopes ...[]string) []string

func ParseScopeString added in v0.1.71

func ParseScopeString(scope string) []string

Types

type AtlassianProvider added in v0.1.95

type AtlassianProvider struct {
	// contains filtered or unexported fields
}

AtlassianProvider handles Atlassian OAuth 2.0 (3LO) operations.

func NewAtlassianProvider added in v0.1.95

func NewAtlassianProvider(creds types.ProviderOAuthCredentials, callbackURL string) *AtlassianProvider

func (*AtlassianProvider) AuthorizeURL added in v0.1.95

func (a *AtlassianProvider) AuthorizeURL(state, integrationType string) (string, error)

func (*AtlassianProvider) Exchange added in v0.1.95

func (a *AtlassianProvider) Exchange(ctx context.Context, code, integrationType string) (*types.IntegrationCredentials, error)

func (*AtlassianProvider) Integrations added in v0.1.95

func (a *AtlassianProvider) Integrations() []string

func (*AtlassianProvider) IsConfigured added in v0.1.95

func (a *AtlassianProvider) IsConfigured() bool

func (*AtlassianProvider) Name added in v0.1.95

func (a *AtlassianProvider) Name() string

func (*AtlassianProvider) Refresh added in v0.1.95

func (a *AtlassianProvider) Refresh(ctx context.Context, refreshToken string) (*types.IntegrationCredentials, error)

type Backend added in v0.1.15

type Backend interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
	Delete(ctx context.Context, key string) error
}

Backend abstracts session storage.

type GitHubProvider

type GitHubProvider struct {
	// contains filtered or unexported fields
}

GitHubProvider handles GitHub OAuth operations.

func NewGitHubProvider

func NewGitHubProvider(creds types.ProviderOAuthCredentials, callbackURL string) *GitHubProvider

func (*GitHubProvider) AuthorizeURL

func (g *GitHubProvider) AuthorizeURL(state, integrationType string) (string, error)

func (*GitHubProvider) Exchange

func (g *GitHubProvider) Exchange(ctx context.Context, code, integrationType string) (*types.IntegrationCredentials, error)

func (*GitHubProvider) Integrations added in v0.1.15

func (g *GitHubProvider) Integrations() []string

func (*GitHubProvider) IsConfigured

func (g *GitHubProvider) IsConfigured() bool

func (*GitHubProvider) Name

func (g *GitHubProvider) Name() string

func (*GitHubProvider) Refresh

func (g *GitHubProvider) Refresh(ctx context.Context, refreshToken string) (*types.IntegrationCredentials, error)

type GoogleProvider

type GoogleProvider struct {
	// contains filtered or unexported fields
}

GoogleProvider handles Google OAuth operations.

func NewGoogleProvider

func NewGoogleProvider(creds types.ProviderOAuthCredentials, callbackURL string) *GoogleProvider

func (*GoogleProvider) AuthorizeURL

func (g *GoogleProvider) AuthorizeURL(state, integrationType string) (string, error)

func (*GoogleProvider) Exchange

func (g *GoogleProvider) Exchange(ctx context.Context, code, integrationType string) (*types.IntegrationCredentials, error)

func (*GoogleProvider) Integrations added in v0.1.15

func (g *GoogleProvider) Integrations() []string

func (*GoogleProvider) IsConfigured

func (g *GoogleProvider) IsConfigured() bool

func (*GoogleProvider) Name

func (g *GoogleProvider) Name() string

func (*GoogleProvider) Refresh

func (g *GoogleProvider) Refresh(ctx context.Context, refreshToken string) (*types.IntegrationCredentials, error)

type LinearProvider added in v0.1.9

type LinearProvider struct {
	// contains filtered or unexported fields
}

LinearProvider handles Linear OAuth operations.

func NewLinearProvider added in v0.1.9

func NewLinearProvider(creds types.ProviderOAuthCredentials, callbackURL string) *LinearProvider

func (*LinearProvider) AuthorizeURL added in v0.1.9

func (l *LinearProvider) AuthorizeURL(state, integrationType string) (string, error)

func (*LinearProvider) Exchange added in v0.1.9

func (l *LinearProvider) Exchange(ctx context.Context, code, integrationType string) (*types.IntegrationCredentials, error)

func (*LinearProvider) Integrations added in v0.1.15

func (l *LinearProvider) Integrations() []string

func (*LinearProvider) IsConfigured added in v0.1.9

func (l *LinearProvider) IsConfigured() bool

func (*LinearProvider) Name added in v0.1.9

func (l *LinearProvider) Name() string

func (*LinearProvider) Refresh added in v0.1.9

func (l *LinearProvider) Refresh(ctx context.Context, refreshToken string) (*types.IntegrationCredentials, error)

type MicrosoftProvider added in v0.1.143

type MicrosoftProvider struct {
	// contains filtered or unexported fields
}

MicrosoftProvider handles Microsoft OAuth 2.0 operations.

func NewMicrosoftProvider added in v0.1.143

func NewMicrosoftProvider(creds types.ProviderOAuthCredentials, callbackURL string) *MicrosoftProvider

func (*MicrosoftProvider) AuthorizeURL added in v0.1.143

func (m *MicrosoftProvider) AuthorizeURL(state, integrationType string) (string, error)

func (*MicrosoftProvider) Exchange added in v0.1.143

func (m *MicrosoftProvider) Exchange(ctx context.Context, code, integrationType string) (*types.IntegrationCredentials, error)

func (*MicrosoftProvider) Integrations added in v0.1.143

func (m *MicrosoftProvider) Integrations() []string

func (*MicrosoftProvider) IsConfigured added in v0.1.143

func (m *MicrosoftProvider) IsConfigured() bool

func (*MicrosoftProvider) Name added in v0.1.143

func (m *MicrosoftProvider) Name() string

func (*MicrosoftProvider) Refresh added in v0.1.143

func (m *MicrosoftProvider) Refresh(ctx context.Context, refreshToken string) (*types.IntegrationCredentials, error)

type NotionProvider

type NotionProvider struct {
	// contains filtered or unexported fields
}

NotionProvider handles Notion OAuth operations.

func NewNotionProvider

func NewNotionProvider(creds types.ProviderOAuthCredentials, callbackURL string) *NotionProvider

func (*NotionProvider) AuthorizeURL

func (n *NotionProvider) AuthorizeURL(state, integrationType string) (string, error)

func (*NotionProvider) Exchange

func (n *NotionProvider) Exchange(ctx context.Context, code, integrationType string) (*types.IntegrationCredentials, error)

func (*NotionProvider) Integrations added in v0.1.15

func (n *NotionProvider) Integrations() []string

func (*NotionProvider) IsConfigured

func (n *NotionProvider) IsConfigured() bool

func (*NotionProvider) Name

func (n *NotionProvider) Name() string

func (*NotionProvider) Refresh

func (n *NotionProvider) Refresh(ctx context.Context, refreshToken string) (*types.IntegrationCredentials, error)

type Provider

type Provider interface {
	// Name returns the provider name (e.g., "google", "github")
	Name() string

	// IsConfigured returns true if the provider has valid credentials
	IsConfigured() bool

	// Integrations returns the integration types this provider handles
	Integrations() []string

	// AuthorizeURL generates the OAuth authorization URL for the given integration
	AuthorizeURL(state, integrationType string) (string, error)

	// Exchange exchanges an authorization code for tokens
	Exchange(ctx context.Context, code, integrationType string) (*types.IntegrationCredentials, error)

	// Refresh refreshes an access token using a refresh token
	Refresh(ctx context.Context, refreshToken string) (*types.IntegrationCredentials, error)
}

Provider defines the interface for OAuth providers.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages OAuth providers and maps integration types to providers.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new provider registry.

func (*Registry) GetProvider

func (r *Registry) GetProvider(name string) (Provider, error)

GetProvider returns a provider by name.

func (*Registry) GetProviderForIntegration

func (r *Registry) GetProviderForIntegration(integrationType string) (Provider, error)

GetProviderForIntegration returns the provider that handles the given integration type.

func (*Registry) IsOAuthIntegration

func (r *Registry) IsOAuthIntegration(integrationType string) bool

IsOAuthIntegration returns true if the integration type uses OAuth.

func (*Registry) ListConfiguredProviders

func (r *Registry) ListConfiguredProviders() []string

ListConfiguredProviders returns names of all configured providers.

func (*Registry) ListIntegrations

func (r *Registry) ListIntegrations() []string

ListIntegrations returns all registered integration types.

func (*Registry) Register

func (r *Registry) Register(p Provider)

Register adds a provider to the registry if configured. Automatically registers all integrations the provider supports.

type Session

type Session struct {
	ID              string        `json:"id"`
	State           string        `json:"state"`
	ProviderName    string        `json:"provider"`
	WorkspaceID     uint          `json:"workspace_id_internal"`
	WorkspaceExt    string        `json:"workspace_id"`
	IntegrationType string        `json:"integration_type"`
	Status          SessionStatus `json:"status"`
	Error           string        `json:"error,omitempty"`
	ConnectionID    string        `json:"connection_id,omitempty"`
	ReturnTo        string        `json:"return_to,omitempty"`
	CreatedAt       time.Time     `json:"created_at"`
	ExpiresAt       time.Time     `json:"expires_at"`
}

Session represents an OAuth session in progress.

type SessionStatus

type SessionStatus string
const (
	StatusPending  SessionStatus = "pending"
	StatusComplete SessionStatus = "complete"
	StatusError    SessionStatus = "error"
)

type SlackProvider

type SlackProvider struct {
	// contains filtered or unexported fields
}

SlackProvider handles Slack OAuth operations.

func NewSlackProvider

func NewSlackProvider(creds types.ProviderOAuthCredentials, callbackURL string) *SlackProvider

func (*SlackProvider) AuthorizeURL

func (s *SlackProvider) AuthorizeURL(state, integrationType string) (string, error)

func (*SlackProvider) Exchange

func (s *SlackProvider) Exchange(ctx context.Context, code, integrationType string) (*types.IntegrationCredentials, error)

func (*SlackProvider) Integrations added in v0.1.15

func (s *SlackProvider) Integrations() []string

func (*SlackProvider) IsConfigured

func (s *SlackProvider) IsConfigured() bool

func (*SlackProvider) Name

func (s *SlackProvider) Name() string

func (*SlackProvider) Refresh

func (s *SlackProvider) Refresh(ctx context.Context, refreshToken string) (*types.IntegrationCredentials, error)

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store manages OAuth sessions.

func NewStore

func NewStore(client *common.RedisClient, ttl time.Duration) *Store

NewStore creates a session store. Uses Redis if client is non-nil, otherwise falls back to memory.

func (*Store) Complete

func (s *Store) Complete(id, connectionID string) error

Complete marks a session as successfully completed and schedules cleanup.

func (*Store) Create

func (s *Store) Create(providerName string, workspaceID uint, workspaceExt, integrationType, returnTo string) (*Session, error)

Create creates a new pending OAuth session.

func (*Store) Delete

func (s *Store) Delete(id string) error

Delete removes a session immediately.

func (*Store) Fail

func (s *Store) Fail(id, errMsg string) error

Fail marks a session as failed with an error and schedules cleanup.

func (*Store) Get

func (s *Store) Get(id string) (*Session, error)

Get retrieves a session by ID.

func (*Store) GetByState

func (s *Store) GetByState(state string) (*Session, error)

GetByState retrieves a session by OAuth state parameter.

Jump to

Keyboard shortcuts

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