I'm trying to setup authentication using the passport-jwt strategy, but am so far having now luck. I want to pass the JWT token as a query parameter for authentication
I first tried using the passports fromUrlQueryParameter
extractor with a very simple verifier:
type: "strategy", strategy: { name: "jwt", label: 'Authenticate via JWT token', icon:"fa-cloud", strategy: require("passport-jwt").Strategy, options: { secretOrKey : "<secret>", jwtFromRequest: require('passport-jwt').ExtractJwt.fromUrlQueryParameter("token"), verify: function(jwt_payload, done) { console.log("JWT_PAYLOAD was :" + jwt_payload); return done(null, "Andrew"); } }, },
I hit http://localhost:1880/auth/strategy?token=my_valid_token and I just get bounced to a login page with a button to login. The clicking the button just lands me back at the login page. Nothing is logged from the verify function.
I thought I'd try to verify the strategy is getting invoked by replacing the extractor with my own function that includes some logging:
type: "strategy", strategy: { name: "jwt", label: 'Authenticate via JWT token', icon:"fa-cloud", strategy: require("passport-jwt").Strategy, options: { secretOrKey : "<secret>", jwtFromRequest: function(req) { console.log("jwtFromRequest called with:" + req.query.token); return req.query.token; }, verify: function(jwt_payload, done) { console.log("JWT_PAYLOAD was :" + jwt_payload); return done(null, "Andrew"); } }, },
This DOES log my token, but I still see nothing logged from the verify function and I get bounced to the login panel.
Any suggestions about what I might be doing wrong?