middleware

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: GPL-3.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoIDTokenFound = fmt.Errorf("IDToken not found in context key %s", userContextField)

Functions

func BodyDumpOnHeader

func BodyDumpOnHeader() echo.MiddlewareFunc

func DefaultLogger

func DefaultLogger(level zerolog.Level) echo.MiddlewareFunc

Logger will inject in context a default zerolog logger with all available contextual info. Default logger is a pretty logger with info level and timestamp functionality.

func DefaultRequestZeroLoggerConfig

func DefaultRequestZeroLoggerConfig() echo.MiddlewareFunc

func GetIDToken added in v0.0.10

func GetIDToken(c echo.Context) (*auth.Token, error)

GetIDToken extract the token from the context field in userContextField and return it. If no token is found, it returns a ErrNoIDTokenFound.

func GetLogger

func GetLogger(c echo.Context) zerolog.Logger

GetLogger returns the contextual logger from context

func LoggedUserIs added in v0.0.12

func LoggedUserIs(c echo.Context, rol string) bool

LoggedUserIs returns true if a idToken exists in the context and it have the desired rol.

func LoggedUserIsAny added in v0.0.12

func LoggedUserIsAny(c echo.Context, roles []string) bool

LoggedUserIsAny returns true if a idToken exists in the context and it have, at least, one of the expecified roles.

func RequestID

func RequestID(c echo.Context) string

func SetLogger

func SetLogger(c echo.Context, logger zerolog.Logger)

SetLogger overrides the contextual logger in the echo context.

Types

type AuthClient added in v0.0.12

type AuthClient interface {
	VerifyIDToken(ctx context.Context, idToken string) (*auth.Token, error)
}

type AuthMiddleware added in v0.0.10

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

func DefaultAuthMiddleware added in v0.0.12

func DefaultAuthMiddleware() *AuthMiddleware

DefaultAuthMiddleware returns the auth middleware with a firebase auth client initialized from env vars.

func NewAuthMiddleware added in v0.0.10

func NewAuthMiddleware(ctx context.Context, authClient AuthClient) *AuthMiddleware

NewAuthMiddleware return a new auth middleware with the desired authClient attached.

func (*AuthMiddleware) AllowAnonymous added in v0.0.10

func (a *AuthMiddleware) AllowAnonymous() echo.MiddlewareFunc

AllowAnonymous will let pass all petitions trying to find a JWT in headers and loging in the user if the JWT is found.

func (*AuthMiddleware) LoggedUser added in v0.0.10

func (a *AuthMiddleware) LoggedUser() echo.MiddlewareFunc

LoggedUsers searchs for a valid JWT and logs in the founded user. If no JWT is found, it returns a 401 unauthorized standar error, stopping the request.

func (*AuthMiddleware) WithAny added in v0.0.12

func (a *AuthMiddleware) WithAny(roles []string) echo.MiddlewareFunc

WhitAny searchs for a valid JWT with at least one of the desired roles as a boolean true key in the token Claims and logs in the founded user. If no JWT with one desired rol is found, it returns a 401 or 403 standard error, stopping the request.

func (*AuthMiddleware) WithRol added in v0.0.10

func (a *AuthMiddleware) WithRol(rol string) echo.MiddlewareFunc

WithRol searchs for a valid JWT with the desired rol as a boolean true key in the token Claims and logs in the founded user. If no JWT with the rol is found, it returns a 401 or 403 standard error, stopping the request.

Jump to

Keyboard shortcuts

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