package system import ( "errors" "time" ) // The token contract lives apart from the other infrastructure seams because // the transport middleware and every service that authenticates a request reach // for these types and errors without caring about cache or storage. type IssuedToken struct { Value string ExpiresAt time.Time TTL time.Duration } type AuthClaims struct { UUID string ID uint Username string NickName string AuthorityID uint UserType string BufferTime time.Duration MustChangePwd bool PasswordVersion int64 Issuer string Audience []string IssuedAt time.Time NotBefore time.Time ExpiresAt time.Time } var ( ErrTokenExpired = errors.New("token expired") ErrTokenMalformed = errors.New("token malformed") ErrTokenSignatureInvalid = errors.New("token signature invalid") ErrTokenNotValidYet = errors.New("token not valid yet") ErrTokenInvalid = errors.New("token invalid") ErrTokenDisabled = errors.New("token disabled") ) type TokenIssuer interface { IssueToken(*User, uint, bool, time.Duration) (*IssuedToken, error) ReissueToken(*AuthClaims, uint) (*IssuedToken, error) ParseToken(string) (*AuthClaims, error) }