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

Allow environment variables to configure options #73

Merged
merged 5 commits into from Apr 23, 2015
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -121,6 +121,10 @@ Each strategy accepts the following optional settings:

### Advanced Usage

#### Configuration via Environment Variables
The `server.auth.strategy()` method supports string representations of its boolean and number typed options.
For example, `forceHttps` can be set to 'true', 'false', 'yes', or 'no'. In effect, this allows you to configure any strategy option using environment variables.

#### Handling Errors

By default, **bell** will reply back with an internal error (500) on most authentication errors due to the nature of the OAuth protocol.
Expand Down
6 changes: 5 additions & 1 deletion lib/index.js
Expand Up @@ -71,7 +71,11 @@ internals.implementation = function (server, options) {
settings.provider = Providers[settings.provider].call(null, settings.config);
}

Joi.assert(settings, internals.schema);
var results = Joi.validate(settings, internals.schema);
Hoek.assert(!results.error, results.error);

// Passed validation, use Joi converted settings
settings = results.value;

// Setup cookie for managing temporary authorization state

Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -40,7 +40,8 @@
"hapi": "8.x.x",
"hawk": "2.x.x",
"lab": "5.x.x",
"code": "1.x.x"
"code": "1.x.x",
"sinon": "1.x.x"
},
"scripts": {
"test": "make test-cov"
Expand Down
45 changes: 44 additions & 1 deletion test/index.js
Expand Up @@ -6,7 +6,8 @@ var Hapi = require('hapi');
var Hoek = require('hoek');
var Lab = require('lab');
var Mock = require('./mock');

var Sinon = require('sinon');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this above the Mock require

var OAuth = require('../lib/oauth');

// Declare internals

Expand All @@ -23,6 +24,48 @@ var expect = Code.expect;

describe('Bell', function () {

it('supports string representations of boolean and number strategy options', function(done) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function (done) {


var mock = new Mock.V1();
mock.start(function (provider) {

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

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

var spy = Sinon.spy(OAuth, 'v1');

server.auth.strategy('custom', 'bell', {
password: 'password',
isSecure: 'false',
clientId: 'test',
clientSecret: 'secret',
ttl: '1234567890',
forceHttps: 'true',
provider: provider,
config: {
testNoBoolean: 'false',
testNoNumber: '0987654321'
}
});

expect( spy.calledOnce ).to.be.true();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(spy.calledOnce).to.be.true();

no need for extra spaces in ()

expect( spy.getCall(0).args[0] ).to.be.an.object();
expect( spy.getCall(0).args[0].isSecure ).to.be.false();
expect( spy.getCall(0).args[0].ttl ).to.be.equal(1234567890);
expect( spy.getCall(0).args[0].forceHttps ).to.be.true();
expect( spy.getCall(0).args[0].config.testNoBoolean ).to.be.equal('false');
expect( spy.getCall(0).args[0].config.testNoNumber ).to.be.equal('0987654321');

spy.restore();

mock.stop(done);
});
});
});

it('authenticates an endpoint via oauth', function (done) {

var mock = new Mock.V1();
Expand Down