Encoding JWTs
jwt-authn
Encoding a JWT
jwtEncode(header, payload, key[, options])
where options contains:
- keyFormat - format of the rs256 private key
- passphrase - if using an encrypted private key, passphrase is also required
*Encoding example taken from RFC 7515 JSON Web Signature (JWS).
import * as jwtAuthn from "jwt-authn";
jwt.jwtEncode(
'{"typ":"JWT",\r\n "alg":"HS256"}',
'{"iss":"joe",\r\n "exp":1300819380,\r\n "http://example.com/is_root":true}',
'AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow'
);
// returns
"eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"