jwtx

package
v0.0.0-...-3414fa2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleAdmin = "admin"
	RoleUser  = "user"
)

Variables

This section is empty.

Functions

func GetToken

func GetToken(secretKey string, iat, seconds, userId int64, role string) (string, error)

Types

type ClaimKey

type ClaimKey string

ClaimKey defines custom type for JWT claim keys

const (
	KeyUserId ClaimKey = "userId"
	KeyRole   ClaimKey = "role"
	KeyExp    ClaimKey = "exp"
	KeyIat    ClaimKey = "iat"
)

Define claim keys as constants

type CustomClaims

type CustomClaims struct {
	UserID int64  `json:"userId"`
	Role   string `json:"role"`
	jwt.RegisteredClaims
}

CustomClaims holds JWT claims

func ParseToken

func ParseToken(tokenString string, secretKey string) (*CustomClaims, error)

ParseToken parses and validates JWT token

Jump to

Keyboard shortcuts

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