auth

package
v0.0.0-...-b8e807e Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppProvider

type AppProvider struct {
	BaseAuthProvider
	// contains filtered or unexported fields
}

AppProvider provides authentication using a GitHub App

func NewAppProvider

func NewAppProvider(appID, privateKeyPEM, installationID string, logger observability.Logger) (*AppProvider, error)

NewAppProvider creates a new provider with GitHub App authentication

func (*AppProvider) AuthenticateRequest

func (p *AppProvider) AuthenticateRequest(req *http.Request) error

AuthenticateRequest authenticates an HTTP request with the app token

func (*AppProvider) GetToken

func (p *AppProvider) GetToken(ctx context.Context) (string, error)

GetToken returns a valid installation token

func (*AppProvider) IsValid

func (p *AppProvider) IsValid() bool

IsValid checks if the app authentication is valid

func (*AppProvider) RefreshToken

func (p *AppProvider) RefreshToken(ctx context.Context) error

RefreshToken obtains a new installation token

func (*AppProvider) SetAuthHeaders

func (p *AppProvider) SetAuthHeaders(req *http.Request) error

SetAuthHeaders sets the app authentication headers

type AuthProvider

type AuthProvider interface {
	// Type returns the authentication type
	Type() AuthType

	// GetToken returns a valid authentication token
	GetToken(ctx context.Context) (string, error)

	// SetAuthHeaders sets the authentication headers on an HTTP request
	SetAuthHeaders(req *http.Request) error

	// AuthenticateRequest authenticates an HTTP request with the appropriate credentials
	AuthenticateRequest(req *http.Request) error

	// RefreshToken refreshes the authentication token if needed
	RefreshToken(ctx context.Context) error

	// IsValid checks if the authentication is valid
	IsValid() bool
}

AuthProvider defines the interface for GitHub authentication providers

func GetAuthProviderFromContext

func GetAuthProviderFromContext(ctx context.Context, fallback AuthProvider, logger observability.Logger) AuthProvider

GetAuthProviderFromContext creates an auth provider from context if passthrough token exists Priority: 1) User credentials from database, 2) Passthrough token, 3) Service account fallback

func NewAuthProvider

func NewAuthProvider(config *Config, logger observability.Logger) (AuthProvider, error)

NewAuthProvider creates a new authentication provider based on configuration

type AuthProviderFactory

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

AuthProviderFactory creates authentication providers

func NewAuthProviderFactory

func NewAuthProviderFactory(configs map[string]*Config, logger observability.Logger) *AuthProviderFactory

NewAuthProviderFactory creates a new authentication provider factory

func (*AuthProviderFactory) AddConfig

func (f *AuthProviderFactory) AddConfig(name string, config *Config)

AddConfig adds a new authentication configuration

func (*AuthProviderFactory) GetProvider

func (f *AuthProviderFactory) GetProvider(name string) (AuthProvider, error)

GetProvider gets or creates an authentication provider

func (*AuthProviderFactory) RemoveConfig

func (f *AuthProviderFactory) RemoveConfig(name string)

RemoveConfig removes an authentication configuration

type AuthType

type AuthType string

AuthType defines the type of authentication

const (
	// AuthTypeNone represents no authentication
	AuthTypeNone AuthType = "none"

	// AuthTypeToken represents personal access token authentication
	AuthTypeToken AuthType = "token"

	// AuthTypeApp represents GitHub App authentication
	AuthTypeApp AuthType = "app"

	// AuthTypeOAuth represents OAuth token authentication
	AuthTypeOAuth AuthType = "oauth"
)

type BaseAuthProvider

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

BaseAuthProvider provides base functionality for authentication providers

func (*BaseAuthProvider) Type

func (p *BaseAuthProvider) Type() AuthType

Type returns the authentication type

type Config

type Config struct {
	// Personal Access Token
	Token string

	// GitHub App
	AppID             string
	AppPrivateKey     string
	AppInstallationID string

	// OAuth
	OAuthToken        string
	OAuthClientID     string
	OAuthClientSecret string
}

Config holds authentication configuration

type NoAuthProvider

type NoAuthProvider struct {
	BaseAuthProvider
}

NoAuthProvider provides no authentication

func NewNoAuthProvider

func NewNoAuthProvider(logger observability.Logger) *NoAuthProvider

NewNoAuthProvider creates a new provider with no authentication

