jwtutil

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTokenDuration = 30 * 24 * time.Hour

Variables

This section is empty.

Functions

func GenerateJWTToken

func GenerateJWTToken(conf *config.AuthJwtTokenCmd) error

func GeneratePrivateKey

func GeneratePrivateKey(conf *config.AuthKeyPrivateCmd) error

func GeneratePublicKey

func GeneratePublicKey(conf *config.AuthKeyPublicCmd) error

func WithRole

func WithRole(role Role) func(*tokenSigner)

func WithSignerAudience

func WithSignerAudience(audience string) func(*tokenSigner)

func WithTokenDuration

func WithTokenDuration(duration time.Duration) func(*tokenSigner)

func WithVerifierAudience

func WithVerifierAudience(audience string) func(*tokenVerifier)

Types

type Role

type Role string
const (
	RoleClient Role = Role(config.RoleClient)
	RoleAgent  Role = Role(config.RoleAgent)
)

type TokenAlg

type TokenAlg string
const (
	RS256 TokenAlg = "RS256"
	ES256 TokenAlg = "ES256"
)

type TokenClaims

type TokenClaims struct {
	AgentID string `json:"agent_id"`
	Role    string `json:"role"`
	jwt.RegisteredClaims
}

type TokenSigner

type TokenSigner interface {
	SignToken() (string, error)
}

func NewTokenSigner

func NewTokenSigner(alg TokenAlg, privateKey crypto.PrivateKey, agentID string, opts ...TokenSignerOption) TokenSigner

type TokenSignerOption

type TokenSignerOption func(*tokenSigner)

type TokenVerifier

type TokenVerifier interface {
	VerifyToken(tokenString string) (*TokenClaims, error)
}

func NewTokenVerifier

func NewTokenVerifier(publicKey crypto.PublicKey, opts ...TokenVerifierOption) TokenVerifier

type TokenVerifierOption

type TokenVerifierOption func(*tokenVerifier)

Jump to

Keyboard shortcuts

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