Skip to content

Commit

Permalink
Merge pull request #73 from hofan41/master
Browse files Browse the repository at this point in the history
Allow environment variables to configure options
  • Loading branch information
geek committed Apr 23, 2015
2 parents 73faada + eb9448c commit c6c023f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
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 @@ -5,8 +5,9 @@ var Code = require('code');
var Hapi = require('hapi');
var Hoek = require('hoek');
var Lab = require('lab');
var Sinon = require('sinon');
var Mock = require('./mock');

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) {

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();
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

0 comments on commit c6c023f

Please sign in to comment.