New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added mixer provider #314
Closed
Closed
Added mixer provider #314
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
aa0b722
added mixer as provider
2e8f760
forgot to add the provider to the list...
967d1e9
commented the example
c75efc3
es6 to es5, because reasons.
4f44ac3
used tabs instead of spaces >.<
c9c19ab
fixed travis-ci error reports
32b8195
forgot an semicolon.. >.<
dec892a
removed scopeSeperator and added missing semicolon (again...)
48c4a6e
added unit test
edabc56
tests fixes
888c6b9
removed yarn.lock and added an entry to the .gitignore
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ config.json | |
coverage.* | ||
lib-cov | ||
complexity.md | ||
yarn.lock |
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,54 @@ | ||
'use strict'; | ||
|
||
// Load modules | ||
|
||
const Hapi = require('hapi'); | ||
const Hoek = require('hoek'); | ||
const Bell = require('../'); | ||
|
||
|
||
const server = new Hapi.Server(); | ||
server.connection({ | ||
port: 8000 | ||
}); | ||
|
||
server.register(Bell, (err) => { | ||
|
||
Hoek.assert(!err, err); | ||
server.auth.strategy('mixer', 'bell', { | ||
provider: 'mixer', | ||
password: 'cookie_encryption_password_secure', | ||
isSecure: false, | ||
/** | ||
* you need to register your OAuth client here: https://mixer.com/lab/oauth | ||
* for all scopes see https://dev.mixer.com/reference/oauth/index.html#oauth_scopes | ||
*/ | ||
clientId: '', | ||
clientSecret: '' | ||
// Uncomment the below line for more scopes (check Mixer API documentation), "user:details:self" scope is set as default | ||
// scope: ['user:details:self'] | ||
}); | ||
|
||
server.route({ | ||
method: ['GET', 'POST'], | ||
path: '/bell/door', | ||
config: { | ||
auth: 'mixer', | ||
handler: function (request, reply) { | ||
|
||
if (!request.auth.isAuthenticated) { | ||
return reply('Authentication failed due to: ' + request.auth.error.message); | ||
} | ||
|
||
reply('<pre>' + JSON.stringify(request.auth.credentials, null, 4) + '</pre>'); | ||
|
||
} | ||
} | ||
}); | ||
|
||
server.start((err) => { | ||
|
||
Hoek.assert(!err, err); | ||
console.log('Server started at:', server.info.uri); | ||
}); | ||
}); |
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,32 @@ | ||
'use strict'; | ||
|
||
exports = module.exports = function (options) { | ||
|
||
options = options || {}; | ||
|
||
const uri = options.uri || 'https://mixer.com'; | ||
const user = options.uri ? options.uri + '/api/v1/users/current' : 'https://mixer.com/api/v1/users/current'; | ||
|
||
return { | ||
protocol: 'oauth2', | ||
auth: uri + '/oauth/authorize', | ||
token: uri + '/api/v1/oauth/token', | ||
scope: ['user:details:self'], | ||
useParamsAuth: true, | ||
headers: { 'User-Agent': 'hapi-bell-mixer' }, | ||
profile: function (credentials, params, get, callback) { | ||
|
||
get(user, null, (profile) => { | ||
|
||
credentials.profile = { | ||
id: profile.id, | ||
username: profile.username, | ||
email: profile.email, | ||
raw: profile | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
'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('mixer', () => { | ||
|
||
it('authenticates with moch', { 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.mixer(); | ||
Hoek.merge(custom, provider); | ||
|
||
const profile = { | ||
id: '1234567890', | ||
username: 'jerome724', | ||
email: 'jerome724@example.com' | ||
}; | ||
|
||
Mock.override('https://mixer.com/api/v1/users/current', profile); | ||
|
||
server.auth.strategy('custom', 'bell', { | ||
password: 'cookie_encryption_password_secure', | ||
isSecure: false, | ||
clientId: 'mixer', | ||
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 } }, (response) => { | ||
|
||
Mock.clear(); | ||
expect(response.result).to.equal({ | ||
provider: 'custom', | ||
token: '456', | ||
expiresIn: 3600, | ||
refreshToken: undefined, | ||
query: {}, | ||
profile: { | ||
id: '1234567890', | ||
username: 'jerome724', | ||
email: 'jerome724@example.com', | ||
raw: profile | ||
} | ||
}); | ||
mock.stop(done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it('authenticates with moch and custom uri', { 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.exists(); | ||
|
||
const custom = Bell.providers.mixer({ uri: 'http://example.com' }); | ||
Hoek.merge(custom, provider); | ||
|
||
const profile = { | ||
id: '1234567890', | ||
username: 'jerome724', | ||
email: 'jerome724@example.com' | ||
}; | ||
|
||
Mock.override('http://example.com/api/v1/users/current', profile); | ||
|
||
server.auth.strategy('custom', 'bell', { | ||
password: 'cookie_encryption_password_secure', | ||
isSecure: false, | ||
clientId: 'mixer', | ||
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 } }, (response) => { | ||
|
||
Mock.clear(); | ||
expect(response.result).to.equal({ | ||
provider: 'custom', | ||
token: '456', | ||
expiresIn: 3600, | ||
refreshToken: undefined, | ||
query: {}, | ||
profile: { | ||
id: '1234567890', | ||
username: 'jerome724', | ||
email: 'jerome724@example.com', | ||
raw: profile | ||
} | ||
}); | ||
|
||
mock.stop(done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably just be: