auth

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthSlug   = "google-auth"
	DBAuthSlug = "db-auth"
)

Variables

This section is empty.

Functions

func CheckAuthStatus

func CheckAuthStatus() (bool, error)

CheckAuthStatus checks if a valid token exists

func CreateTokenStoreFromLayers

func CreateTokenStoreFromLayers(parsedLayers *layers.ParsedLayers) (store.TokenStore, error)

CreateTokenStoreFromLayers creates a token store from parsed layers

func CreateTokenStoreFromSettings

func CreateTokenStoreFromSettings(s *AuthSettings, dbs *DBAuthSettings, db interface{}) (store.TokenStore, error)

CreateTokenStoreFromSettings creates a token store from settings

func GetOAuthTokenStoreLayers

func GetOAuthTokenStoreLayers() (*layers.ParameterLayers, error)

GetOAuthTokenStoreLayers returns all layers required for OAuth token store configuration

func NewAuthParameterLayer

func NewAuthParameterLayer() (layers.ParameterLayer, error)

func NewDBAuthParameterLayer

func NewDBAuthParameterLayer() (layers.ParameterLayer, error)

func NewGoogleClient

func NewGoogleClient(ctx context.Context, opts ...Option) (*http.Client, error)

NewGoogleClient creates a new authenticated Google Calendar client

func RemoveToken

func RemoveToken() error

RemoveToken removes the stored token file

Types

type AuthResult

type AuthResult struct {
	Client *oauth2.Config
	Token  *oauth2.Token
}

AuthResult contains the authentication result

type AuthSettings

type AuthSettings struct {
	CredentialsFile string `glazed.parameter:"credentials-file"`
	TokenStoreType  string `glazed.parameter:"token-store-type"`
	TokenStorePath  string `glazed.parameter:"token-store-path"`
	TokenStorePerms int    `glazed.parameter:"token-store-perms"`
	ServerPort      int    `glazed.parameter:"server-port"`
	CallbackPath    string `glazed.parameter:"callback-path"`
	Timeout         int    `glazed.parameter:"timeout"`
}

type Authenticator

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

Authenticator handles OAuth2 authentication flow

func CreateAuthenticatorFromLayers

func CreateAuthenticatorFromLayers(parsedLayers *layers.ParsedLayers) (*Authenticator, error)

CreateAuthenticatorFromLayers creates an authenticator from parsed layers

func NewAuthenticator

func NewAuthenticator(opts ...Option) (*Authenticator, error)

NewAuthenticator creates a new authenticator with the given options

func (*Authenticator) Authenticate

func (a *Authenticator) Authenticate(ctx context.Context) (*AuthResult, error)

Authenticate starts the OAuth2 flow and returns the result

func (*Authenticator) Clear

func (a *Authenticator) Clear(ctx context.Context) error

Clear removes any stored token

type DBAuthSettings

type DBAuthSettings struct {
	UserID    int      `glazed.parameter:"user-id"`
	Provider  string   `glazed.parameter:"provider"`
	Scopes    []string `glazed.parameter:"scopes"`
	TeamID    string   `glazed.parameter:"team-id"`
	UserAppID string   `glazed.parameter:"user-app-id"`
	AppID     string   `glazed.parameter:"app-id"`
}

type Option

type Option func(*config) error

Option is a function that configures the authenticator

func CreateOptionsFromSettings

func CreateOptionsFromSettings(s *AuthSettings) ([]Option, error)

CreateOptionsFromSettings creates authenticator options from AuthSettings

func WithCredentialsFile

func WithCredentialsFile(path string) Option

WithCredentialsFile sets the OAuth2 credentials from a file

func WithCredentialsJSON

func WithCredentialsJSON(json []byte) Option

WithCredentialsJSON sets the OAuth2 credentials from JSON bytes

func WithErrorPage

func WithErrorPage(page []byte) Option

WithErrorPage sets a custom error page

func WithLogger

func WithLogger(logger *zerolog.Logger) Option

WithLogger sets a custom logger

func WithOAuthConfig

func WithOAuthConfig(cfg *oauth2.Config) Option

WithOAuthConfig sets a pre-configured OAuth2 config

func WithScopes

func WithScopes(scopes ...string) Option

WithScopes sets the OAuth2 scopes

func WithServerMode

func WithServerMode(mode server.ServerMode) Option

WithServerMode sets the server mode implementation

func WithSuccessPage

func WithSuccessPage(page []byte) Option

WithSuccessPage sets a custom success page

func WithTimeout

func WithTimeout(duration time.Duration) Option

WithTimeout sets the maximum duration to wait for authentication

func WithTokenStore

func WithTokenStore(store store.TokenStore) Option

WithTokenStore sets the token storage implementation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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