auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter handles authentication operations using bcrypt and JWT

func NewAdapter

func NewAdapter(jwtSecret string) *Adapter

NewAdapter creates a new auth adapter with the given JWT secret

func NewAdapterWithCost

func NewAdapterWithCost(jwtSecret string, bcryptCost int) *Adapter

NewAdapterWithCost creates a new auth adapter with custom bcrypt cost

func (*Adapter) GenerateToken

func (a *Adapter) GenerateToken(claims *domain.TokenClaims) (string, error)

GenerateToken creates a signed JWT from domain claims

func (*Adapter) HashPassword

func (a *Adapter) HashPassword(password string) (string, error)

HashPassword generates a bcrypt hash from a plaintext password

func (*Adapter) ParseToken

func (a *Adapter) ParseToken(tokenString string) (*domain.TokenClaims, error)

ParseToken validates a JWT and extracts domain claims

func (*Adapter) VerifyPassword

func (a *Adapter) VerifyPassword(password, hash string) bool

VerifyPassword checks if a password matches a bcrypt hash

type OAuthTokenProvider

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

OAuthTokenProvider implements TokenProvider for OAuth2 credentials. It automatically refreshes tokens when they expire.

func NewOAuthTokenProvider

func NewOAuthTokenProvider(
	connectionID string,
	accessToken string,
	refreshToken string,
	expiry *time.Time,
	refresher TokenRefresherFunc,
	connectionStore driven.ConnectionStore,
) *OAuthTokenProvider

NewOAuthTokenProvider creates a token provider for OAuth credentials.

func (*OAuthTokenProvider) AuthMethod

func (p *OAuthTokenProvider) AuthMethod() domain.AuthMethod

AuthMethod returns OAuth2.

func (*OAuthTokenProvider) GetAccessToken

func (p *OAuthTokenProvider) GetAccessToken(ctx context.Context) (string, error)

GetAccessToken returns a valid access token, refreshing if needed.

func (*OAuthTokenProvider) GetCredentials

func (p *OAuthTokenProvider) GetCredentials(ctx context.Context) (*domain.Credentials, error)

GetCredentials returns credentials for OAuth.

func (*OAuthTokenProvider) IsValid

func (p *OAuthTokenProvider) IsValid(ctx context.Context) bool

IsValid checks if credentials are valid (not expired or can be refreshed).

type StaticTokenProvider

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

StaticTokenProvider implements TokenProvider for non-OAuth credentials. Used for API keys, PATs, and service accounts.

func NewStaticTokenProvider

func NewStaticTokenProvider(token string, authMethod domain.AuthMethod) *StaticTokenProvider

NewStaticTokenProvider creates a token provider for static credentials.

func (*StaticTokenProvider) AuthMethod

func (p *StaticTokenProvider) AuthMethod() domain.AuthMethod

AuthMethod returns the authentication method.

func (*StaticTokenProvider) GetAccessToken

func (p *StaticTokenProvider) GetAccessToken(ctx context.Context) (string, error)

GetAccessToken returns the static token.

func (*StaticTokenProvider) GetCredentials

func (p *StaticTokenProvider) GetCredentials(ctx context.Context) (*domain.Credentials, error)

GetCredentials returns nil for static tokens - use GetAccessToken instead.

func (*StaticTokenProvider) IsValid

func (p *StaticTokenProvider) IsValid(ctx context.Context) bool

IsValid returns true - static credentials don't expire.

type TokenProviderFactory

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

TokenProviderFactory creates TokenProviders from connection credentials.

func NewTokenProviderFactory

func NewTokenProviderFactory(
	connectionStore driven.ConnectionStore,
) *TokenProviderFactory

NewTokenProviderFactory creates a new TokenProviderFactory.

func (*TokenProviderFactory) Create

func (f *TokenProviderFactory) Create(ctx context.Context, connectionID string) (driven.TokenProvider, error)

Create creates a TokenProvider for a connection. It looks up the connection by ID, decrypts credentials, and creates an appropriate TokenProvider based on the auth method.

func (*TokenProviderFactory) CreateFromConnection

func (f *TokenProviderFactory) CreateFromConnection(ctx context.Context, conn *domain.Connection) (driven.TokenProvider, error)

CreateFromConnection creates a TokenProvider from a connection directly. Use this when you already have the connection loaded.

func (*TokenProviderFactory) RegisterRefresher

func (f *TokenProviderFactory) RegisterRefresher(
	providerType domain.ProviderType,
	refresher TokenRefresherFunc,
)

RegisterRefresher registers a token refresh function for a provider type.

type TokenRefresherFunc

type TokenRefresherFunc func(ctx context.Context, refreshToken string) (*driven.OAuthToken, error)

TokenRefresherFunc is a function type for token refresh operations.

Jump to

Keyboard shortcuts

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