func (*NoAuthProvider) AuthenticateRequest

func (p *NoAuthProvider) AuthenticateRequest(req *http.Request) error

AuthenticateRequest does nothing for no authentication

func (*NoAuthProvider) GetToken

func (p *NoAuthProvider) GetToken(ctx context.Context) (string, error)

GetToken returns an empty token

func (*NoAuthProvider) IsValid

func (p *NoAuthProvider) IsValid() bool

IsValid returns false for no authentication

func (*NoAuthProvider) RefreshToken

func (p *NoAuthProvider) RefreshToken(ctx context.Context) error

RefreshToken does nothing for no authentication

func (*NoAuthProvider) SetAuthHeaders

func (p *NoAuthProvider) SetAuthHeaders(req *http.Request) error

SetAuthHeaders does nothing for no authentication

type OAuthProvider

type OAuthProvider struct {
	BaseAuthProvider
	// contains filtered or unexported fields
}

OAuthProvider provides authentication using OAuth tokens

func NewOAuthProvider

func NewOAuthProvider(token, clientID, clientSecret string, logger observability.Logger) *OAuthProvider

NewOAuthProvider creates a new provider with OAuth authentication

func (*OAuthProvider) AuthenticateRequest

func (p *OAuthProvider) AuthenticateRequest(req *http.Request) error

AuthenticateRequest authenticates an HTTP request with the OAuth token

func (*OAuthProvider) GetToken

func (p *OAuthProvider) GetToken(ctx context.Context) (string, error)

GetToken returns the OAuth token

func (*OAuthProvider) IsValid

func (p *OAuthProvider) IsValid() bool

IsValid checks if the OAuth authentication is valid

func (*OAuthProvider) RefreshToken

func (p *OAuthProvider) RefreshToken(ctx context.Context) error

RefreshToken refreshes the OAuth token if possible

func (*OAuthProvider) SetAuthHeaders

func (p *OAuthProvider) SetAuthHeaders(req *http.Request) error

SetAuthHeaders sets the OAuth authentication header

type PassthroughProvider

type PassthroughProvider struct {
	BaseAuthProvider
	// contains filtered or unexported fields
}

PassthroughProvider provides authentication using a token passed through from a gateway

func NewPassthroughProvider

func NewPassthroughProvider(token string, logger observability.Logger) *PassthroughProvider

NewPassthroughProvider creates a new passthrough authentication provider

func (*PassthroughProvider) AuthenticateRequest

func (p *PassthroughProvider) AuthenticateRequest(req *http.Request) error

AuthenticateRequest authenticates an HTTP request with the passthrough token

func (*PassthroughProvider) GetToken

func (p *PassthroughProvider) GetToken(ctx context.Context) (string, error)

GetToken returns the passthrough token

func (*PassthroughProvider) IsValid

func (p *PassthroughProvider) IsValid() bool

IsValid checks if the passthrough token is available

func (*PassthroughProvider) RefreshToken

func (p *PassthroughProvider) RefreshToken(ctx context.Context) error

RefreshToken is a no-op for passthrough tokens

func (*PassthroughProvider) SetAuthHeaders

func (p *PassthroughProvider) SetAuthHeaders(req *http.Request) error

SetAuthHeaders sets the authentication headers on an HTTP request

type TokenProvider

type TokenProvider struct {
	BaseAuthProvider
	// contains filtered or unexported fields
}

TokenProvider provides authentication using a personal access token

func NewTokenProvider

func NewTokenProvider(token string, logger observability.Logger) *TokenProvider

NewTokenProvider creates a new provider with token authentication

func (*TokenProvider) AuthenticateRequest

func (p *TokenProvider) AuthenticateRequest(req *http.Request) error

AuthenticateRequest authenticates an HTTP request with the token

func (*TokenProvider) GetToken

func (p *TokenProvider) GetToken(ctx context.Context) (string, error)

GetToken returns the token

func (*TokenProvider) IsValid

func (p *TokenProvider) IsValid() bool

IsValid checks if the token is non-empty

func (*TokenProvider) RefreshToken

func (p *TokenProvider) RefreshToken(ctx context.Context) error

RefreshToken does nothing for token authentication

func (*TokenProvider) SetAuthHeaders

func (p *TokenProvider) SetAuthHeaders(req *http.Request) error

SetAuthHeaders sets the token authentication header

Jump to

Keyboard shortcuts

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