Documentation
¶
Index ¶
Constants ¶
const DefaultMaxBodySizeBytes int64 = 102_400 // 100kb
const DefaultMaxTimeout = 15 * time.Second
Variables ¶
Functions ¶
Types ¶
type ExpiredTokenError ¶
func (*ExpiredTokenError) Error ¶
func (e *ExpiredTokenError) Error() string
func (*ExpiredTokenError) Unwrap ¶
func (e *ExpiredTokenError) Unwrap() error
type HTTPRequestSigner ¶
type HTTPRequestSigner interface {
SignHTTPRequest(req *http.Request, timeout time.Duration) error
}
HTTPRequestSigner is responsible for signing HTTP requests using JWTs.
func NewHTTPRequestSigner ¶
func NewHTTPRequestSigner(generator JWTTokenGenerator) HTTPRequestSigner
NewHTTPRequestSigner creates a new HTTPRequestSigner with the given JWTTokenGenerator.
type HTTPRequestVerifier ¶
HTTPRequestVerifier is responsible for verifying HTTP requests using JWTs.
func NewHTTPRequestVerifier ¶
func NewHTTPRequestVerifier(parser JWTTokenParser, maxBodySizeBytes int64) HTTPRequestVerifier
NewHTTPRequestVerifier creates a new HTTPRequestVerifier with the given JWTTokenParser.
type JWTHTTPSignerVerifier ¶
type JWTHTTPSignerVerifier struct {
// contains filtered or unexported fields
}
JWTHTTPSignerVerifier implements both signing and verifying of HTTP requests.
func (*JWTHTTPSignerVerifier) MaxBodySizeBytes ¶
func (s *JWTHTTPSignerVerifier) MaxBodySizeBytes() int64
func (*JWTHTTPSignerVerifier) SignHTTPRequest ¶
SignHTTPRequest signs an HTTP request with a JWT.
func (*JWTHTTPSignerVerifier) VerifyHTTPRequest ¶
func (s *JWTHTTPSignerVerifier) VerifyHTTPRequest(req *http.Request) error
VerifyHTTPRequest verifies the JWT in an HTTP request.
type JWTManager ¶
func NewJWTManager ¶
func NewJWTManager(stellarPrivateKey string, stellarPublicKey string, maxTimeout time.Duration) (*JWTManager, error)
NewJWTManager creates a new JWT token manager that can generate and parse JWT tokens.
func (*JWTManager) GenerateJWT ¶
func (m *JWTManager) GenerateJWT(methodAndPath string, body []byte, expiresAt time.Time) (string, error)
GenerateJWT generates a JWT token with the given body and expiration time.
func (*JWTManager) ParseJWT ¶
func (m *JWTManager) ParseJWT(tokenString, methodAndPath string, body []byte) (*jwtgo.Token, *customClaims, error)
ParseJWT parses a JWT token and returns it with the claims. It also checks if the token expiration is within [now, now+MaxTimeout], and if the claims' hashed_body matches the requestBody's hash.
type JWTTokenGenerator ¶
type JWTTokenGenerator interface {
// GenerateJWT generates a JWT token with the given body and expiration time.
GenerateJWT(methodAndPath string, body []byte, expiresAt time.Time) (string, error)
}
func NewJWTTokenGenerator ¶
func NewJWTTokenGenerator(stellarPrivateKey string) (JWTTokenGenerator, error)
type JWTTokenParser ¶
type JWTTokenParser interface {
// ParseJWT parses a JWT token and returns it with the claims.
ParseJWT(tokenString, methodAndPath string, body []byte) (*jwtgo.Token, *customClaims, error)
}
func NewJWTTokenParser ¶
func NewJWTTokenParser(maxTimeout time.Duration, stellarPublicKey string) (JWTTokenParser, error)
NewJWTTokenParser creates a new JWT token parser that can parse a JWT token as long as it has been signed by the provided Stellar public key.
func NewMultiJWTTokenParser ¶
func NewMultiJWTTokenParser(maxTimeout time.Duration, stellarPublicKeys ...string) (JWTTokenParser, error)
NewMultiJWTTokenParser creates a new JWT token parser that can parse a JWT token as long as it has been signed by an least one of the provided Stellar public keys.
type MultiJWTTokenParser ¶
type MultiJWTTokenParser struct {
// contains filtered or unexported fields
}