Documentation
¶
Overview ¶
Package jwt provides explicit, stateless HS256 access-token primitives.
Index ¶
Constants ¶
const ( MinimumSecretBytes = 32 DefaultMaxTTL = 24 * time.Hour DefaultClockSkew = time.Duration(0) )
Variables ¶
Functions ¶
func BearerToken ¶
BearerToken reads an Authorization: Bearer token header.
Types ¶
type Claims ¶
type Claims struct {
Subject string
Issuer string
Audience string
IssuedAt time.Time
ExpiresAt time.Time
}
Claims is tanGO's fixed, registered-claims-only JWT payload.
type Extractor ¶
Extractor obtains a JWT string from one request.
func QueryToken ¶
QueryToken returns an Extractor that reads a named query parameter.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service issues and verifies tokens for one issuer and audience. Its key set is immutable after construction.
func NewService ¶
func NewService(active Key, verificationKeys []Key, issuer string, audience string, opts ...ServiceOption) (*Service, error)
NewService constructs an HS256 service. active signs new tokens and is automatically included alongside verificationKeys during verification.
func (*Service) Middleware ¶
func (s *Service) Middleware(extract Extractor) tango.Middleware
Middleware verifies an extracted token once per request and stores Claims on the standard request context. Missing tokens pass through for optional authentication; supplied invalid tokens receive a generic JSON 401.
type ServiceOption ¶
type ServiceOption func(*serviceConfig)
ServiceOption configures a Service at construction.
func WithClockSkew ¶
func WithClockSkew(skew time.Duration) ServiceOption
WithClockSkew permits the configured amount of clock drift during time validation. Values above five minutes are rejected by NewService.
func WithMaxTTL ¶
func WithMaxTTL(ttl time.Duration) ServiceOption
WithMaxTTL changes the maximum lifetime Issue accepts.