Tuesday 23 January 2018

Help - Having trouble relating an oauth access token to local user account when using Angular

Specifically for instagram... I can't find a way to connect the local username (which is unique in the database and is not related to the instagram username) to the instagram access token provided in the instagram redirect_uri. I want either to save the access token in the user model, or just pass it to the angular component so I can fetch that users images. I've been considering using angular universal which can render the pages from the server and I can pass the token in that way, but I was hoping there is something easier. I've tried cookies, sessions but they won't work as the redirect_uri request is made by instagram to your server not by the user. Maybe I'm missing something. Alternatively I also thought about making a non angular page just to get the instagram token and save it in the model which can then be used by the angular component.Thanks, any help appreciated!I'm using npm instagram-node (http://ift.tt/1FrVvW5) to assist with the api calls.This is my instagram component typescript function that runs when the "Connect instagram" button is clickedthis.http.get('http://ift.tt/2rvTaJH => { window.location.href = data.url }) This is in app.js//instagram exports.authorize_user = function(req, res) { res.redirect(api.get_authorization_url(redirect_uri, { scope: ['likes'], state: 'a state' })); }; exports.handleauth = function(req, res) { console.log('req user in handlauth'); console.log(req.user) api.authorize_user(req.query.code, redirect_uri, function(err, result) { if (err) { console.log(err.body); res.send("Didn't work"); } else { console.log('Yay! Access token is ' + result.access_token); res.send('You made it!!'); } }); }; //authorize isnta link app.get('/auth/social/ig', exports.authorize_user); // This is your redirect URI app.get('/oauth/done', exports.handleauth);

Submitted January 23, 2018 at 08:47PM by are_videos

No comments:

Post a Comment