D
D
Dmitry2015-05-06 15:04:42
Node.js
Dmitry, 2015-05-06 15:04:42

Why doesn't VK authentication through passport-vkontakte always work?

Set up authentication through Vkontakte using passport-vkontakte. Authentication works, but quite often an error occurs.. I noticed the following kinds of errors:

InternalOAuthError: failed to fetch user profile
    at /home/www/workspace/node_modules/passport-vkontakte/lib/passport-vkontakte/strategy.js:144:28
    at ClientRequest.<anonymous> (/home/www/workspace/node_modules/passport-vkontakte/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:148:5)
    at ClientRequest.emit (events.js:107:17)
    at TLSSocket.socketErrorListener (_http_client.js:272:9)
    at TLSSocket.emit (events.js:129:20)
    at net.js:451:14
    at process._tickCallback (node.js:355:11)


InternalOAuthError: Failed to obtain access token
    at Strategy.OAuth2Strategy._createOAuthError (/home/www/workspace/node_modules/passport-vkontakte/node_modules/passport-oauth2/lib/strategy.js:349:17)
    at /home/www/workspace/node_modules/passport-vkontakte/node_modules/passport-oauth2/lib/strategy.js:171:43
    at /home/www/workspace/node_modules/passport-vkontakte/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:177:18
    at ClientRequest.<anonymous> (/home/www/workspace/node_modules/passport-vkontakte/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:148:5)
    at ClientRequest.emit (events.js:107:17)
    at TLSSocket.socketErrorListener (_http_client.js:272:9)
    at TLSSocket.emit (events.js:129:20)
    at net.js:451:14
    at process._tickCallback (node.js:355:11)

nothing special about the code
VKontakteStrategy = require('passport-vkontakte').Strategy
...
passport.use(new VKontakteStrategy({
      clientID:     VKONTAKTE_APP_ID, // VK.com docs call it 'API ID'
      clientSecret: VKONTAKTE_APP_SECRET,
      callbackURL:  "https://local/workspace/auth/vkontakte/callback/"
    },
    function(accessToken, refreshToken, profile, done) {
      console.log(profile);
    });
    });

app.get('/auth/vkontakte', passport.authenticate('vkontakte', { 
    successRedirect: '/workspace/', 
    failureRedirect: '/error'
    //scope: ['email'] 
  }));
  
  app.get('/auth/vkontakte/callback/',
      passport.authenticate('vkontakte', { 
        failureRedirect: '/workspace/auth/vkontakte'
        //scope: ['email'] 
      }),
        function(req, res) {
    console.log("[OAuth2:redirect:query]:", JSON.stringify(req.query));
      console.log("[OAuth2:redirect:body]:", JSON.stringify(req.body))
          // Successful authentication, redirect home.
          res.redirect('workspace/');
        });

In parallel, authentication through Facebook is used - it works without failures. The FB and VK designs are completely identical.
The error occurs chaotically .. I couldn’t track the dependencies .. It works - it doesn’t ..
Actually, because of what VKontakte authentication can mess up?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2015-05-07
@falcon_sapsan

Got an answer on github
If it's random, then it's most likely a VK issue. Can't help you there.
Be prepared to handle auth errors in your app, because they can and will happen.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question