Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpatrick committed Feb 18, 2020
1 parent 31177e3 commit d122f08
Show file tree
Hide file tree
Showing 11 changed files with 560 additions and 389 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
key: npm-packages-{{ checksum "package-lock.json" }}
paths:
- ./node_modules
- run:
name: Run Linter
command: npm run lint
- run:
name: Run Tests
command: npm run test:ci
Expand Down
14 changes: 8 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"parser": "babel-eslint",
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"generators": true,
"modules": true
"parserOptions": {
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"generators": true,
"modules": true
}
},
"rules": {
"array-bracket-spacing": [2, "always"],
Expand All @@ -31,4 +33,4 @@
"plugins": [
"babel"
]
}
}
206 changes: 186 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@types/nock": "^10.0.3",
"babel-cli": "^6.9.0",
"babel-core": "^6.9.0",
"babel-eslint": "^6.0.4",
"babel-eslint": "^8.2.6",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"chai": "^3.5.0",
Expand All @@ -43,6 +43,7 @@
"clean": "rimraf lib/",
"clean:ts": "rimraf ts-output/",
"compile": "babel -d lib/ src/",
"lint": "eslint ./src ./tests",
"prepublish": "npm run clean && npm run compile",
"test:ts": "npm run clean:ts && tsc && NODE_ENV=test mocha --require babel-core/register --exit --timeout 5000 $(find ./ts-output -name *.tests.js)",
"test:js": "NODE_ENV=test mocha --require babel-core/register --exit --timeout 5000 $(find ./tests -name *.tests.js)",
Expand All @@ -66,4 +67,4 @@
"url": "https://github.com/auth0/node-jwks-rsa/issues"
},
"homepage": "https://github.com/auth0/node-jwks-rsa#readme"
}
}
53 changes: 26 additions & 27 deletions src/JwksClient.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import debug from 'debug';
import request from 'request';

import ArgumentError from './errors/ArgumentError';
import JwksError from './errors/JwksError';
import SigningKeyNotFoundError from './errors/SigningKeyNotFoundError';

Expand Down Expand Up @@ -41,7 +40,7 @@ export class JwksClient {
strictSSL: this.options.strictSsl,
headers: this.options.requestHeaders,
agentOptions: this.options.requestAgentOptions,
proxy: this.options.proxy,
proxy: this.options.proxy
}, (err, res) => {
if (err || res.statusCode < 200 || res.statusCode >= 300) {
this.logger('Failure:', res && res.body || err);
Expand All @@ -67,32 +66,32 @@ export class JwksClient {
}

const signingKeys = keys
.filter((key) => {
if(key.kty !== 'RSA'){
return false;
}
if(!key.kid){
return false;
}
if(key.hasOwnProperty('use') && key.use !== 'sig'){
return false;
}
return ((key.x5c && key.x5c.length) || (key.n && key.e));
.filter((key) => {
if(key.kty !== 'RSA') {
return false;
}
if(!key.kid) {
return false;
}
if(key.hasOwnProperty('use') && key.use !== 'sig') {
return false;
}
return ((key.x5c && key.x5c.length) || (key.n && key.e));
})
.map(key => {
const jwk = {
kid: key.kid,
nbf: key.nbf
};
const hasCertificateChain = key.x5c && key.x5c.length;
if (hasCertificateChain){
jwk.publicKey = certToPEM(key.x5c[0]);
jwk.getPublicKey = () => jwk.publicKey;
} else {
jwk.rsaPublicKey = rsaPublicKeyToPEM(key.n, key.e);
jwk.getPublicKey = () => jwk.rsaPublicKey;
}
return jwk;
.map(key => {
const jwk = {
kid: key.kid,
nbf: key.nbf
};
const hasCertificateChain = key.x5c && key.x5c.length;
if (hasCertificateChain) {
jwk.publicKey = certToPEM(key.x5c[0]);
jwk.getPublicKey = () => jwk.publicKey;
} else {
jwk.rsaPublicKey = rsaPublicKeyToPEM(key.n, key.e);
jwk.getPublicKey = () => jwk.rsaPublicKey;
}
return jwk;
});

if (!signingKeys.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/integrations/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports.passportJwtSecret = (options) => {
const onError = options.handleSigningKeyError || handleSigningKeyError;

return function secretProvider(req, rawJwtToken, cb) {
const decoded = jwt.decode(rawJwtToken, { complete: true })
const decoded = jwt.decode(rawJwtToken, { complete: true });

// Only RS256 is supported.
if (!decoded || !decoded.header || decoded.header.alg !== 'RS256') {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export function rsaPublicKeyToPEM(modulusB64, exponentB64) {
const der = new Buffer(encodedPubkey, 'hex')
.toString('base64');

let pem = `-----BEGIN RSA PUBLIC KEY-----\n`;
let pem = '-----BEGIN RSA PUBLIC KEY-----\n';
pem += `${der.match(/.{1,64}/g).join('\n')}`;
pem += `\n-----END RSA PUBLIC KEY-----\n`;
pem += '\n-----END RSA PUBLIC KEY-----\n';
return pem;
};
Loading

0 comments on commit d122f08

Please sign in to comment.