Documentation ¶
Overview ¶
Package jws implements JSON Web Signature (JWS) specification.
Index ¶
- Constants
- type ErrGetKey
- type ErrInvalidFormat
- type ErrInvalidSignature
- type ErrInvalidToken
- type GetKeyFunc
- type Header
- type RegHeader
- func (h *RegHeader) GetAlgorithm() string
- func (h *RegHeader) GetID() string
- func (h *RegHeader) GetJWKSetURL() string
- func (mj *RegHeader) MarshalJSON() ([]byte, error)
- func (mj *RegHeader) MarshalJSONBuf(buf fflib.EncodingBuffer) error
- func (uj *RegHeader) UnmarshalJSON(input []byte) error
- func (uj *RegHeader) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error
- type SignedToken
Constants ¶
const (
// JWTHeaderType defines the type name for JWT header.
JWTHeaderType = "JOSE"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrGetKey ¶
type ErrGetKey string
An ErrGetKey represents an error when was unable to retrieve token signing key.
type ErrInvalidFormat ¶
type ErrInvalidFormat string
An ErrInvalidFormat represents an error when token format is invalid.
func (ErrInvalidFormat) Error ¶
func (e ErrInvalidFormat) Error() string
Error returns string representation of current instance error.
type ErrInvalidSignature ¶
type ErrInvalidSignature string
An ErrInvalidSignature represents an error when token signature could not be validated.
func (ErrInvalidSignature) Error ¶
func (e ErrInvalidSignature) Error() string
Error returns string representation of current instance error.
type ErrInvalidToken ¶
type ErrInvalidToken string
An ErrInvalidToken represents an error when a token is not valid by time being.
func (ErrInvalidToken) Error ¶
func (e ErrInvalidToken) Error() string
Error returns string representation of current instance error.
type GetKeyFunc ¶
GetKeyFunc defines a function to retrieve a key for specified token.
type Header ¶
type Header interface { GetID() string GetAlgorithm() string GetJWKSetURL() string json.Marshaler json.Unmarshaler }
A Header represents the JOSE Header which describes the digital signature or MAC applied to the JWS Protected Header and the JWS Payload and optionally additional properties of the JWS.
type RegHeader ¶
type RegHeader struct { ID string `json:"kid,omitempty"` Type string `json:"typ,omitempty"` ContentType string `json:"cty,omitempty"` Algorithm string `json:"alg"` JWKSetURL string `json:"jku,omitempty"` JWK string `json:"jwk,omitempty"` X509URL string `json:"x5u,omitempty"` X509Chain string `json:"x5c,omitempty"` X509SHA1 string `json:"x5t,omitempty"` X509SHA256 string `json:"x5t#S256,omitempty"` Critical []string `json:"crit,omitempty"` }
A RegHeader represents the JOSE header with all registered parameter names.
func (*RegHeader) GetAlgorithm ¶
GetAlgorithm returns the algorithm used to sign current token.
func (*RegHeader) GetJWKSetURL ¶
GetJWKSetURL returns a URL to retrieve the key used to sign current token.
func (*RegHeader) MarshalJSON ¶
func (*RegHeader) MarshalJSONBuf ¶
func (mj *RegHeader) MarshalJSONBuf(buf fflib.EncodingBuffer) error
func (*RegHeader) UnmarshalJSON ¶
func (*RegHeader) UnmarshalJSONFFLexer ¶
type SignedToken ¶
A SignedToken represents a token encapsuled by JWS.
func DecodeAndValidate ¶
func DecodeAndValidate( token string, header Header, payload jwt.Claims, getKey GetKeyFunc, ) (*SignedToken, error)
DecodeAndValidate decodes an existing token and validates it.
func NewSignedToken ¶
func NewSignedToken(alg string) *SignedToken
NewSignedToken creates a new instance of SignedToken using default header and payload.
func (*SignedToken) EncodeAndSign ¶
func (t *SignedToken) EncodeAndSign(key interface{}) (string, error)
EncodeAndSign creates a string representation of current token and appends a signature.
func (*SignedToken) Validate ¶
func (t *SignedToken) Validate() bool
Validate returns whether current token header and payload is valid.