auth

package
v0.0.0-...-f8e9dc7 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Bearer = "Bearer"

Variables

View Source
var (
	ClaimsContext contextkey.Key[*Claims] = "claims"

	LoggerContext contextkey.Key[*slog.Logger] = "logger"
)
View Source
var (
	ErrClaimsInvalid = errors.New("auth: invalid claims")
	ErrTokenInvalid  = errors.New("auth: invalid token")
)

Functions

func BasicHandler

func BasicHandler(h http.Handler, credentials map[string]string) http.Handler

func BearerAuth

func BearerAuth(r *http.Request) (string, bool)

func BearerHandler

func BearerHandler(h http.Handler, secret []byte) http.Handler

func RequireBearerHandler

func RequireBearerHandler(h http.Handler) http.Handler

Types

type Claims

type Claims = jwt.RegisteredClaims

type JWT

type JWT struct {
	Secret []byte
}

func NewJWT

func NewJWT(secret []byte) *JWT

func (*JWT) Sign

func (j *JWT) Sign(claims Claims, ttl time.Duration) (string, error)

func (*JWT) Verify

func (j *JWT) Verify(bearerToken string) (*Claims, error)

Jump to

Keyboard shortcuts

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