Documentation
¶
Overview ¶
Package auth provides functions for services to issue and sign api consumer tokens.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyMustBePEMEncoded happens when the PEM format is not valid. ErrKeyMustBePEMEncoded = errors.New("invalid key: must be PEM encoded PKCS1 or PKCS8 private key") // ErrNotRSAPrivateKey happens when the key is not a valid RSA private key. ErrNotRSAPrivateKey = errors.New("invalid key: must be a valid RSA private key") // ErrNotPrivateKey happens when the key is neither an RSA or ECDSA private key. ErrNotPrivateKey = errors.New("invalid key: must be either an RSA or ECDSA private key") // ErrNotPublicKey happens when the key is neither an RSA or ECDSA public key. ErrNotPublicKey = errors.New("invalid key: must be either an RSA or ECDSA public key") )
Functions ¶
func PrivateKeyFromPEM ¶ added in v0.21.0
func PrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error)
PrivateKeyFromPEM will take a private key PEM and derive the private key from it.
func PrivateKeyFromPEMWithPassword ¶ added in v0.21.0
func PrivateKeyFromPEMWithPassword(key []byte, password string) (crypto.PrivateKey, error)
PrivateKeyFromPEMWithPassword will take a private key PEM with a password and derive the private key from it.
Types ¶
type Issuer ¶
type Issuer struct {
// contains filtered or unexported fields
}
Issuer represents a set of methods for generating a JWT with a private key
func NewIssuer ¶
func NewIssuer(private crypto.PrivateKey, method jwt.SigningMethod) *Issuer
NewIssuer creates a new issuer.
func NewIssuerFromPEM ¶ added in v0.21.0
NewIssuerFromPEM will take a private key PEM and derive the private key from it.
func NewIssuerFromPEMWithPassword ¶ added in v0.21.0
func NewIssuerFromPEMWithPassword(key []byte, password string, method jwt.SigningMethod) (*Issuer, error)
NewIssuerFromPEMWithPassword will take a private key PEM with a password and derive the private key from it.
func (*Issuer) Issue ¶
Issue will sign a JWT and return its string representation.
Example ¶
claims := jwt.StandardClaims{ Id: "1234", Issuer: "Tests", Audience: "Developers", Subject: "Example", ExpiresAt: time.Now().Add(24 * time.Hour).Unix(), IssuedAt: time.Now().Unix(), NotBefore: time.Now().Unix(), } raw, err := issuer.Issue(&claims) if err != nil { return } fmt.Println(raw)
Output:
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser represents a set of methods for parsing and validating a JWT against a public key
func NewParser ¶
func NewParser(pk crypto.PublicKey, fn PublicKeyFunc) *Parser
NewParser returns a new parser with a public key.
func NewParserFromPEM ¶ added in v0.21.0
func NewParserFromPEM(key []byte, fn PublicKeyFunc) (*Parser, error)
NewParserFromPEM will take a PEM and derive the public key from it and instantiate a parser.
type PublicKeyFunc ¶ added in v0.21.0
PublicKeyFunc is used to parse tokens using a public key.
type RSAPublicKeyCopierRenewer ¶
RSAPublicKeyCopierRenewer represents the combination of a Copier and Renewer interface