jwt

package
v0.0.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoKey = errors.New("not provider jwt private/secret key")
	// ErrTokenExpired variable
	ErrTokenExpired = errors.New("token is expired")
	// ErrParsePrivateKey variable
	ErrParsePrivateKey = errors.New("parse private key error")
)
View Source
var (
	// Now variable
	Now = time.Now
)

Functions

func ParseUnverified

func ParseUnverified(raw string, claims IJWTClaims) error

Types

type ClaimsBuilder

type ClaimsBuilder jwt.Claims

ClaimsBuilder type

func NewClaimsBuilder

func NewClaimsBuilder() *ClaimsBuilder

NewClaimsBuilder method

func (*ClaimsBuilder) Build

func (c *ClaimsBuilder) Build() *jwt.Claims

Build method

func (*ClaimsBuilder) ExpiresAfter

func (c *ClaimsBuilder) ExpiresAfter(d time.Duration) *ClaimsBuilder

ExpiresAfter method

func (*ClaimsBuilder) GetAudience

func (c *ClaimsBuilder) GetAudience() jwt.Audience

GetAudience method

func (*ClaimsBuilder) GetExpiresAfter

func (c *ClaimsBuilder) GetExpiresAfter() *jwt.NumericDate

GetExpiresAfter method

func (*ClaimsBuilder) GetID

func (c *ClaimsBuilder) GetID() string

GetID method

func (*ClaimsBuilder) GetIssuedAt

func (c *ClaimsBuilder) GetIssuedAt() *jwt.NumericDate

GetIssuedAt method

func (*ClaimsBuilder) GetIssuer

func (c *ClaimsBuilder) GetIssuer() string

GetIssuer method

func (*ClaimsBuilder) GetNotBefore

func (c *ClaimsBuilder) GetNotBefore() *jwt.NumericDate

GetNotBefore method

func (*ClaimsBuilder) GetSubject

func (c *ClaimsBuilder) GetSubject() string

GetSubject method

func (*ClaimsBuilder) NotUseBefore

func (c *ClaimsBuilder) NotUseBefore(d time.Duration) *ClaimsBuilder

NotUseBefore method

func (*ClaimsBuilder) WithAudience

func (c *ClaimsBuilder) WithAudience(audience jwt.Audience) *ClaimsBuilder

WithAudience method

func (*ClaimsBuilder) WithID

func (c *ClaimsBuilder) WithID(id string) *ClaimsBuilder

WithID method

func (*ClaimsBuilder) WithIssuedAt

func (c *ClaimsBuilder) WithIssuedAt() *ClaimsBuilder

WithIssuedAt method

func (*ClaimsBuilder) WithIssuer

func (c *ClaimsBuilder) WithIssuer(issuer string) *ClaimsBuilder

WithIssuer method

func (*ClaimsBuilder) WithSubject

func (c *ClaimsBuilder) WithSubject(subject string) *ClaimsBuilder

WithSubject method

type ClaimsOption

type ClaimsOption interface {
	Apply(*Common)
}

ClaimsOption interface

func WithClientID

func WithClientID[T generic.ByteSeq](id T) ClaimsOption

WithClientID method

func WithPermissions

func WithPermissions(permissions ...string) ClaimsOption

WithPermissions method

func WithRootID added in v0.0.6

func WithRootID[T generic.ByteSeq](id T) ClaimsOption

WithRootID method

func WithScopes

func WithScopes(scopes ...string) ClaimsOption

WithScopes method

func WithSecret

func WithSecret[T generic.ByteSeq](secret T) ClaimsOption

WithSecret method

type Common

type Common struct {
	Secret      []byte   `json:"s,omitempty"`
	RootID      []byte   `json:"root_id,omitempty"`
	ClientID    []byte   `json:"client_id,omitempty"`
	Permissions []string `json:"permissions,omitempty"`
	Scopes      []string `json:"scopes,omitempty"`
	*jwt.Claims
}

Common type

func NewCommon

func NewCommon(claims *jwt.Claims, options ...ClaimsOption) *Common

NewCommon method

func (*Common) ExpiresAfter

func (c *Common) ExpiresAfter(d time.Duration)

func (*Common) GetExpiresAfter

func (c *Common) GetExpiresAfter() *jwt.NumericDate

type EES256JWT

type EES256JWT struct {
	SigningKey *ecdsa.PrivateKey
	Sig        jose.Signer
	Enc        jose.Encrypter
}

EES256JWT type

func NewEES256JWT

func NewEES256JWT(ecdsaPrivateKey string) (*EES256JWT, error)

NewEES256JWT method

func NewEES256JWTFromOptions

