-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Fitbit provider (#240)""
This reverts commit edf25dd.
- Loading branch information
Showing
6 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
exports = module.exports = function (options) { | ||
|
||
return { | ||
protocol: 'oauth2', | ||
useParamsAuth: false, | ||
auth: 'https://www.fitbit.com/oauth2/authorize', | ||
token: 'https://api.fitbit.com/oauth2/token', | ||
scope: ['activity','profile'], //see https://dev.fitbit.com/docs/oauth2/#scope | ||
profile: function (credentials, params, get, callback) { | ||
|
||
get('https://api.fitbit.com/1/user/-/profile.json', null, (profile) => { | ||
|
||
credentials.profile = { | ||
id: profile.user.encodedId, | ||
displayName: profile.user.displayName, | ||
name: profile.user.fullName | ||
}; | ||
|
||
return callback(); | ||
}); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"bitbucket", | ||
"dropbox", | ||
"facebook", | ||
"fitbit", | ||
"foursquare", | ||
"github", | ||
"gitlab", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
'use strict'; | ||
|
||
// Load modules | ||
|
||
const Bell = require('../../'); | ||
const Code = require('code'); | ||
const Hapi = require('hapi'); | ||
const Hoek = require('hoek'); | ||
const Lab = require('lab'); | ||
const Mock = require('../mock'); | ||
|
||
|
||
// Test shortcuts | ||
|
||
const lab = exports.lab = Lab.script(); | ||
const describe = lab.describe; | ||
const it = lab.it; | ||
const expect = Code.expect; | ||
|
||
|
||
describe('fitbit', () => { | ||
|
||
it('authenticates with mock', { parallel: false }, (done) => { | ||
|
||
const mock = new Mock.V2(); | ||
mock.start((provider) => { | ||
|
||
const server = new Hapi.Server(); | ||
server.connection({ host: 'localhost', port: 80 }); | ||
server.register(Bell, (err) => { | ||
|
||
expect(err).to.not.exist(); | ||
|
||
const custom = Bell.providers.fitbit(); | ||
Hoek.merge(custom, provider); | ||
|
||
const profile = { | ||
user: { | ||
encodedId: '1234', | ||
displayName: 'Steve', | ||
fullName: 'Steve Smith' | ||
} | ||
}; | ||
|
||
Mock.override('https://api.fitbit.com/1/user/-/profile.json', profile); | ||
|
||
server.auth.strategy('custom', 'bell', { | ||
password: 'cookie_encryption_password_secure', | ||
isSecure: false, | ||
clientId: 'fitbit', | ||
clientSecret: 'secret', | ||
provider: custom | ||
}); | ||
|
||
server.route({ | ||
method: '*', | ||
path: '/login', | ||
config: { | ||
auth: 'custom', | ||
handler: function (request, reply) { | ||
|
||
reply(request.auth.credentials); | ||
} | ||
} | ||
}); | ||
|
||
server.inject('/login', (res) => { | ||
|
||
const cookie = res.headers['set-cookie'][0].split(';')[0] + ';'; | ||
mock.server.inject(res.headers.location, (mockRes) => { | ||
|
||
server.inject({ url: mockRes.headers.location, headers: { cookie: cookie } }, (response) => { | ||
|
||
Mock.clear(); | ||
|
||
expect(response.result).to.equal({ | ||
provider: 'custom', | ||
token: '456', | ||
expiresIn: 3600, | ||
refreshToken: undefined, | ||
query: {}, | ||
profile: { id: '1234', displayName: 'Steve', name: 'Steve Smith' } | ||
}); | ||
|
||
mock.stop(done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |