Skip to content
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

Support returning raw resource payload. Closes #193 #194

Merged
merged 1 commit into from Mar 4, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -401,9 +401,11 @@ internals.Client.prototype._request = function (method, uri, params, oauth, opti
return callback(Boom.internal('Failed obtaining ' + this.provider + ' ' + desc, payload), payload, res.statusCode);
}

payload = internals.parse(payload);
if (payload instanceof Error) {
return callback(Boom.internal('Received invalid payload from ' + this.provider + ' ' + desc + ' endpoint', payload), payload, res.statusCode);
if (!options.raw) {
payload = internals.parse(payload);
if (payload instanceof Error) {
return callback(Boom.internal('Received invalid payload from ' + this.provider + ' ' + desc + ' endpoint', payload), payload, res.statusCode);
}
}

return callback(null, payload, res.statusCode);
@@ -1,7 +1,7 @@
{
"name": "bell",
"description": "Third-party login plugin for hapi",
"version": "7.0.0",
"version": "7.1.0",
"repository": "git://github.com/hapijs/bell",
"main": "lib/index.js",
"keywords": [
@@ -37,7 +37,7 @@
"boom": "3.x.x",
"cryptiles": "3.x.x",
"hoek": "3.x.x",
"joi": "7.x.x",
"joi": "8.x.x",
"wreck": "7.x.x"
},
"peerDependencies": {
@@ -607,7 +607,6 @@ describe('Bell', () => {
});
});


it('passes if isSecure is true when protocol is https (forced)', (done) => {

const mock = new Mock.V1();
@@ -872,6 +871,69 @@ describe('Bell', () => {
});
});

it('returns raw resource response', { parallel: false }, (done) => {

const mock = new Mock.V1();
mock.start((provider) => {

const server = new Hapi.Server();
server.connection({ host: 'localhost', port: 80 });
server.register(Bell, (err) => {

expect(err).to.not.exist();

server.auth.strategy('custom', 'bell', {
password: 'cookie_encryption_password_secure',
isSecure: false,
clientId: 'test',
clientSecret: 'secret',
provider: provider
});

server.route({
method: '*',
path: '/login',
config: {
auth: 'custom',
handler: function (request, reply) {

const client = new Bell.oauth.Client({
name: 'twitter',
provider: provider,
clientId: 'test',
clientSecret: 'secret'
});

const credentials = request.auth.credentials;
client.resource('POST', mock.uri + '/resource', { a: 5 }, { token: credentials.token, secret: credentials.secret, raw: true }, (err, res) => {

expect(err).to.not.exist();
return reply(res);
});
}
}
});

server.inject('/login?next=%2Fhome', (res) => {

const cookie = res.headers['set-cookie'][0].split(';')[0] + ';';
expect(res.headers.location).to.equal(mock.uri + '/auth?oauth_token=1');

mock.server.inject(res.headers.location, (mockRes) => {

expect(mockRes.headers.location).to.equal('http://localhost:80/login?oauth_token=1&oauth_verifier=123');

server.inject({ url: mockRes.headers.location, headers: { cookie: cookie } }, (response) => {

expect(response.result).to.equal('{"a":"5"}');
mock.stop(done);
});
});
});
});
});
});

it('returns resource POST response', { parallel: false }, (done) => {

const mock = new Mock.V1();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.