jwt

package
v0.0.7-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthorizationHeaderRequired = errors.New("jwt/service: authorization header required")
	ErrInvalidToken                = errors.New("jwt/service: invalid token")
	ErrInvalidUserClaim            = errors.New("jwt/service: invalid user id claim")
	ErrInvalidEmailClaim           = errors.New("jwt/service: invalid email claim")
)
View Source
var (
	ErrInvalidOrganiztionID = errors.New("rest/jwt: invalid organization id")
)
View Source
var (
	ErrInvalidSignatureAlgorithm = errors.New("jwt: invalid signature algorithm")
)

Functions

func ParseAlgorithm

func ParseAlgorithm(keyAttrs *keystore.KeyAttributes) (string, error)

Types

type RestHandler

type RestHandler struct {
	TokenHandler
	// contains filtered or unexported fields
}

func (*RestHandler) CreateSession

func (handler *RestHandler) CreateSession(
	w http.ResponseWriter,
	r *http.Request) (service.Session, error)

Creates a new web service session from the parsed JWT

func (*RestHandler) GenerateToken

func (handler *RestHandler) GenerateToken(w http.ResponseWriter, req *http.Request)

Decodes the requst body to a service.UserCredentials structure and generates a new JWT using the unmarshalled username and password.

func (*RestHandler) RefreshToken

func (handler *RestHandler) RefreshToken(w http.ResponseWriter, r *http.Request)

Exchange a JWT for a new token with a new expiration date

func (*RestHandler) Verify

func (handler *RestHandler) Verify(
	w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Validates the raw JWT token to ensure it's not expired or contains invalid claims. This is used by the negroni middleware to enforce authenticated access to procted resources.

type Service

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

func NewService

func NewService(params ServiceParams) (*Service, error)

func (*Service) GenerateToken

func (service *Service) GenerateToken(user *entities.User) (string, error)

func (*Service) KeyFunc

func (service *Service) KeyFunc(token *jwt.Token) (interface{}, error)

func (*Service) ParseToken

func (service *Service) ParseToken(
	w http.ResponseWriter, r *http.Request) (*jwt.Token, *TokenClaims, error)

func (*Service) ParseTokenString

func (service *Service) ParseTokenString(tokenString string) (*jwt.Token, error)

func (*Service) PublicKey

func (service *Service) PublicKey() crypto.PublicKey

func (*Service) Verify

func (service *Service) Verify(token *jwt.Token) error

type ServiceParams

type ServiceParams struct {
	Audience   string
	Expiration int
	Issuer     string
	KeyAttrs   *keystore.KeyAttributes
	Keyring    *platform.Keyring
}

type SigningMethod

type SigningMethod struct {
	jwt.SigningMethod
	// contains filtered or unexported fields
}

func NewSigningMethod

func NewSigningMethod(keyAttrs *keystore.KeyAttributes) (*SigningMethod, error)

func (*SigningMethod) Alg

func (sm *SigningMethod) Alg() string

func (*SigningMethod) Digest

func (sm *SigningMethod) Digest(signingString string) ([]byte, error)

func (*SigningMethod) Sign

func (sm *SigningMethod) Sign(signingString string, key interface{}) ([]byte, error)

func (*SigningMethod) Verify

func (sm *SigningMethod) Verify(signingString string, signature []byte, key interface{}) error

type TokenClaims

type TokenClaims struct {
	Organizations  []uint64 `json:"orgs"`
	Services       []uint64 `json:"svcs"`
	UserID         uint64   `json:"uid"`
	WebAuthnClaims *webauthn.SessionData
	jwt.RegisteredClaims
}

type TokenHandler

type TokenHandler interface {
	middleware.JsonWebTokenMiddleware
}

func NewRestHandler

func NewRestHandler(
	logger *logging.Logger,
	responseWriter response.HttpWriter,
	jwtService *Service,
	userService service.UserServicer) (TokenHandler, error)

Instantiate a new JsonWebTokenService

Jump to

Keyboard shortcuts

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