v1.2.9: bugfix RSA hash type
This commit is contained in:
parent
083cc6d73e
commit
e04557c84a
|
@ -154,9 +154,9 @@ Keypairs.signJwt = function (opts) {
|
||||||
var header = opts.header || {};
|
var header = opts.header || {};
|
||||||
var claims = JSON.parse(JSON.stringify(opts.claims || {}));
|
var claims = JSON.parse(JSON.stringify(opts.claims || {}));
|
||||||
header.typ = 'JWT';
|
header.typ = 'JWT';
|
||||||
if (!header.kid) {
|
|
||||||
header.kid = thumb;
|
if (!header.kid) { header.kid = thumb; }
|
||||||
}
|
if (!header.alg && opts.alg) { header.alg = opts.alg; }
|
||||||
if (!claims.iat && (false === claims.iat || false === opts.iat)) {
|
if (!claims.iat && (false === claims.iat || false === opts.iat)) {
|
||||||
claims.iat = undefined;
|
claims.iat = undefined;
|
||||||
} else if (!claims.iat) {
|
} else if (!claims.iat) {
|
||||||
|
@ -197,7 +197,7 @@ Keypairs.signJws = function (opts) {
|
||||||
if (!opts.jwk) {
|
if (!opts.jwk) {
|
||||||
throw new Error("opts.jwk must exist and must declare 'typ'");
|
throw new Error("opts.jwk must exist and must declare 'typ'");
|
||||||
}
|
}
|
||||||
return ('RSA' === opts.jwk.typ) ? "RS256" : "ES256";
|
return ('RSA' === opts.jwk.kty) ? "RS256" : "ES256";
|
||||||
}
|
}
|
||||||
|
|
||||||
function sign(pem) {
|
function sign(pem) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "keypairs",
|
"name": "keypairs",
|
||||||
"version": "1.2.8",
|
"version": "1.2.9",
|
||||||
"description": "Lightweight RSA/ECDSA keypair generation and JWK <-> PEM",
|
"description": "Lightweight RSA/ECDSA keypair generation and JWK <-> PEM",
|
||||||
"main": "keypairs.js",
|
"main": "keypairs.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|
2
test.js
2
test.js
|
@ -90,7 +90,7 @@ Keypairs.parseOrGenerate({ key: '' }).then(function (pair) {
|
||||||
if ('NOERR' === e.code) { throw e; }
|
if ('NOERR' === e.code) { throw e; }
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
, Keypairs.signJwt({ jwk: pair.private, iss: 'https://example.com/', exp: '1h' }).then(function (jwt) {
|
, Keypairs.signJwt({ jwk: pair.private, alg: 'ES512', iss: 'https://example.com/', exp: '1h' }).then(function (jwt) {
|
||||||
var parts = jwt.split('.');
|
var parts = jwt.split('.');
|
||||||
var now = Math.round(Date.now()/1000);
|
var now = Math.round(Date.now()/1000);
|
||||||
var token = {
|
var token = {
|
||||||
|
|
Loading…
Reference in New Issue