jwt

package
v0.0.0-...-599305b Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ClaimsKey is the context key for storing JWT claims in the request context.
	ClaimsKey contextKey = "claims"
	// TokenKey is the context key for storing the JWT token in the request context.
	TokenKey contextKey = "token"
)

Variables

This section is empty.

Functions

func GetSubject

func GetSubject(tokenString string) (string, error)

GetSubject extracts the subject (user ID) from a JWT token.

func IsValidJWT

func IsValidJWT(value interface{}) error

IsValidJWT is a custom validator to check if the provided string is a valid JWT token.

Types

type Claims

type Claims struct {
	golangjwt.RegisteredClaims
	Email       string   `json:"email"`
	Roles       []string `json:"roles"`
	Permissions []string `json:"permissions"`
	Type        string   `json:"type"`
}

Add a custom Claims structure to include internal role, external roles, and permissions

func Parse

func Parse(tokenString string, signingKey []byte) (*Claims, error)

Parse function validates and extracts the JWT claims.

type JWTConfig

type JWTConfig struct {
	VerifyIssuer    bool
	Issuer          string
	SigningMethod   golangjwt.SigningMethod
	SigningKey      []byte
	ValidationDelay time.Duration
	Leeway          int64
}

Jump to

Keyboard shortcuts

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