authentication

package
v0.0.0-...-1ba6274 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultProvider = "provider"
)

Variables

View Source
var (
	ErrEmptyArgument      = errors.New("argument can not be empty")
	ErrInvalidProvider    = errors.New("provider is invalid")
	ErrLoggerIsInvalid    = errors.New("provided logger is nil")
	ErrMissingDB          = errors.New("missing database")
	ErrMissingDomain      = errors.New("missing domain")
	ErrMissingProvider    = errors.New("missing provider")
	ErrNotSetup           = errors.New("this function has not been completed")
	ErrSessionsStoreIsNil = errors.New("provided sessions.Store is nil")
	ErrSessionsIsNil      = errors.New("provided Sessions is nil")
)

Functions

func MiddlewareBearerToken

func MiddlewareBearerToken(db DB) echo.MiddlewareFunc

func MiddlewareMustBeAuthenticated

func MiddlewareMustBeAuthenticated(db DB) echo.MiddlewareFunc

func MiddlewareOIDC

func MiddlewareOIDC() echo.MiddlewareFunc

func MiddlewareSessionManager

func MiddlewareSessionManager(session Session, key string) echo.MiddlewareFunc

func New

func New(g *echo.Echo, opts ...Option) error

Types

type DB

type DB interface {
	GetUserWithSession(ctx context.Context, userID string, token string) (user any, err error)               // Get the user with the userID and the active token.
	GetUserID(ctx context.Context, gothID string) (userID string, err error)                                 // GetUserID takes a id from goth and searches for a user in the database. It returns the id of the user
	GetUserIDFromToken(ctx context.Context, apiToken string) (string, error)                                 // Get the user id from the api key
	UpdateUserInfo(ctx context.Context, id string, email string, name string) error                          // Update a user with the given id from the database with the given email and name.
	CreateOrUpdateUser(ctx context.Context, gothID, provider, email, name string) (userID string, err error) // Create or update a user for the given gothID
	UserDisabled(ctx context.Context, userID string) (disabled bool, err error)                              // Check if a user is disabled.
	AddSessionToUser(ctx context.Context, gothID string, session string) error                               // Adds the session to the user with the connected goth id. Returns an error if a user is not connected to the goth id.
}

gothID is for the id of the user from the provider. userID is for the id of the user from the database.

type Log

type Log interface {
	LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr)
}

Log interface that this package uses. By default it is `log/slog`

type Option

type Option interface {
	// contains filtered or unexported methods
}

func SetBackend

func SetBackend(raw string) Option

SetBackend sets the url for the backend to use.

func SetDatabase

func SetDatabase(db DB) Option

SetDatabase sets the database that will be used.

func SetFrontend

func SetFrontend(raw string) Option

SetFrontend sets the url for the frontend to use.

func SetLogger

func SetLogger(logger Log) Option

func SetNames

func SetNames(sesson, provider, refetch, addition string) Option

func SetPaths

func SetPaths(login, logout, profile, err string) Option

func SetSessions

func SetSessions(s Session) Option

func SetStore

func SetStore(store sessions.Store) Option

func WithProvider

func WithProvider(p provider.Provider, key, secret, callbackDomain, source string) Option

WithProvider adds a provider. Source is required for Okta, Nextcloud, and OpenID Providers.

type Options

type Options []Option

type Session

type Session interface {
	GetString(ctx context.Context, key string) string
	Token(context.Context) string
	Destroy(context.Context) error
	Put(ctx context.Context, key string, val any)
	PopBool(ctx context.Context, key string) bool
	RenewToken(context.Context) error
	Commit(context.Context) (token string, expires time.Time, err error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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