jwt

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthorizationHeaderName = "Authorization"
	BearerTokenPrefix       = "Bearer "
)
View Source
const (
	ClaimAddress             = "sub"
	ClaimTokenType           = "type"
	ClaimExpirationTimestamp = "exp"
	ClaimIsAdmin             = "is_admin"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthClaim

type AuthClaim struct {
	Address string
	Type    TokenType
	IsAdmin bool
}

AuthClaim is a helper structure to organize all claims in one entity

type JWTConfig

type JWTConfig struct {
	SecretKey             string        `fig:"secret_key,required"`
	AccessExpirationTime  time.Duration `fig:"access_expiration_time,required"`
	RefreshExpirationTime time.Duration `fig:"refresh_expiration_time,required"`
}

type JWTIssuer

type JWTIssuer struct {
	// contains filtered or unexported fields
}

func (*JWTIssuer) IssueJWT

func (i *JWTIssuer) IssueJWT(claim *AuthClaim) (token string, exp time.Time, err error)

func (*JWTIssuer) ValidateJWT

func (i *JWTIssuer) ValidateJWT(str string) (claim *AuthClaim, err error)

type Jwter

type Jwter interface {
	JWT() *JWTIssuer
}

func NewJwter

func NewJwter(getter kv.Getter) Jwter

type RawJWT

type RawJWT struct {
	// contains filtered or unexported fields
}

RawJWT represents helper structure to provide setter and getter methods to work with JWT claims

func (*RawJWT) Address

func (r *RawJWT) Address() (res string, ok bool)

func (*RawJWT) IsAdmin

func (r *RawJWT) IsAdmin() (res bool, ok bool)

func (*RawJWT) SetAddress

func (r *RawJWT) SetAddress(sub string) *RawJWT

func (*RawJWT) SetExpirationTimestamp

func (r *RawJWT) SetExpirationTimestamp(expiration time.Time) *RawJWT

func (*RawJWT) SetIsAdmin

func (r *RawJWT) SetIsAdmin(isAdmin bool) *RawJWT

func (*RawJWT) SetTokenType

func (r *RawJWT) SetTokenType(typ TokenType) *RawJWT

func (*RawJWT) TokenType

func (r *RawJWT) TokenType() (typ TokenType, ok bool)

type TokenType

type TokenType string
var (
	AccessTokenType  TokenType = "access"
	RefreshTokenType TokenType = "refresh"
)

func (TokenType) String

func (t TokenType) String() string

Jump to

Keyboard shortcuts

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