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

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


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('/');    });