Testing JWT created by Auth0

node v8.16.2
version: master
endpointsharetweet
var jwt = require("jsonwebtoken") // HS256 /* var token='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3RvcGl4LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHw1YmJjZmVhYjY4YTU2YzRjNTEzMjIyM2MiLCJhdWQiOlsiaHR0cHM6Ly90b3BpeC5pby90ZXN0Il0sImlhdCI6MTUzOTQ3NTQ5NSwiZXhwIjoxNTM5NDgyNjk1LCJhenAiOiJTaWNWUUlQRFJqQ2t2WVFFaTQ2bFNJWFhUeVllc1RJWCIsInNjb3BlIjoib3BlbmlkIHByb2ZpbGUifQ.p9VPXiKqD4zFcKAoq112dV3FIyoHncAi0UytOJaPs2c'; */ var token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlEwUXpNVU5ETmtKRk4wRTJNVVE1TXpORk9EQkVSVFZDTXpGQk1VWkJPRVJHTkRaQ05UZENNZyJ9.eyJpc3MiOiJodHRwczovL3RvcGl4LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHw1YmJjZmVhYjY4YTU2YzRjNTEzMjIyM2MiLCJhdWQiOlsiaHR0cHM6Ly90b3BpeC9hcGkvcGFyc2UiLCJodHRwczovL3RvcGl4LmF1dGgwLmNvbS91c2VyaW5mbyJdLCJpYXQiOjE1Mzk2MTkxNzYsImV4cCI6MTUzOTYyNjM3NiwiYXpwIjoiU2ljVlFJUERSakNrdllRRWk0NmxTSVhYVHlZZXNUSVgiLCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIn0.RWJLpXy3jk2yfNrBezxEJirnbdjM9kQIFhXwWw2Oz8FWH89z76mdoa3nhb2zdkJLufZJyl6MYDFcyyxXdF94z1C3gHoGsCstKVTmf4fsIlnA1ANh_B5gX-NITxPMgHXCahC5Z8Z8n4rcbCUWgwkra9k1mijcEz_KY63DmglZ6YkB4pWJJB3an9gcK0GyPfuMZn98cDMkAMcKJB5iMaXnRPljc2pwodagGzp2ML_AGhgwWChLGo_8A8_Juys_MqbkDG0wkGMSeFRH3YRgG4_Lfv_mlA4cacVlz7vOczKwte2e6WAGzRjR7dbDv_IpaHcUa4pnRCQfJkR5WMa2-fzYYw"; // This is the "Signing Secret" obtained from Auth0 for the test API var key = 'cE9d0Vy07dFxD3SOnpiAYLwwkDno7ZB6' // Sync version: First try without specifying alg try { var decoded = jwt.verify(token, key) console.log("Decoded: "+decoded) } catch(err){ console.log("Verify: Sync test 1: " +err.message); } // Need a PEM cert to test this /* try { var decoded = jwt.verify(token, cert, { algorithms: ['RS256'] }) } catch(err){ console.log("Verify: Sync test 2: " +err.message); } */ // Try async version jwt.verify(token, key, function(err, decoded) { if (!err) { console.log('Verify: Async test 1: Audience decoded: ' +decoded.aud) } else { console.log("Verify: Async test 1: "+ err.message); } }); // Now just decode without signature verification try { var decoded = jwt.decode(token,{complete: true, json: true}); console.log('Decode Only: '+ JSON.stringify(decoded)); } catch(err){ console.log(err.message); }
Loading…

no comments

    sign in to comment