auth

package
v0.0.0-...-553821e Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APITokenHandler

type APITokenHandler interface {

	// GetAPIToken takes an indent and genereates
	// a unique and secure token which can be used to
	// recover the passed ident from it.
	//
	// Also, an expiration time is returned after which
	// the token will become invalid.
	GetAPIToken(ident string) (token string, expires time.Time, err error)

	// ValidateAPIToken takes a token and validates
	// it. When the token is invalid, an error is returned.
	// Otherwise, the ident is recovered from the token
	// and returned.
	ValidateAPIToken(token string) (ident string, err error)

	// RevokeToken marks the token linked to the passed
	// ident as invalid so it can not be validated
	// anymore.
	RevokeToken(ident string) error
}

APITokenHandler provides functionalities to manage API tokens.

type AccessTokenHandler

type AccessTokenHandler interface {

	// GetAccessToken takes an indent and genereates
	// a unique and secure token which can be used to
	// recover the passed ident from it.
	//
	// Also, an expiration time is returned after which
	// the token will become invalid.
	GetAccessToken(ident string) (token string, expires time.Time, err error)

	// ValidateAccessToken takes a token and validates
	// it. When the token is invalid, an error is returned.
	// Otherwise, the ident is recovered from the token
	// and returned.
	ValidateAccessToken(token string) (ident string, err error)
}

AccessTokenHandler provides functionalities to manage access tokens.

type AccessTokenMiddleware

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

AccessTokenMiddleware implements Middleware for Access and API tokens passed via an Authorization header

func NewAccessTokenMiddleware

func NewAccessTokenMiddleware(container di.Container) *AccessTokenMiddleware

NewAccessTokenMiddleware initializes a new instance of AccessTokenMiddleware.

func (*AccessTokenMiddleware) Handle

func (m *AccessTokenMiddleware) Handle(ctx *fiber.Ctx) (err error)

type DatabaseAPITokenHandler

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

DatabaseAPITokenHandler implements APITokenHandler for a JWT token stored in the database

func NewDatabaseAPITokenHandler

func NewDatabaseAPITokenHandler(container di.Container) (*DatabaseAPITokenHandler, error)

NewDatabaseAPITokenHandler returns a new instance of DatabaseAPITokenHandler

func (*DatabaseAPITokenHandler) GetAPIToken

func (apith *DatabaseAPITokenHandler) GetAPIToken(ident string) (token string, expires time.Time, err error)

func (*DatabaseAPITokenHandler) RevokeToken

func (apith *DatabaseAPITokenHandler) RevokeToken(ident string) error

func (*DatabaseAPITokenHandler) ValidateAPIToken

func (apith *DatabaseAPITokenHandler) ValidateAPIToken(token string) (ident string, err error)

type DatabaseRefreshTokenHandler

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

DatabaseRefreshTokenHandler implements RefreshTokenHandler for a base64 encoded token stored in the database

func NewDatabaseRefreshTokenHandler

func NewDatabaseRefreshTokenHandler(container di.Container) *DatabaseRefreshTokenHandler

NewDatabaseRefreshTokenHandler returns a new instance of DatabaseRefreshTokenHandler

func (*DatabaseRefreshTokenHandler) GetRefreshToken

func (rth *DatabaseRefreshTokenHandler) GetRefreshToken(ident string) (token string, err error)

func (*DatabaseRefreshTokenHandler) RevokeToken

func (rth *DatabaseRefreshTokenHandler) RevokeToken(ident string) error

func (*DatabaseRefreshTokenHandler) ValidateRefreshToken

func (rth *DatabaseRefreshTokenHandler) ValidateRefreshToken(token string) (ident string, err error)

type JWTAccessTokenHandler

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

JWTAccessTokenHandler implements AccessTokenHandler for a JWT based access token

func NewJWTAccessTokenHandler

func NewJWTAccessTokenHandler(container di.Container) (ath *JWTAccessTokenHandler, err error)

NewJWTAccessTokenHandler returns a new instance of JWTAccessTokenHandler

func (*JWTAccessTokenHandler) GetAccessToken

func (ath *JWTAccessTokenHandler) GetAccessToken(ident string) (token string, expires time.Time, err error)

func (*JWTAccessTokenHandler) ValidateAccessToken

func (ath *JWTAccessTokenHandler) ValidateAccessToken(token string) (ident string, err error)

type Middleware

type Middleware interface {
	Handle(ctx *fiber.Ctx) error
}

Middleware provides an authorization fiber middleware

type RefreshTokenHandler

type RefreshTokenHandler interface {

	// GetRefreshToken takes an indent and genereates
	// a unique and secure token which can be used to
	// recover the passed ident from it.
	GetRefreshToken(ident string) (token string, err error)

	// ValidateRefreshToken takes a token and validates
	// it. When the token is invalid, an error is returned.
	// Otherwise, the ident is recovered from the token
	// and returned.
	ValidateRefreshToken(token string) (ident string, err error)

	// RevokeToken marks the token linked to the passed
	// ident as invalid so it can not be validated
	// anymore.
	RevokeToken(ident string) error
}

RefreshTokenHandler provides functionalities to manage refresh tokens.

type RefreshTokenRequestHandler

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

RefreshTokenRequestHandler implements RequestHandler for the refresh-access token authentication system.

func NewRefreshTokenRequestHandler

func NewRefreshTokenRequestHandler(container di.Container) *RefreshTokenRequestHandler

func (*RefreshTokenRequestHandler) BindRefreshToken

func (h *RefreshTokenRequestHandler) BindRefreshToken(ctx *fiber.Ctx, uid string) error

func (*RefreshTokenRequestHandler) LoginFailedHandler

func (h *RefreshTokenRequestHandler) LoginFailedHandler(ctx *fiber.Ctx, status int, msg string) error

func (*RefreshTokenRequestHandler) LoginSuccessHandler

func (h *RefreshTokenRequestHandler) LoginSuccessHandler(ctx *fiber.Ctx, res discordoauth.SuccessResult) error

func (*RefreshTokenRequestHandler) LogoutHandler

func (h *RefreshTokenRequestHandler) LogoutHandler(ctx *fiber.Ctx) error

type RequestHandler

type RequestHandler interface {

	// LoginFailedHandler is called when either the
	// user authentication failed or something went
	// wrong during the authentication process.
	LoginFailedHandler(ctx *fiber.Ctx, status int, msg string) error

	// BindRefreshToken generates a refresh token
	// and binds it as cookie to the passed
	// context.
	BindRefreshToken(ctx *fiber.Ctx, uid string) error

	// LoginSuccessHandler is called when the
	// authentication process was successful.
	//
	// The function is getting passed the ident of
	// the authenticated user.
	LoginSuccessHandler(ctx *fiber.Ctx, res discordoauth.SuccessResult) error

	// LogoutHandler is called when the user
	// wants to log out.
	LogoutHandler(ctx *fiber.Ctx) error
}

RequestHandler provides fiber endpoints and handlers to authenticate users via an OAuth2 interface.

Jump to

Keyboard shortcuts

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