func NewEES256JWTFromOptions(option config.JWT) (*EES256JWT, error)

func (EES256JWT) GenerateToken

func (ee EES256JWT) GenerateToken(claims IJWTClaims) (token string, err error)

GenerateToken method

func (EES256JWT) RefreshToken

func (ee EES256JWT) RefreshToken(token string, claims IJWTClaims, duration time.Duration) (string, error)

RefreshToken method

func (EES256JWT) Validate

func (ee EES256JWT) Validate(raw string) error

Validate method

func (EES256JWT) VerifyToken

func (ee EES256JWT) VerifyToken(token string, claims IJWTClaims) (err error)

VerifyToken method

type EHS256JWT

type EHS256JWT struct {
	SigningKey []byte
	Sig        jose.Signer
	Enc        jose.Encrypter
}

EHS256JWT type

func NewEHS256JWT

func NewEHS256JWT(hmacSecretKey string) (*EHS256JWT, error)

NewEHS256JWT method

func NewEHS256JWTFromOptions

func NewEHS256JWTFromOptions(option config.JWT) (*EHS256JWT, error)

func (EHS256JWT) GenerateToken

func (eh EHS256JWT) GenerateToken(claims IJWTClaims) (token string, err error)

GenerateToken method

func (EHS256JWT) RefreshToken

func (eh EHS256JWT) RefreshToken(token string, claims IJWTClaims, duration time.Duration) (string, error)

RefreshToken method

func (EHS256JWT) Validate

func (eh EHS256JWT) Validate(raw string) error

Validate method

func (EHS256JWT) VerifyToken

func (eh EHS256JWT) VerifyToken(token string, claims IJWTClaims) (err error)

VerifyToken method

type EHS384JWT

type EHS384JWT struct {
	SigningKey []byte
	Sig        jose.Signer
	Enc        jose.Encrypter
}

EHS384JWT type

func NewEHS384JWT

func NewEHS384JWT(hmacSecretKey string) (*EHS384JWT, error)

NewEHS384JWT method

func NewEHS384JWTFromOptions

func NewEHS384JWTFromOptions(option config.JWT) (*EHS384JWT, error)

func (EHS384JWT) GenerateToken

func (eh EHS384JWT) GenerateToken(claims IJWTClaims) (token string, err error)

GenerateToken method

func (EHS384JWT) RefreshToken

func (eh EHS384JWT) RefreshToken(token string, claims IJWTClaims, duration time.Duration) (string, error)

RefreshToken method

func (EHS384JWT) Validate

func (eh EHS384JWT) Validate(raw string) error

Validate method

func (EHS384JWT) VerifyToken

func (eh EHS384JWT) VerifyToken(token string, claims IJWTClaims) (err error)

VerifyToken method

type EHS512JWT

type EHS512JWT struct {
	SigningKey []byte
	Sig        jose.Signer
	Enc        jose.Encrypter
}

EHS512JWT type

func NewEHS512JWT

func NewEHS512JWT(hmacSecretKey string) (*EHS512JWT, error)

NewEHS512JWT method

func NewEHS512JWTFromOptions

func NewEHS512JWTFromOptions(option config.JWT) (*EHS512JWT, error)

func (EHS512JWT) GenerateToken

func (eh EHS512JWT) GenerateToken(claims IJWTClaims) (token string, err error)

GenerateToken method

func (EHS512JWT) RefreshToken

func (eh EHS512JWT) RefreshToken(token string, claims IJWTClaims, duration time.Duration) (string, error)

RefreshToken method

func (EHS512JWT) Validate

func (eh EHS512JWT) Validate(raw string) error

Validate method

func (EHS512JWT) VerifyToken

func (eh EHS512JWT) VerifyToken(token string, claims IJWTClaims) (err error)

VerifyToken method

type ERS256JWT

type ERS256JWT struct {
	SigningKey *rsa.PrivateKey
	Sig        jose.Signer
	Enc        jose.Encrypter
}

ERS256JWT type

func NewERS256JWT

func NewERS256JWT(rsaPrivateKey string) (*ERS256JWT, error)

NewERS256JWT method

func NewERS256JWTFromOptions

func NewERS256JWTFromOptions(option config.JWT) (*ERS256JWT, error)

func (ERS256JWT) GenerateToken

func (er ERS256JWT) GenerateToken(claims IJWTClaims) (token string, err error)

GenerateToken method

func (ERS256JWT) RefreshToken

func (er ERS256JWT) RefreshToken(token string, claims IJWTClaims, duration time.Duration) (string, error)

RefreshToken method

func (ERS256JWT) Validate

func (er ERS256JWT) Validate(raw string) error

Validate method

