Documentation ¶
Index ¶
- Variables
- func Decode(part string) ([]byte, error)
- func Encode(part []byte) string
- func ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)
- func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)
- func ReadBytes(path string) ([]byte, error)
- type Algorithm
- type HMACAlgorithm
- type Header
- type JWT
- func (j *JWT) AddAlgorithm(name string, algorithm Algorithm)
- func (j *JWT) Issuer() string
- func (j *JWT) JTI() string
- func (j *JWT) NewPayload(subject, audience string) *Payload
- func (j *JWT) NewToken(algorithm, subject, audience string) (*Token, error)
- func (j *JWT) NewTokenByRaw(token string) (*Token, error)
- func (j *JWT) SetAutoCreateJTI(auto bool)
- func (j *JWT) SetNotBefore(t time.Time)
- type Payload
- type RSAAlgorithm
- type RawToken
- type Token
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidKey = errors.New("Key is invalid or of invalid type") ErrInvalidSignature = errors.New("Signature is invalid") )
View Source
var ( ErrKeyMustBePEMEncoded = errors.New("Invalid Key: Key must be PEM encoded PKCS1 or PKCS8 private key") ErrNotRSAPrivateKey = errors.New("Key is not a valid RSA private key") ErrNotRSAPublicKey = errors.New("Key is not a valid RSA public key") )
View Source
var ( ErrInvalidIssuer = errors.New("Issuer is invalid.") ErrTokenExpired = errors.New("Token is expired.") )
Functions ¶
func ParseRSAPrivateKeyFromPEM ¶
func ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)
Parse PEM encoded PKCS1 or PKCS8 private key
func ParseRSAPublicKeyFromPEM ¶
Parse PEM encoded PKCS1 or PKCS8 public key
Types ¶
type HMACAlgorithm ¶
type HMACAlgorithm struct {
// contains filtered or unexported fields
}
func NewHMACAlgorithm ¶
func NewHMACAlgorithm(hash crypto.Hash, key []byte) (*HMACAlgorithm, error)
func (*HMACAlgorithm) Encrypt ¶
func (h *HMACAlgorithm) Encrypt(data string) (string, error)
Implements the Encrypt method from Algorithm.
func (*HMACAlgorithm) Verify ¶
func (h *HMACAlgorithm) Verify(data, signature string) error
Implements the Verify method from Algorithm.
type JWT ¶
type JWT struct {
// contains filtered or unexported fields
}
JWT(JSON WEB TOKEN) Manager.
func (*JWT) AddAlgorithm ¶
Add Algorithm.
func (*JWT) NewPayload ¶
func (*JWT) SetAutoCreateJTI ¶
func (*JWT) SetNotBefore ¶
type Payload ¶
type Payload struct { Exp int64 `json:"exp"` // expiration time Iss string `json:"iss"` // issuer Sub string `json:"sub"` // subject Aud string `json:"aud"` // audience Nbf int64 `json:"nbf"` // not before Iat int64 `json:"iat"` // issued at Jti string `json:"jti"` // jwt id Extra map[string]interface{} `json:"extra"` // extra }
func NewPayload ¶
func NewPayload() *Payload
type RSAAlgorithm ¶
type RSAAlgorithm struct {
// contains filtered or unexported fields
}
func NewRSAAlgorithm ¶
func NewRSAAlgorithm(hash crypto.Hash, publicKey, privateKey interface{}) (*RSAAlgorithm, error)
func (*RSAAlgorithm) Encrypt ¶
func (ra *RSAAlgorithm) Encrypt(data string) (string, error)
Implements the Encrypt method from Algorithm.
func (*RSAAlgorithm) Verify ¶
func (ra *RSAAlgorithm) Verify(data, signature string) error
Implements the Verify method from Algorithm.
type RawToken ¶
type RawToken struct {
// contains filtered or unexported fields
}
func NewRawToken ¶
type Token ¶
type Token struct { Raw *RawToken // The raw token. Header *Header // The first part of the token. Payload *Payload // The second part of the token. // contains filtered or unexported fields }
func (*Token) ValidateExpiration ¶
Check expiration time.
func (*Token) ValidateIssuer ¶
Click to show internal directories.
Click to hide internal directories.