I am trying to get the access_token for a user using the FB API + everyauth module for NodeJS, and then I will make serverside graph API requests using the Facebook_Graph_API module to actually make the requests (which requires an access token).
According to the everyauth page:
Then, from within your views, you will have access to the following helpers methods attached to the helper,
everyauth:
everyauth.loggedIneveryauth.user- the User document associated with the sessioneveryauth.facebook- The is equivalent to what is stored atreq.session.auth.facebook, so you can do things like ...everyauth.facebook.user- returns the user json provided from the OAuth provider.everyauth.facebook.accessToken- returns the access_token provided from the OAuth provider for authorized API calls on behalf of the user.- And you also get this pattern for other modules - e.g.,
everyauth.twitter.user,everyauth.github.user, etc.
Within my .jade templates I can make the requests just fine:
- if (everyauth.facebook)
h3 Facebook User Data
p= JSON.stringify(everyauth.facebook.user)
p= 'facebook access token is '+ everyauth.facebook.accessToken
My question is, how can I fetch the access token from the server-side javascript? I noticed that within
app.get('/', function (req, res) {
res.render('home');
console.log(req.sessionStore.sessions.);
});
the req object does contain the access_token value but the corresponding JSON is very unwieldy to parse and not really practical for dozens of APIs. Is there any way I can simply retrieve the access_token from the server using everyauth?
Hypothetically I could simply use a bit of AJAX and send everyauth.facebook.accessToken back to the server from the client but I feel like this is somewhat impractical.
This section answered your question:
https://github.com/bnoguchi/everyauth/blob/master/README.md#accessing-the-user