javascript - Can I use jwcrypto to validate a Google generated OAuth2 id_token? -


building on work in question: what proper way validate google granted oauth tokens in node.js server?

can use jwcrypto library validate google oauth2 token in node.js server? have 857 byte token given google, validates using google's web endpoint @ https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=. in theory can use token plus google's certs available here this:

{ 859c1234d08e008cc261ff11de5f8da1b8c4d490: "-----begin certificate----- <stuff> -----end certificate----- ", ad2a50cb70c5da789ee26d05b8f621a99e81202e: "-----begin certificate----- <stuff> -----end certificate----- " } 

so far i've been unable load keys jwcrypto using loadpublickey method. presumably once working can call verify method. there working examples of online?

i've added new npm modules decodes , validates google's id_token. can find code here: https://github.com/gmelika/google-id-token

usage straightforward:

var googleidtoken = require('google-id-token'); var parser = new googleidtoken({ getkeys: getgooglecerts }); parser.decode(samplegoogleidtoken, function(err, token) {     if(err) {         console.log("error while parsing google token: " + err);     } else {         console.log("parsed id_token is:\n" + json.stringify(token));     } }); 

the getgooglecerts function referenced above user supplied function return appropriate google certificate based on supplied key. basic example of is:

var request = require('request'); function getgooglecerts(kid, callback) {     request({uri: 'https://www.googleapis.com/oauth2/v1/certs'}, function(err, response, body){         if(err && response.statuscode !== 200) {             err = err || "error while retrieving google certs";             console.log(err);             callback(err, {})         } else {             var keys = json.parse(body);             callback(null, keys[kid]);         }     }); } 

obviously want add caching in there. feel free use favorite caching mechanism that.

hope helps.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -