Skip to content

Commit

Permalink
catch errors from invalid crypto.sign
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed May 28, 2020
1 parent 5e00fb5 commit 5702a71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
printWidth: 160,
tabWidth: 4,
singleQuote: true
singleQuote: true,
endOfLine: 'lf',
trailingComma: 'none',
arrowParens: 'avoid',
};
12 changes: 7 additions & 5 deletions lib/xoauth2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ class XOAuth2 extends Stream {
iat,
exp: iat + this.options.serviceRequestTimeout
};
let token = this.jwtSignRS256(tokenData);
let token;
try {
token = this.jwtSignRS256(tokenData);
} catch (err) {
return callback(new Error('Can\x27t generate token. Check your auth options'));
}

urlOptions = {
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
Expand Down Expand Up @@ -355,10 +360,7 @@ class XOAuth2 extends Stream {
*/
jwtSignRS256(payload) {
payload = ['{"alg":"RS256","typ":"JWT"}', JSON.stringify(payload)].map(val => this.toBase64URL(val)).join('.');
let signature = crypto
.createSign('RSA-SHA256')
.update(payload)
.sign(this.options.privateKey);
let signature = crypto.createSign('RSA-SHA256').update(payload).sign(this.options.privateKey);
return payload + '.' + this.toBase64URL(signature);
}
}
Expand Down

0 comments on commit 5702a71

Please sign in to comment.