Authentication for the Jawbone API using OAuth 2.0
npm install jawbone-oauth2
var JawboneClient = require('jawbone-oauth2');
var jawboneAuth = new JawboneClient('clientID', 'clientSecret', 'options');
- clientID: ID given to you when you register your app on Jawbone
- clientSecret: secret given to you when you register your app on Jawbone
- options: specify a certain redirect_uri or scope
app.get('/auth/jawbone', function(req, res) {
var redirectUri = 'http://someredirecturi/auth/jawbone/callback';
// Define data that you want to get back in the scope of your request to Jawbone
var scope = 'basic_read extended_read move_read sleep_read weight_read heartrate_read';
var authorizationUri = jawboneAuth.getAuthorizationUrl(redirectUri, scope);
res.redirect(authorizationUri);
});
app.get('/auth/jawbone/callback', function(req, res, done) {
var code = req.query.code;
jawboneAuth.getToken(code, redirectUri)
.then(function(token) {
// do something
})
.catch(function(err) {
// handle error
});
});
Special thanks to thegameofcode for their fitbit-client-oauth2 as inspiration.