Passing web token from backend to frontend (Node.js + Express to AngularJS)

Being relatively new to JavaScript, I am trying to implement Amazon login in Node.js + Express / Angular.js app.

Here is the piece from Node.js Passport authentication middleware example:

app.get('/auth/facebook/callback', 
  passport.authenticate('service', { session: false }),
  function(req, res) {
    // Successful authentication, redirect home.
    // I have access to web token here
    res.redirect('/');
  });

The question is how do I modify the code above to pass web token that I obtain in function(req, res) in Node.js backend to AngularJS frontend assuming my AngularJS app is hosted at http://example.com while after logging in with Amazon, the app gets redirected to http://example.com/auth/facebook/callback URL.

I'm going to assume you are using Express. As I understand it the access token will be stored somewhere in the req variable (eg. req.session.amazon....), having not used Amazon myself I'm not sure. This can then be passed to the Express renderer and included in a template.

res.render('myTemplate', {
    amazon_access_token : req.session.amazon.token // example
});

Then in your template (in this case handlebars in a file called myTemplate.hbs):

<script>
    var myAccessToken = {amazon_access_token};

    // Angular code

</script>

Alright. The first way is to set it in a cookie like below. I still would like to know what the other options are.

app.get('/auth/facebook/callback',
    passport.authenticate('facebook', {
        session: true
    }), function(req, res) {
        res.cookie('token', '1234567890', {
            maxAge: 3600000
        });
        res.redirect('/');
    }
);