mw

package
v0.0.0-...-d26b62e Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const CSRFCookieName = "xcsrf"
View Source
const IdentityCookieKey = "RYL_Session"

Variables

This section is empty.

Functions

func ExtractFromCookie

func ExtractFromCookie(r *http.Request) (string, error)

ExtractFromCookie extracts a jwt from the session Cookie

func GetJWTMW

func GetJWTMW() *jwtMW.JWTMiddleware

func GetKeyGetter

func GetKeyGetter(key string) jwt.Keyfunc

func OptionalAuth

func OptionalAuth(f func(w http.ResponseWriter, r *http.Request)) http.Handler

func RequireAuth

func RequireAuth(f func(http.ResponseWriter, *http.Request)) http.Handler

func ValidateCSRF

func ValidateCSRF(res *http.Request) error

ValidateCSRF compares the two csrf tokens for a double submit cookie csrf protection.

func ValidateJwt

func ValidateJwt(bearer, key string) (jwt.MapClaims, error)

Types

type AuthMWHandler

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

func NewAuthMWHandler

func NewAuthMWHandler(logger *zap.SugaredLogger, key string) *AuthMWHandler

NewAuthMWHandler creates a new AuthMWR Handler

func (*AuthMWHandler) AuthMWO

func (h *AuthMWHandler) AuthMWO(next http.Handler) http.Handler

AuthMWO is the auth middleware for a optional authenticated request.

func (*AuthMWHandler) AuthMWR

func (h *AuthMWHandler) AuthMWR(next http.Handler) http.Handler

AuthMWR is the auth middleware for a required authenticated request.

func (*AuthMWHandler) RequireAuthTokenHandler

func (h *AuthMWHandler) RequireAuthTokenHandler(rw http.ResponseWriter, r *http.Request) (jwt.MapClaims, error)

type InvalidTokenError

type InvalidTokenError struct {
	Err error
}

func (InvalidTokenError) Error

func (err InvalidTokenError) Error() string

type KeyJWTClaims

type KeyJWTClaims struct{}

type KeyUserId

type KeyUserId struct{}

type Logger

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

Logger is a Middleware for logging using the zap logger

func NewLogger

func NewLogger(zap *zap.Logger) *Logger

NewLogger creates a new zap logging middleware

func (*Logger) ServeHTTP

func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

ServeHTTP is the middleware handler for the logging middleware.

type UnauthorizedError

type UnauthorizedError struct {
	Err error
}

func (UnauthorizedError) Error

func (err UnauthorizedError) Error() string

type UserClaims

type UserClaims struct {
	Username string
	ID       string
	Name     string
}

func FromUserTokenContext

func FromUserTokenContext(user interface{}) *UserClaims

FromUserTokenContext creates a claims list of a user from a given jwt token given by the mw. We trust the user parameter to be a valid jwt token with the claims username and id.

Jump to

Keyboard shortcuts

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