Documentation
¶
Index ¶
- Constants
- Variables
- func GenTokens(userID string, username string, session *model.Session) (aToken, rToken string, err error)
- func GetSession(userID string) (*model.Session, bool)
- func Init() error
- func RefreshTokens(accessToken, refreshToken string, session *model.Session) (newAccessToken, newRefreshToken string, err error)
- func RevokeTokens(userID string)
- func Verify(claims *Claims, accessToken, userAgent string) error
- type Claims
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 RefreshTokens ¶
func RefreshTokens(accessToken, refreshToken string, session *model.Session) (newAccessToken, newRefreshToken string, err error)
RefreshTokens 通过 refresh token 刷新一个新的 AccessToken
func RevokeTokens ¶
func RevokeTokens(userID string)
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
}
Click to show internal directories.
Click to hide internal directories.