auth

package
v0.1.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Author xc, Created on 2019-08-11 16:49 {COPYRIGHTS}

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenErrorExpired = errors.New("Expired token")
	TokenErrorRevoked = errors.New("Expired revoked")
)

Functions

func NewAccessToken

func NewAccessToken(refreshToken string, r *http.Request) (string, error)

func NewRefreshToken

func NewRefreshToken(ctx context.Context, userID int, rememberMe bool) (string, error)

func RegisterTokenManager

func RegisterTokenManager(manager RefreshTokenManager)

Types

type RefreshClaims

type RefreshClaims struct {
	jwt.StandardClaims
	UserID int    `json:"user_id"`
	GUID   string `json:"guid"`
}

func VerifyRefreshToken

func VerifyRefreshToken(token string) (RefreshClaims, error)

if failed there will be always err

type RefreshTokenManager

type RefreshTokenManager interface {
	Store(ctx context.Context, id string, userID int, Expiry int64, claims map[string]interface{}) error
	Get(id string) interface{}
	Delete(ctx context.Context, id string) error
}

func GetTokenManager

func GetTokenManager() RefreshTokenManager

type UserClaims

type UserClaims struct {
	jwt.StandardClaims
	UserID int    `json:"user_id"`
	Name   string `json:"user_name"`
}

func VerifyToken

func VerifyToken(token string) (error, UserClaims)

Verify access token, return nil, TokenErrorExpired or other err @todo: maybe store refresh's guid in access token also to check if it's there? It will have access token revoked in refresh token is revoked.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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