v1.2.9: bugfix RSA hash type

This commit is contained in:
AJ ONeal 2019-03-08 15:24:52 -07:00
parent 083cc6d73e
commit e04557c84a
3 changed files with 6 additions and 6 deletions

View File

@ -154,9 +154,9 @@ Keypairs.signJwt = function (opts) {
var header = opts.header || {};
var claims = JSON.parse(JSON.stringify(opts.claims || {}));
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)) {
claims.iat = undefined;
} else if (!claims.iat) {
@ -197,7 +197,7 @@ Keypairs.signJws = function (opts) {
if (!opts.jwk) {
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) {

View File

@ -1,6 +1,6 @@
{
"name": "keypairs",
"version": "1.2.8",
"version": "1.2.9",
"description": "Lightweight RSA/ECDSA keypair generation and JWK <-> PEM",
"main": "keypairs.js",
"files": [

View File

@ -90,7 +90,7 @@ Keypairs.parseOrGenerate({ key: '' }).then(function (pair) {
if ('NOERR' === e.code) { throw e; }
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 now = Math.round(Date.now()/1000);
var token = {