JWT manager for issuing and verifying access and refresh tokens with TTL support.
// Source: https://github.com/laowang74152/gpt2api | License: MIT | Copyright 2026 gpt2api contributors
// Provided via justclaw.it.com; keep this notice with the code.
package jwt
import (
"errors"
"fmt"
"time"
jwtv5 "github.com/golang-jwt/jwt/v5"
)
// Claims 是 JWT 的 payload。
type Claims struct {
UserID uint64 `json:"uid"`
Role string `json:"role"`
jwtv5.RegisteredClaims
}
// TokenPair 登录/刷新返回的双 token。
type TokenPair struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
TokenType string `json:"token_type"`
}
// Config 依赖注入配置。
type Config struct {
Secret string
Issuer string
AccessTTLSec int
RefreshTTLSec int
}
// Manager 负责签发与校验 access / refresh token。
// 通过 SetTTLProvi
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key