strongloop / loopback-example-passport

LoopBack example for facebook login
Other
185 stars 134 forks source link

how to get the accessToken? #19

Closed dstroot closed 10 years ago

dstroot commented 10 years ago

Having a hell of a time figuring out how to get the accessToken so after my user is authenticated I can hit the api and do stuff. Tried:

    console.log('Token: ' + req.accessToken);

    if (req.headers && req.headers.access_token) {
      tokenId = req.headers.access_token;
      console.log('Token: ' + tokenId);
    }

    var AccessToken = app.models.AccessToken;
    AccessToken.findForRequest(req, {}, function (err, token) {
      if (err) {
        req.flash('error', { msg: 'Sorry, something went wrong! ' + err.message });
        return res.redirect('back');
      }
      console.log('Token: ' + token);
    });
dstroot commented 10 years ago

Once I enabled the cookieParser all of these approaches worked:

    console.log('Token: ' + req.accessToken.id);
    console.log('Good Tok: ' + req.signedCookies.access_token);

    // Find a token for the given ServerRequest.
    var AccessToken = app.models.AccessToken;
    AccessToken.findForRequest(req, {}, function (err, token) {
      if (err) {
        req.flash('error', { msg: 'Sorry, something went wrong! ' + err.message });
        return res.redirect('back');
      }
      console.log('Token2: ' + token.id);
    });