L
L
loksiokda2017-09-19 19:33:22
JavaScript
loksiokda, 2017-09-19 19:33:22

Error during authorization through Passport-VK?

Good day.
The module for authorization passport-vkontakte is installed. At the first! authorization throws on the page:
site.net/auth/vk/callback?code=42aa39f9b2791ce327
At the same time, if you go to the site, the user is authorized!
And gives an error:

TokenError: Code is invalid or expired.
    at Strategy.OAuth2Strategy.parseErrorResponse (/srv/13aaa/node_modules/passport-oauth2/lib/strategy.js:320:12)
    at Strategy.parseErrorResponse (/srv/13aaaa/node_modules/passport-vkontakte/lib/passport-vkontakte/strategy.js:176:54)
    at Strategy.OAuth2Strategy._createOAuthError (/srv/13aaaa/node_modules/passport-oauth2/lib/strategy.js:367:16)
    at /srv/13aaaa/node_modules/passport-oauth2/lib/strategy.js:166:45
    at /srv/13aaaa/node_modules/oauth/lib/oauth2.js:191:18
    at passBackControl (/srv/13aaaa/node_modules/oauth/lib/oauth2.js:132:9)
    at IncomingMessage.<anonymous> (/srv/13aaaa/node_modules/oauth/lib/oauth2.js:157:7)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)

Handler code:
passport.use(new VkStrategy(
  {
    clientID: config.get('vkID'),
    clientSecret: config.get('vkSecret'),
    callbackURL: config.get('vkCb') + '/auth/vk/callback'
  },
  function verify(accessToken, refreshToken, params, profile, done) {
    process.nextTick(function () {
        return done(null, {
            userid: profile.id,
            username: profile.displayName,
            photoUrl: profile.photos[0].value,
            profileUrl: profile.profileUrl
        });
    });
  }
));

Routers:
app.get('/auth/vk', passport.authenticate('vkontakte'), function(req, res){});
   app.get('/auth/vk/undefined', passport.authenticate('vkontakte'), function(req, res){});
   app.get('/auth/vk/callback', passport.authenticate('vkontakte', { failureRedirect: '/' }), function(req, res) {
      res.redirect(req.headers.referer);
   });

What could be the problem?
And the second question - sometimes there are times when the module redirects to the /auth/vk/undefined page, I also can’t understand why.
Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question