token

package
v0.0.0-...-a2066d2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Unlicense Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractToken

func ExtractToken(c *gin.Context) (string, error)

Extracts Token from query or "Authorization" request header

func ParseWithClaims

func ParseWithClaims(token string, claims jwt.Claims, secret string) (*jwt.Token, error)

While parsing checks if token is valid by checking its sign method and signature signature is token specific secret key

Types

type AccessToken

type AccessToken struct {
	jwt.RegisteredClaims
	UserId int64    `json:"user_id"`
	Roles  []string `json:"roles"`
}

func AccessFromString

func AccessFromString(token string, secret string) (*AccessToken, error)

Parses token from token string

func NewAccess

func NewAccess(userId int64, roles []string, expiresAt time.Time) *AccessToken

func (*AccessToken) TokenString

func (c *AccessToken) TokenString(secret string) (string, error)

Encodes RefreshToken model into a JWT string

type RefreshToken

type RefreshToken struct {
	jwt.RegisteredClaims
	TokenID  int64    `json:"token_id"`
	DeviceID uint     `json:"device_id"`
	UserID   int64    `json:"user_id"`
	Roles    []string `json:"roles"`
}

func NewRefresh

func NewRefresh(tokenId int64, deviceId uint, userId int64, roles []string, expiresAt time.Time) *RefreshToken

func RefreshFromString

func RefreshFromString(token string, secret string) (*RefreshToken, error)

Parses token from token string

func (*RefreshToken) Exists

func (t *RefreshToken) Exists(db *sql.DB) (bool, error)

func (*RefreshToken) FindID

func (t *RefreshToken) FindID(db *sql.DB) (int64, bool, error)

func (*RefreshToken) InsertOrUpdate

func (t *RefreshToken) InsertOrUpdate(db *sql.DB) (int64, error)

func (*RefreshToken) InsertToDb

func (t *RefreshToken) InsertToDb(db *sql.DB) (int64, error)

Inserts row that identifies token into the database (not token string)

func (*RefreshToken) TokenString

func (c *RefreshToken) TokenString(secret string) (string, error)

Encodes RefreshToken model into a JWT string

func (*RefreshToken) Update

func (t *RefreshToken) Update(db *sql.DB, expiresAt uint64) (*RefreshToken, error)

Updates expiredAt field of token in the database

Jump to

Keyboard shortcuts

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