jwt

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScopeAnonymous is a token with a scope of anonymous
	ScopeAnonymous = "anonymous"
	// ScopeTenant is a token with a scope of tenant
	ScopeTenant = "tenant"
	// ScopeMerchant is a token with a scope of merchant
	ScopeMerchant = "merchant"

	// XJWT is the JWT that was sent by the caller of the request
	XJWT = "Authorization"

	// XIP is the ip of the caller
	XIP = "X-IP"
	// XScope is authorization scopes of the token
	XScope = "X-Scope"
	// XRole is the role of the token. One of anonymous, buyer, tenant or merchant
	XRole = "X-Role"

	// XTenantID is the uuid of the tenant
	XTenantID = "X-Tenant-ID"
	// XMerchantID is the uuid of the merchant
	XMerchantID = "X-Merchant-ID"
	// XUserID is the uuid of the user of API
	XUserID = "X-User-ID"
	// APIKey is the Sirius API key that is given to tenants and merchants
	APIKey = "X-Sirius-API-Key"
	// AppID is an application's app-id
	AppID = "X-Sirius-App-ID"

	// XTimeOffset is the header key that carries an optional time offset for testing
	XTimeOffset = "X-Time-Offset"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type JWKS

type JWKS struct {
	Keys []PublicKey `json:"keys"`
}

type PublicKey

type PublicKey struct {
	E   string `json:"e"`
	KID string `json:"kid"`
	KTY string `json:"kty"`
	N   string `json:"n"`
}

type SecretStore

type SecretStore interface {
	GetKeyIDs() []string
	GetPublicKeyWithID(kid string) string
	GetPrivateKeyWithID(kid string) string
}

SecretStore store containing secrets

type SiriusClaims

type SiriusClaims struct {
	jwt.RegisteredClaims
	TenantID   string   `json:"tenantID"`
	MerchantID string   `json:"merchantID,omitempty"`
	UserID     string   `json:"userID,omitempty"` // UserID is the original user of the token that requested a token exchange
	Scope      []string `json:"scp"`
	Role       string   `json:"role"`
}

func GetClaims

func GetClaims(token *jwt.Token) SiriusClaims

type Store

type Store struct {
	SecretStore
	// contains filtered or unexported fields
}

Store is the database for secrets

func (*Store) Authorize

func (db *Store) Authorize(inner http.Handler) http.Handler

func (*Store) GenerateToken

func (db *Store) GenerateToken(token Token, kid string) (string, error)

func (*Store) GetPublicKeys

func (db *Store) GetPublicKeys() (JWKS, error)

func (*Store) ParseHTTPToken

func (db *Store) ParseHTTPToken(header *http.Header) (token Token, err error)

func (*Store) ParseHTTPTokenWithoutValidation

func (db *Store) ParseHTTPTokenWithoutValidation(s string) (Token, error)

func (*Store) ParseTokenAndValidate

func (db *Store) ParseTokenAndValidate(tokenString string) (Token, error)

func (*Store) SetTokenLifetime

func (db *Store) SetTokenLifetime(lifetime time.Duration) error

func (*Store) ValidateSignature

func (db *Store) ValidateSignature(tokenString string) (Token, error)

type Token

type Token struct {
	jwt.Token
	SiriusClaims
}

Token is Bread's Token which includes all standard fields and Bread's custom claims

type Validator

type Validator interface {
	GenerateToken(token Token, kid string) (string, error)
	ParseHTTPToken(header *http.Header) (token Token, err error)
	ParseHTTPTokenWithoutValidation(token string) (Token, error)
	Authorize(inner http.Handler) http.Handler
	ParseTokenAndValidate(tokenString string) (Token, error)
	SetTokenLifetime(lifetime time.Duration) error
	ValidateSignature(token string) (Token, error)
	GetPublicKeys() (JWKS, error)
}

Validator is the interface to token validation of the jwt

func NewValidator

func NewValidator(store SecretStore) Validator

Jump to

Keyboard shortcuts

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