jwt

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package jwt defines all the methods for JWT manipulation.

Index

Constants

View Source
const ExpiresDuration = 24 * time.Hour

ExpiresDuration is the duration when a user session expires.

View Source
const (
	// TokenCookieKey is the key of the cookie stored in the context.
	TokenCookieKey = "session_token"
)

Variables

This section is empty.

Functions

func Deny added in v1.6.0

func Deny(next http.Handler) http.Handler

Deny is an authentication guard for HTTP servers.

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims
	Provider    string                `json:"provider"`
	Credentials []webauthn.Credential `json:"credentials"`
}

Claims are the fields stored in a JWT.

func GetClaimsFromRequest added in v1.6.0

func GetClaimsFromRequest(r *http.Request) (claims Claims, ok bool)

GetClaimsFromRequest is a helper function to fetch the JWT session token from an HTTP request.

type Option added in v1.5.0

type Option func(*Options)

Option is an option for JWT.

func WithCredentials added in v1.5.0

func WithCredentials(credentials []webauthn.Credential) Option

WithCredentials exports Webauthn credentials in the JWT.

type Options added in v1.5.0

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

Options is the struct storing the options for JWT.

type Secret added in v1.4.1

type Secret []byte

Secret is a HMAC JWT secret used for signing.

func (Secret) GenerateToken added in v1.4.1

func (s Secret) GenerateToken(
	userID string,
	userName string,
	provider string,
	options ...Option,
) (string, error)

GenerateToken creates a JWT session token which stores the user identity.

The returned token is signed with the JWT secret, meaning it cannot be falsified.

func (Secret) Middleware added in v1.6.0

func (s Secret) Middleware(next http.Handler) http.Handler

Middleware is a middleware that inject the JWT in the context for HTTP servers.

func (Secret) VerifyToken added in v1.4.1

func (s Secret) VerifyToken(tokenString string) (*Claims, error)

VerifyToken checks if the token signature is valid compared to the JWT secret.

Jump to

Keyboard shortcuts

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