Documentation
¶
Index ¶
- type Claims
- type JWT
- func (u *JWT) Claims(tokenString string) (*Claims, error)
- func (u *JWT) Create(userID string, ttl time.Duration) (string, error)
- func (u *JWT) CreateWithJTI(userID string, ttl time.Duration) (string, string, error)
- func (u *JWT) IsUser(token string, userID string) bool
- func (u *JWT) UserID(token string) (string, error)
- func (u *JWT) Validate(token string, userID string) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Claims ¶
type Claims struct {
UserID string `json:"user_id"`
// JTI is the JWT identifier, used for revocation. Tokens issued
// before JTI rollout will have an empty JTI; callers should treat
// an empty JTI as "not revocable" rather than as an error.
JTI string `json:"jti"`
// ExpiresAt is the unix timestamp from the `exp` claim, if present.
ExpiresAt int64 `json:"exp"`
jwt.MapClaims
}
JWT and Claims provide JWT token creation and validation.
type JWT ¶
type JWT struct {
// contains filtered or unexported fields
}
JWT and Claims provide JWT token creation and validation.
func (*JWT) Create ¶
Create generates a signed JWT token for the given userID with the specified TTL. A fresh JTI (JWT ID) is embedded so the token can be individually revoked. Use CreateWithJTI when the caller needs to know the JTI in advance (e.g. to insert it into a revocation table later).
func (*JWT) CreateWithJTI ¶
CreateWithJTI generates a signed JWT and returns both the encoded token and its JTI claim. The JTI is a ULID, lex-sortable by issue time.
Click to show internal directories.
Click to hide internal directories.