Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable usage of other jsonwebtoken options when verifying Azure AD JWTs #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ const getPem = require('rsa-pem-from-mod-exp');
const publicKeys = {};

// Validate the jwt Token with the audience and the issuer
const verifyJwt = function verifyJwt(jwtToken, publicKey, aud, iss) {
const verifyJwt = function verifyJwt(jwtToken, publicKey, aud, iss, options) {
return new BbPromise(function (resolve, reject) {
jwt.verify(jwtToken, publicKey, { algorithms: ['RS256'], audience: aud, issuer: iss },
const jwtConfig = Object.assign(
{
algorithms: ['RS256'],
audience: aud,
issuer: iss,
},
options
Copy link
Collaborator

@AshanFernando AshanFernando May 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here don't we need to handle the case if options become undefined?

)
jwt.verify(jwtToken, publicKey, jwtConfig,
function (error, decoded) {
if (!error) {
resolve(decoded);
Expand Down Expand Up @@ -76,7 +84,7 @@ exports.verify = function (jwtToken, config) {
getPublicKeys(config.JWK_URI, jwtKid).then(function (response) {
if (hasPublicKey(jwtKid)) {
let publicKey = getPublicKey(jwtKid);
return verifyJwt(jwtToken, publicKey, config.AUD, config.ISS).then(function (response) {
return verifyJwt(jwtToken, publicKey, config.AUD, config.ISS, config.options).then(function (response) {
resolve(JSON.stringify({ "status": "success", "message": response }));
}).catch(function (error) {
reject(JSON.stringify({ "status": "error", "message": error }));
Expand Down