0

I have a single page web app in Node.js/Express and Angular.js and I need to use the Jawbone API to retrieve fitness data. In order to use their API I need to be redirected to the Jawbone website to authenticate and provide a callback URL to receive the fitness data. I'm implementing the code in the following tutorial but this is not designed as a single page app. Rather a separate route (/sleepdata) is provided for the callback which is rendered to a 'userdata.ejs' page...

app.get('/login/jawbone', 
  passport.authorize('jawbone', {
    scope: ['basic_read','sleep_read'],
    failureRedirect: '/'
  })
);

app.get('/sleepdata',
  passport.authorize('jawbone', {
    scope: ['basic_read','sleep_read'],
    failureRedirect: '/'
  }), function(req, res) {
    res.render('userdata', req.account);
  }
);

Is there a way to adapt this code so the jawbone account data can be retrieved by my Angular SPA, rather than implementing a separate route for the callback?

CSharp
  • 1,186
  • 1
  • 12
  • 33
  • I'm not familiar with this tutorial or how passport works, but you can set your callback URL to the same one that initiates the OAuth flow. The handler on that URL would just need to understand when the incoming request is the OAuth callback. You could use the presence of the code parameter in the request to differentiate. – RAY Jan 27 '17 at 16:21
  • Thanks, I would be initiating it from any number of states within my angular app though, by sending a http get request..I'm not sure how to prevent causing my angular application to break when there's a redirect. One approach I've looked into is opening a popup window or new tab when the login request is made though..this seems like it might be a solution. – CSharp Jan 31 '17 at 16:25
  • A popup would work as long as you have a way of closing it when you get the callback. By the way, this is pretty standard OAuth behavior. Is there a reason you only want a single page app? You could have a separate login page that sends the user back to your app after receiving the OAuth callback. – RAY Jan 31 '17 at 20:40

0 Answers0