func (ERS256JWT) VerifyToken

func (er ERS256JWT) VerifyToken(token string, claims IJWTClaims) (err error)

VerifyToken method

type ES256JWT

type ES256JWT struct {
	SigningKey *ecdsa.PrivateKey
	Sig        jose.Signer
}

ES256JWT type

func NewES256JWT

func NewES256JWT(ecdsaPrivateKey string) (*ES256JWT, error)

NewES256JWT method

func NewES256JWTFromOptions

func NewES256JWTFromOptions(option config.JWT) (*ES256JWT, error)

func (ES256JWT) GenerateToken

func (e ES256JWT) GenerateToken(claims IJWTClaims) (token string, err error)

GenerateToken method

func (ES256JWT) RefreshToken

func (e ES256JWT) RefreshToken(token string, claims IJWTClaims, duration time.Duration) (string, error)

RefreshToken method

func (ES256JWT) Validate

func (e ES256JWT) Validate(raw string) error

Validate method

func (ES256JWT) VerifyToken

func (e ES256JWT) VerifyToken(token string, claims IJWTClaims) (err error)

VerifyToken method

type HS256JWT

type HS256JWT struct {
	SigningKey []byte
	Sig        jose.Signer
}

HS256JWT type

func NewHS256JWT

func NewHS256JWT(hmacSecretKey string) (*HS256JWT, error)

NewHS256JWT method

func NewHS256JWTFromOptions

func NewHS256JWTFromOptions(option config.JWT) (*HS256JWT, error)

func (HS256JWT) GenerateToken

func (h HS256JWT) GenerateToken(claims IJWTClaims) (token string, err error)

GenerateToken method

func (HS256JWT) RefreshToken

func (h HS256JWT) RefreshToken(token string, claims IJWTClaims, duration time.Duration) (string, error)

RefreshToken method

func (HS256JWT) Validate

func (h HS256JWT) Validate(raw string) error

Validate method

func (HS256JWT) VerifyToken

func (h HS256JWT) VerifyToken(token string, claims IJWTClaims) (err error)

VerifyToken method

type HS384JWT

type HS384JWT struct {
	SigningKey []byte
	Sig        jose.Signer
}

HS384JWT type

func NewHS384JWT

func NewHS384JWT(hmacSecretKey string) (*HS384JWT, error)

NewHS384JWT method

func NewHS384JWTFromOptions

func NewHS384JWTFromOptions(option config.JWT) (*HS384JWT, error)

func (HS384JWT) GenerateToken

func (h HS384JWT) GenerateToken(claims IJWTClaims) (token string, err error)

GenerateToken method

func (HS384JWT) RefreshToken

func (h HS384JWT) RefreshToken(token string, claims IJWTClaims, duration time.Duration) (string, error)

RefreshToken method

func (HS384JWT) Validate

func (h HS384JWT) Validate(raw string) error

Validate method

func (HS384JWT) VerifyToken

func (h HS384JWT) VerifyToken(token string, claims IJWTClaims) (err error)

VerifyToken method

type IJWT

type IJWT interface {
	GenerateToken(claims IJWTClaims) (string, error)
	Validate(raw string) (err error)
	VerifyToken(token string, claims IJWTClaims) (err error)
	RefreshToken(token string, claims IJWTClaims, duration time.Duration) (string, error)
}

IJWT interface

type IJWTClaims

type IJWTClaims interface {
	Validate(e jwt.Expected) error
	ValidateWithLeeway(e jwt.Expected, leeway time.Duration) error
}

type IJWTExpire

type IJWTExpire interface {
	ExpiresAfter(d time.Duration)
	GetExpiresAfter() *jwt.NumericDate
}

type RS256JWT

type RS256JWT struct {
	SigningKey *rsa.PrivateKey
	Sig        jose.Signer
}

RS256JWT type

func NewRS256JWT

func NewRS256JWT(rsaPrivateKey string) (*RS256JWT, error)

NewRS256JWT method

func NewRS256JWTFromOptions

func NewRS256JWTFromOptions(option config.JWT) (*RS256JWT, error)

func (RS256JWT) GenerateToken

func (r RS256JWT) GenerateToken(claims IJWTClaims) (token string, err error)

GenerateToken method

func (RS256JWT) RefreshToken

func (r RS256JWT) RefreshToken(token string, claims IJWTClaims, duration time.Duration) (string, error)

RefreshToken method

func (RS256JWT) Validate

func (r RS256JWT) Validate(raw string) error

Validate method

func (RS256JWT) VerifyToken

func (r RS256JWT) VerifyToken(token string, claims IJWTClaims) (err error)

VerifyToken method

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL