jwt

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(secret string) gin.HandlerFunc

AuthMiddleware is a middleware function for Gin that authenticates requests using a JWT token. It checks for a valid "Authorization" header in the Bearer format. If the token is valid, the middleware extracts the user ID from the token's claims and stores it in the request context.

func GenerateToken

func GenerateToken(userID *uuid.UUID, secret string, lifeTime int) (string, error)

GenerateToken creates a signed JWT token for a given user ID with a specified lifetime. The token includes standard claims, such as expiration time, issue time, user ID (as the subject), and a unique token ID. Returns the signed token string or an error if signing fails.

Types

This section is empty.

Jump to

Keyboard shortcuts

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