How to use Jsonwebtoken NPM package to verify JWT token issued by Azure AD? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How do I return the response from an asynchronous call?Where does npm install packages?How can I update NodeJS and NPM to the next versions?Find the version of an installed npm packageJWT (JSON Web Token) automatic prolongation of expirationVerifying JWT using jsonwebtoken in node.js with a token generated by jose4j failsHow do you verify a JWT token with a x.509 certificate in node?How to verify JWT id_token produced by MS Azure AD?Do I commit the package-lock.json file created by npm 5?Using x5c cert to verify JWTAzure JWT Token Key Rotation
Split coins into combinations of different denominations
Israeli soda type drink
How would I use different systems of magic when they are capable of the same effects?
c++ diamond problem - How to call base method only once
What is the ongoing value of the Kanban board to the developers as opposed to management
What is the best argument for maximum parsimony method in phylogenetic tree construction?
Error: Syntax error. Missing ')' for CASE Statement
Is this homebrew racial feat, Stonehide, balanced?
My admission is revoked after accepting the admission offer
What is it called when you ride around on your front wheel?
Is Diceware more secure than a long passphrase?
Is accepting an invalid credit card number a security issue?
Arriving in Atlanta after US Preclearance in Dublin. Will I go through TSA security in Atlanta to transfer to a connecting flight?
AI positioning circles within an arc at equal distances and heights
Are all CP/M-80 implementations binary compatible?
401(k) cost basis
Putting Ant-Man on house arrest
Can I criticise the more senior developers around me for not writing clean code?
Is Bran literally the world's memory?
Co-worker works way more than he should
Multiple fireplaces in an apartment building?
std::is_constructible on incomplete types
Can you stand up from being prone using Skirmisher outside of your turn?
Determining the ideals of a quotient ring
How to use Jsonwebtoken NPM package to verify JWT token issued by Azure AD?
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How do I return the response from an asynchronous call?Where does npm install packages?How can I update NodeJS and NPM to the next versions?Find the version of an installed npm packageJWT (JSON Web Token) automatic prolongation of expirationVerifying JWT using jsonwebtoken in node.js with a token generated by jose4j failsHow do you verify a JWT token with a x.509 certificate in node?How to verify JWT id_token produced by MS Azure AD?Do I commit the package-lock.json file created by npm 5?Using x5c cert to verify JWTAzure JWT Token Key Rotation
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to use jsonwebtoken NPM package for verifying a JWT token issued by Azure Active Directory. Following is the node.js code that I have written:
var jwt = require('jsonwebtoken');
var token = '<valid JWT token>';
var x5cString = '<x5cSTring>';
var publicKey = '-----BEGIN CERTIFICATE-----n' + x5cString + 'n-----END CERTIFICATE-----';
var verifiedToken = jwt.verify(token, publicKey) //, verifyOptions);
Please note that in the above code I use the actual x5c String from https://login.microsoftonline.com/common/discovery/keys. This works fine and I get the expected result. But, the X5C string which is the public key keeps changing. I am trying to understand how to get this public key automatically.
EDIT
I found some sample code on Jsonwebtoken NPM package web site. In this code signingKey is what I want. Following is the code.
var jwksClient = require('jwks-rsa');
var client = jwksClient(
jwksUri: 'https://login.microsoftonline.com/common/discovery/keys'
);
function getKey(header, callback)
client.getSigningKey(header.kid, function(err, key)
var signingKey = key.publicKey );
jwt.verify(token, getKey, options, function(err, decoded)
console.log(decoded.foo) // bar
);
In the above code, jwt.verify calls getKey that takes header and callback as parameter. I do not understand how jwt.verify function passed 'header' parameter to the getKey. Following is the header that I have retrieved. how do I pass this header to getKey in the jwt.verify?
var decoded = jwt.decode(token, complete: true);
var header = decoded.header
node.js jwt
add a comment |
I am trying to use jsonwebtoken NPM package for verifying a JWT token issued by Azure Active Directory. Following is the node.js code that I have written:
var jwt = require('jsonwebtoken');
var token = '<valid JWT token>';
var x5cString = '<x5cSTring>';
var publicKey = '-----BEGIN CERTIFICATE-----n' + x5cString + 'n-----END CERTIFICATE-----';
var verifiedToken = jwt.verify(token, publicKey) //, verifyOptions);
Please note that in the above code I use the actual x5c String from https://login.microsoftonline.com/common/discovery/keys. This works fine and I get the expected result. But, the X5C string which is the public key keeps changing. I am trying to understand how to get this public key automatically.
EDIT
I found some sample code on Jsonwebtoken NPM package web site. In this code signingKey is what I want. Following is the code.
var jwksClient = require('jwks-rsa');
var client = jwksClient(
jwksUri: 'https://login.microsoftonline.com/common/discovery/keys'
);
function getKey(header, callback)
client.getSigningKey(header.kid, function(err, key)
var signingKey = key.publicKey );
jwt.verify(token, getKey, options, function(err, decoded)
console.log(decoded.foo) // bar
);
In the above code, jwt.verify calls getKey that takes header and callback as parameter. I do not understand how jwt.verify function passed 'header' parameter to the getKey. Following is the header that I have retrieved. how do I pass this header to getKey in the jwt.verify?
var decoded = jwt.decode(token, complete: true);
var header = decoded.header
node.js jwt
add a comment |
I am trying to use jsonwebtoken NPM package for verifying a JWT token issued by Azure Active Directory. Following is the node.js code that I have written:
var jwt = require('jsonwebtoken');
var token = '<valid JWT token>';
var x5cString = '<x5cSTring>';
var publicKey = '-----BEGIN CERTIFICATE-----n' + x5cString + 'n-----END CERTIFICATE-----';
var verifiedToken = jwt.verify(token, publicKey) //, verifyOptions);
Please note that in the above code I use the actual x5c String from https://login.microsoftonline.com/common/discovery/keys. This works fine and I get the expected result. But, the X5C string which is the public key keeps changing. I am trying to understand how to get this public key automatically.
EDIT
I found some sample code on Jsonwebtoken NPM package web site. In this code signingKey is what I want. Following is the code.
var jwksClient = require('jwks-rsa');
var client = jwksClient(
jwksUri: 'https://login.microsoftonline.com/common/discovery/keys'
);
function getKey(header, callback)
client.getSigningKey(header.kid, function(err, key)
var signingKey = key.publicKey );
jwt.verify(token, getKey, options, function(err, decoded)
console.log(decoded.foo) // bar
);
In the above code, jwt.verify calls getKey that takes header and callback as parameter. I do not understand how jwt.verify function passed 'header' parameter to the getKey. Following is the header that I have retrieved. how do I pass this header to getKey in the jwt.verify?
var decoded = jwt.decode(token, complete: true);
var header = decoded.header
node.js jwt
I am trying to use jsonwebtoken NPM package for verifying a JWT token issued by Azure Active Directory. Following is the node.js code that I have written:
var jwt = require('jsonwebtoken');
var token = '<valid JWT token>';
var x5cString = '<x5cSTring>';
var publicKey = '-----BEGIN CERTIFICATE-----n' + x5cString + 'n-----END CERTIFICATE-----';
var verifiedToken = jwt.verify(token, publicKey) //, verifyOptions);
Please note that in the above code I use the actual x5c String from https://login.microsoftonline.com/common/discovery/keys. This works fine and I get the expected result. But, the X5C string which is the public key keeps changing. I am trying to understand how to get this public key automatically.
EDIT
I found some sample code on Jsonwebtoken NPM package web site. In this code signingKey is what I want. Following is the code.
var jwksClient = require('jwks-rsa');
var client = jwksClient(
jwksUri: 'https://login.microsoftonline.com/common/discovery/keys'
);
function getKey(header, callback)
client.getSigningKey(header.kid, function(err, key)
var signingKey = key.publicKey );
jwt.verify(token, getKey, options, function(err, decoded)
console.log(decoded.foo) // bar
);
In the above code, jwt.verify calls getKey that takes header and callback as parameter. I do not understand how jwt.verify function passed 'header' parameter to the getKey. Following is the header that I have retrieved. how do I pass this header to getKey in the jwt.verify?
var decoded = jwt.decode(token, complete: true);
var header = decoded.header
node.js jwt
node.js jwt
edited Mar 9 at 7:53
KurioZ7
asked Mar 9 at 5:54
KurioZ7KurioZ7
2,65852343
2,65852343
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Okay so I have found out the solution. Following is the final code that I have.
var jwksClient = require('jwks-rsa');
var jwt = require('jsonwebtoken');
token = 'valid JWT token';
var decoded = jwt.decode(token, complete: true);
var header = decoded.header
var verifyOptions =
algorithms: ['RS256'],
header: decoded.header
;
var client = jwksClient(
jwksUri: 'https://login.microsoftonline.com/common/discovery/keys'
);
function getKey(header, callback)
client.getSigningKey(header.kid, function(err, key) );
jwt.verify(token, getKey, verifyOptions, function(err, decoded)
//This will display the decoded JWT token.
console.log(decoded)
);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074443%2fhow-to-use-jsonwebtoken-npm-package-to-verify-jwt-token-issued-by-azure-ad%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Okay so I have found out the solution. Following is the final code that I have.
var jwksClient = require('jwks-rsa');
var jwt = require('jsonwebtoken');
token = 'valid JWT token';
var decoded = jwt.decode(token, complete: true);
var header = decoded.header
var verifyOptions =
algorithms: ['RS256'],
header: decoded.header
;
var client = jwksClient(
jwksUri: 'https://login.microsoftonline.com/common/discovery/keys'
);
function getKey(header, callback)
client.getSigningKey(header.kid, function(err, key) );
jwt.verify(token, getKey, verifyOptions, function(err, decoded)
//This will display the decoded JWT token.
console.log(decoded)
);
add a comment |
Okay so I have found out the solution. Following is the final code that I have.
var jwksClient = require('jwks-rsa');
var jwt = require('jsonwebtoken');
token = 'valid JWT token';
var decoded = jwt.decode(token, complete: true);
var header = decoded.header
var verifyOptions =
algorithms: ['RS256'],
header: decoded.header
;
var client = jwksClient(
jwksUri: 'https://login.microsoftonline.com/common/discovery/keys'
);
function getKey(header, callback)
client.getSigningKey(header.kid, function(err, key) );
jwt.verify(token, getKey, verifyOptions, function(err, decoded)
//This will display the decoded JWT token.
console.log(decoded)
);
add a comment |
Okay so I have found out the solution. Following is the final code that I have.
var jwksClient = require('jwks-rsa');
var jwt = require('jsonwebtoken');
token = 'valid JWT token';
var decoded = jwt.decode(token, complete: true);
var header = decoded.header
var verifyOptions =
algorithms: ['RS256'],
header: decoded.header
;
var client = jwksClient(
jwksUri: 'https://login.microsoftonline.com/common/discovery/keys'
);
function getKey(header, callback)
client.getSigningKey(header.kid, function(err, key) );
jwt.verify(token, getKey, verifyOptions, function(err, decoded)
//This will display the decoded JWT token.
console.log(decoded)
);
Okay so I have found out the solution. Following is the final code that I have.
var jwksClient = require('jwks-rsa');
var jwt = require('jsonwebtoken');
token = 'valid JWT token';
var decoded = jwt.decode(token, complete: true);
var header = decoded.header
var verifyOptions =
algorithms: ['RS256'],
header: decoded.header
;
var client = jwksClient(
jwksUri: 'https://login.microsoftonline.com/common/discovery/keys'
);
function getKey(header, callback)
client.getSigningKey(header.kid, function(err, key) );
jwt.verify(token, getKey, verifyOptions, function(err, decoded)
//This will display the decoded JWT token.
console.log(decoded)
);
answered Mar 9 at 7:54
KurioZ7KurioZ7
2,65852343
2,65852343
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074443%2fhow-to-use-jsonwebtoken-npm-package-to-verify-jwt-token-issued-by-azure-ad%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown