jwt

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// matches the access enum (TOKEN) from the db
	ACCESS_TOKEN_DB_ENUM = "access"
	// matches the refresh enum (TOKEN) from the db
	REFRESH_TOKEN_DB_ENUM = "refresh"
)

Variables

This section is empty.

Functions

func GenerateAccessToken

func GenerateAccessToken(tx *sql.Tx, uid string) (string, error)

GenerateAccessToken generates an access token. Access tokens have 10 minutes of lifespan. This uses a transaction to insert the generated token in the database so that validation and invalidation can take place.

You must call tx.Commit for the changes to take effect and the token to be valid.

func GenerateRefreshToken

func GenerateRefreshToken(tx *sql.Tx, uid string) (string, error)

GenerateRefreshToken generates a refresh token. Refresh tokens have 1 week of lifepspan. This uses a transaction to insert the generated token in the database so that validation and invalidation can take place.

You must call tx.Commit for the changes to take effect and the token to be valid.

Types

type JwtClaims

type JwtClaims struct {
	// UserId for easy identification of the user
	UserId string `json:"user_id"`
	// TokenType for a way to differentiate access and refresh tokens
	TokenType string `json:"token_type"`
	// jwt.RegisteredClaims are the default normal claims that a jwt should have
	jwt.RegisteredClaims
}

JwtClaims represents the body of jwt tokens generated when a user signins.

func VerifyAccessToken

func VerifyAccessToken(token string) (*JwtClaims, error)

VerifyAccessToken verifies the given access token.

func VerifyRefreshToken

func VerifyRefreshToken(token string) (*JwtClaims, error)

VerifyRefreshToken verifies the given refresh token.

Jump to

Keyboard shortcuts

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