jwt.signer
import jwt
Everything here is re-exported by
jwt, soimport jwtis enough and the names are called asjwt.*. Importingjwt.signeron its own works too and reaches the same definitions.
Signer, a reusable configured wrapper around core.sign().
Classes
Signer
class jwt.Signer
A reusable token signer that holds a fixed secret and set of default signing options.
Using a Signer instance is recommended when the same signing configuration is used throughout an application. Default options can be overridden on individual sign() calls.
Example
import jwt
var signer = jwt.Signer('my-secret', {
algorithm: jwt.HS256,
expires_in: 900,
issuer: 'auth.example.com',
audience: 'api.example.com',
})
var token = signer.sign({ user_id: 7, role: 'admin' })
Constructor
jwt.Signer(secret, options)
Parameters
secret(string) — The secret or PEM private key used for signing.options(dict) — Default signing options (see sign() for reference).
Signer.sign()
jwt.Signer.sign(payload, options) -> string
Signs the given payload using the secret and default options bound to this Signer, returning a token string.
Options passed here are merged with the instance defaults, with per-call options taking precedence.
Parameters
payload(dict)options(dict) — Optional per-call option overrides.
Returns string
Raises AlgorithmError
Raises JwtError