jwt

package
v0.0.0-...-f767cfc Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package jwt provides functionality for creating and parsing JSON Web Tokens (JWTs) using HMAC-SHA256 for signature validation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHMAC

func NewHMAC[T ClaimsType](secret string, claims T) (token string, err error)

NewHMAC creates and returns a new HMAC-SHA256 signed JWT token. It takes in a secret string and a set of claims of a type that implements the ClaimsType interface. It returns a signed JWT token as a string or an error if the signing process fails.

func ParseHMAC

func ParseHMAC[T ClaimsType, PT ClaimsPointerType[T]](secret string, tokenString string) (T, error)

ParseHMAC parses a given JWT token string and returns a value with the parsed claims or an error. It takes in a secret string, a JWT token string, and two type parameters: T and PT. T is the type of the claims, and PT is a pointer to T and implements the ClaimsType interface. It returns a T value with the parsed claims or an error if the parsing process fails.

Types

type AccessTokenClaims

type AccessTokenClaims struct {
	jwt.RegisteredClaims
	UserID string `json:"user_id"`
}

AccessTokenClaims represents the claims in an access token.

type AccessTokenManagerHMAC

type AccessTokenManagerHMAC struct {
	AccessTokenSecret string
}

AccessTokenManagerHMAC is a struct for managing access tokens using HMAC algorithm.

func NewAccessTokenManagerHMAC

func NewAccessTokenManagerHMAC(accessTokenSecret string) *AccessTokenManagerHMAC

NewAccessTokenManagerHMAC creates and returns a new AccessTokenManagerHMAC with the given access token secret.

func (*AccessTokenManagerHMAC) New

New creates and signs a new access token with the given claims.

func (*AccessTokenManagerHMAC) Parse

Parse parses and validates the signature and claims of an access token.

type ClaimsPointerType

type ClaimsPointerType[T ClaimsType] interface {
	jwt.Claims
	*T
}

ClaimsPointerType is an interface that extends the jwt.Claims interface and also includes a pointer to a ClaimsType. It is used to specify the type of the claims to be used with the JWT.

type ClaimsType

type ClaimsType interface {
	jwt.Claims
}

ClaimsType is an interface that extends the jwt.Claims interface. It is used to specify the type of the claims to be used with the JWT.

type RefreshTokenClaims

type RefreshTokenClaims struct {
	jwt.RegisteredClaims
	UserID string `json:"user_id"`
}

RefreshTokenClaims represents the claims in a refresh token.

type RefreshTokenManagerHMAC

type RefreshTokenManagerHMAC struct {
	RefreshTokenSecret string
}

RefreshTokenManagerHMAC is a struct for managing refresh tokens using HMAC algorithm.

func NewRefreshTokenManagerHMAC

func NewRefreshTokenManagerHMAC(accessTokenSecret string) *RefreshTokenManagerHMAC

NewRefreshTokenManagerHMAC creates and returns a new RefreshTokenManagerHMAC with the given refresh token secret.

func (*RefreshTokenManagerHMAC) New

New creates and signs a new refresh token with the given claims.

func (*RefreshTokenManagerHMAC) Parse

Parse parses and validates the signature and claims of a refresh token.

Jump to

Keyboard shortcuts

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