jwt

package
v0.0.0-...-cba693c Latest Latest
Warning

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

Go to latest
Published: May 30, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenCtxKey       = &contextKey{"Token"}
	ErrorCtxKey       = &contextKey{"Error"}
	CurrentUserCtxKey = &contextKey{"CurrentUser"}
)
View Source
var ErrNoTokenFound = errors.New("no token found")

Functions

func Authenticator

func Authenticator(tv TokenVerifier, up UserProvider, logger *slog.Logger) func(http.Handler) http.Handler

Authenticator http middleware handler will verify a JWT string from a http request.

Authenticator will search for a JWT token in a http request, in the order:

  1. 'Authorization: BEARER T' request header
  2. Cookie 'jwt' value

The first JWT string that is found as a query parameter, authorization header or cookie header is then decoded by the `jwt-go` library and a *jwt.Token object is set on the request context. In the case of a signature decoding error the Authenticator will also set the error on the request context.

Types

type TokenVerifier

type TokenVerifier interface {
	VerifyTokenStringWithES256(tokenString string) (*serviceJwt.Token, error)
}

type UserProvider

type UserProvider interface {
	FindById(id int64) (*entity.User, error)
}

Jump to

Keyboard shortcuts

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