oauth

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsGoogleIntegration

func IsGoogleIntegration(integrationType string) bool

IsGoogleIntegration returns true if the integration uses Google OAuth Deprecated: Use Registry.IsOAuthIntegration instead

func NeedsRefresh

func NeedsRefresh(creds *types.IntegrationCredentials) bool

NeedsRefresh returns true if credentials are expired or about to expire

Types

type GitHubProvider

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

GitHubProvider handles GitHub OAuth operations for workspace integrations Implements the Provider interface

func NewGitHubProvider

func NewGitHubProvider(cfg types.IntegrationGitHubOAuth) *GitHubProvider

NewGitHubProvider creates a new GitHub OAuth provider from config

func (*GitHubProvider) AuthorizeURL

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

AuthorizeURL generates the GitHub OAuth authorization URL for an integration

func (*GitHubProvider) Exchange

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

Exchange exchanges an authorization code for tokens

func (*GitHubProvider) IsConfigured

func (g *GitHubProvider) IsConfigured() bool

IsConfigured returns true if GitHub OAuth is configured

func (*GitHubProvider) Name

func (g *GitHubProvider) Name() string

Name returns the provider name

func (*GitHubProvider) Refresh

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

Refresh refreshes an access token using a refresh token Note: GitHub personal access tokens don't expire, but GitHub Apps use refresh tokens

func (*GitHubProvider) SupportsIntegration

func (g *GitHubProvider) SupportsIntegration(integrationType string) bool

SupportsIntegration returns true if this provider handles the given integration type

type GoogleProvider

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

GoogleProvider handles Google OAuth operations for workspace integrations Implements the Provider interface

func NewGoogleClient

func NewGoogleClient(cfg types.IntegrationGoogleOAuth) *GoogleProvider

NewGoogleClient creates a new Google OAuth client from config Deprecated: Use NewGoogleProvider instead

func NewGoogleProvider

func NewGoogleProvider(cfg types.IntegrationGoogleOAuth) *GoogleProvider

NewGoogleProvider creates a new Google OAuth provider from config

func (*GoogleProvider) AuthorizeURL

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

AuthorizeURL generates the Google OAuth authorization URL for an integration

func (*GoogleProvider) Exchange

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

Exchange exchanges an authorization code for tokens

func (*GoogleProvider) IsConfigured

func (g *GoogleProvider) IsConfigured() bool

IsConfigured returns true if Google OAuth is configured

func (*GoogleProvider) Name

func (g *GoogleProvider) Name() string

Name returns the provider name

func (*GoogleProvider) Refresh

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

Refresh refreshes an access token using a refresh token

func (*GoogleProvider) SupportsIntegration

func (g *GoogleProvider) SupportsIntegration(integrationType string) bool

SupportsIntegration returns true if this provider handles the given integration type

type NotionProvider

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

NotionProvider handles Notion OAuth operations for workspace integrations Implements the Provider interface

func NewNotionProvider

func NewNotionProvider(cfg types.IntegrationNotionOAuth) *NotionProvider

NewNotionProvider creates a new Notion OAuth provider from config

func (*NotionProvider) AuthorizeURL

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

AuthorizeURL generates the Notion OAuth authorization URL for an integration

func (*NotionProvider) Exchange

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

Exchange exchanges an authorization code for tokens

func (*NotionProvider) IsConfigured

func (n *NotionProvider) IsConfigured() bool

IsConfigured returns true if Notion OAuth is configured

func (*NotionProvider) Name

func (n *NotionProvider) Name() string

Name returns the provider name

func (*NotionProvider) Refresh

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

Refresh refreshes an access token using a refresh token Note: Notion tokens don't expire and don't have refresh tokens

func (*NotionProvider) SupportsIntegration

func (n *NotionProvider) SupportsIntegration(integrationType string) bool

SupportsIntegration returns true if this provider handles the given integration type

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

	// SupportsIntegration returns true if this provider handles the given integration type
	SupportsIntegration(integrationType string) bool

	// 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, bool)

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

func (*Registry) RegisterIntegration

func (r *Registry) RegisterIntegration(integrationType, providerName string)

RegisterIntegration maps an integration type to a provider

type Session

type Session struct {
	ID              string        `json:"id"`
	State           string        `json:"state"` // Used in OAuth state param, maps back to session
	WorkspaceID     uint          `json:"-"`     // Internal workspace ID
	WorkspaceExt    string        `json:"workspace_id"`
	IntegrationType string        `json:"integration_type"` // gmail, gdrive
	Status          SessionStatus `json:"status"`
	Error           string        `json:"error,omitempty"`
	ConnectionID    string        `json:"connection_id,omitempty"` // Set on success
	ReturnTo        string        `json:"-"`                       // Optional redirect after callback
	CreatedAt       time.Time     `json:"created_at"`
	ExpiresAt       time.Time     `json:"expires_at"`
}

Session represents an OAuth session in progress

type SessionStatus

type SessionStatus string

SessionStatus represents the state of an OAuth session

const (
	StatusPending  SessionStatus = "pending"
	StatusComplete SessionStatus = "complete"
	StatusError    SessionStatus = "error"

	// DefaultSessionTTL is how long sessions live before cleanup
	DefaultSessionTTL = 10 * time.Minute
)

type SlackProvider

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

SlackProvider handles Slack OAuth operations for workspace integrations Implements the Provider interface

func NewSlackProvider

func NewSlackProvider(cfg types.IntegrationSlackOAuth) *SlackProvider

NewSlackProvider creates a new Slack OAuth provider from config

func (*SlackProvider) AuthorizeURL

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

AuthorizeURL generates the Slack OAuth authorization URL for an integration

func (*SlackProvider) Exchange

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

Exchange exchanges an authorization code for tokens

func (*SlackProvider) IsConfigured

func (s *SlackProvider) IsConfigured() bool

IsConfigured returns true if Slack OAuth is configured

func (*SlackProvider) Name

func (s *SlackProvider) Name() string

Name returns the provider name

func (*SlackProvider) Refresh

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

Refresh refreshes an access token using a refresh token Note: Slack user tokens don't typically expire

func (*SlackProvider) SupportsIntegration

func (s *SlackProvider) SupportsIntegration(integrationType string) bool

SupportsIntegration returns true if this provider handles the given integration type

type Store

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

Store manages OAuth sessions in memory with TTL cleanup

func NewStore

func NewStore(ttl time.Duration) *Store

NewStore creates a new session store with cleanup goroutine

func (*Store) Complete

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

Complete marks a session as successfully completed

func (*Store) Create

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

Create creates a new pending OAuth session

func (*Store) Delete

func (s *Store) Delete(id string)

Delete removes a session

func (*Store) Fail

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

Fail marks a session as failed with an error

func (*Store) Get

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

Get retrieves a session by ID

func (*Store) GetByState

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

GetByState retrieves a session by OAuth state parameter

func (*Store) Stop

func (s *Store) Stop()

Stop stops the cleanup goroutine

Jump to

Keyboard shortcuts

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