jwt

package
v0.10.14 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinUserIDLength   = 1
	MinUsernameLength = 3
)

Variables

View Source
var (
	ErrInvalidToken        = errors.New("invalid token")
	ErrInvalidAccessToken  = errors.New("invalid access token")
	ErrInvalidRefreshToken = errors.New("invalid refresh token")
	ErrTokenExpired        = errors.New("token expired")
	ErrTokenMalformed      = errors.New("token malformed")
	ErrTokenNotValidYet    = errors.New("token not valid yet")
)

Functions

func GenTokens

func GenTokens(userID string, username string, session *model.Session) (aToken, rToken string, err error)

GenTokens 生成 access token 和 refresh token

func GetSession

func GetSession(userID string) (*model.Session, bool)

func Init

func Init() error

func RefreshTokens

func RefreshTokens(accessToken, refreshToken string, session *model.Session) (newAccessToken, newRefreshToken string, err error)

RefreshTokens 通过 refresh token 刷新一个新的 AccessToken

func RevokeTokens

func RevokeTokens(userID string)

func Verify

func Verify(claims *Claims, accessToken, userAgent string) error

Types

type Claims

type Claims struct {
	UserID            string `json:"user_id,omitempty"`
	Username          string `json:"username,omitempty"`
	PreferredUsername string `json:"preferred_username,omitempty"`
	GivenName         string `json:"given_name,omitempty"`
	FamilyName        string `json:"family_name,omitempty"`
	Email             string `json:"email,omitempty"`
	EmailVerified     bool   `json:"email_verified,omitempty"`
	Scope             string `json:"scope,omitempty"`

	// Standard Claims
	AuthTime *jwt.NumericDate `json:"auth_time"` // The time at which the JWT was issued.
	Typ      string           `json:"typ"`       // The media type of this complete JWT. eg: Bearer
	Azp      string           `json:"azp"`       // The authorized party to which the ID Token was issued.
	Sid      string           `json:"sid"`       // An identifier for a session at the relying party.
	Acr      string           `json:"acr"`       // Authentication Context Class. Learn more
	AtHash   string           `json:"at_hash"`   // Access Token hash value encoded in base64url format.

	jwt.RegisteredClaims
}

func ParseToken

func ParseToken(tokenStr string) (*Claims, error)

ParseToken parse token

func ParseTokenFromHeader

func ParseTokenFromHeader(header http.Header) (token string, claims *Claims, err error)

Jump to

Keyboard shortcuts

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