Documentation ¶
Index ¶
- Variables
- func BodyDumpOnHeader() echo.MiddlewareFunc
- func DefaultLogger(level zerolog.Level) echo.MiddlewareFunc
- func DefaultRequestZeroLoggerConfig() echo.MiddlewareFunc
- func GetIDToken(c echo.Context) (*auth.Token, error)
- func GetLogger(c echo.Context) zerolog.Logger
- func LoggedUserIs(c echo.Context, rol string) bool
- func LoggedUserIsAny(c echo.Context, roles []string) bool
- func RequestID(c echo.Context) string
- func SetLogger(c echo.Context, logger zerolog.Logger)
- type AuthClient
- type AuthMiddleware
Constants ¶
This section is empty.
Variables ¶
var ErrNoIDTokenFound = fmt.Errorf("IDToken not found in context key %s", userContextField)
Functions ¶
func BodyDumpOnHeader ¶
func BodyDumpOnHeader() echo.MiddlewareFunc
func DefaultLogger ¶
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
GetIDToken extract the token from the context field in userContextField and return it. If no token is found, it returns a ErrNoIDTokenFound.
func LoggedUserIs ¶ added in v0.0.12
LoggedUserIs returns true if a idToken exists in the context and it have the desired rol.
func LoggedUserIsAny ¶ added in v0.0.12
LoggedUserIsAny returns true if a idToken exists in the context and it have, at least, one of the expecified roles.
Types ¶
type AuthClient ¶ added in v0.0.12
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.