Merge pull request #161 from hybridgroup/api-basic-auth
Add HTTP Basic Auth support to API
This commit is contained in:
commit
c5f09133b0
10
lib/api.js
10
lib/api.js
|
@ -40,6 +40,16 @@ namespace("Cylon", function() {
|
||||||
|
|
||||||
this.server.set('title', 'Cylon API Server');
|
this.server.set('title', 'Cylon API Server');
|
||||||
|
|
||||||
|
// configure basic auth, if requested
|
||||||
|
if (opts.auth.type && opts.auth.type === 'basic') {
|
||||||
|
var user = opts.auth.user,
|
||||||
|
pass = opts.auth.pass;
|
||||||
|
|
||||||
|
if (user && pass) {
|
||||||
|
this.server.use(express.basicAuth(user, pass));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.server.use(express.json());
|
this.server.use(express.json());
|
||||||
this.server.use(express.urlencoded());
|
this.server.use(express.urlencoded());
|
||||||
this.server.use(express["static"](__dirname + "/../node_modules/robeaux/"));
|
this.server.use(express["static"](__dirname + "/../node_modules/robeaux/"));
|
||||||
|
|
|
@ -47,7 +47,8 @@ var Cylon = (function() {
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
port: '3000',
|
port: '3000',
|
||||||
cert: null,
|
cert: null,
|
||||||
key: null
|
key: null,
|
||||||
|
auth: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.robot = bind(this.robot, this);
|
this.robot = bind(this.robot, this);
|
||||||
|
@ -101,6 +102,7 @@ var Cylon = (function() {
|
||||||
|
|
||||||
var host = opts.host || this.api_config.host,
|
var host = opts.host || this.api_config.host,
|
||||||
port = opts.port || this.api_config.port,
|
port = opts.port || this.api_config.port,
|
||||||
|
auth = opts.auth || this.api_config.auth,
|
||||||
cert = opts.cert || this.api_config.cert,
|
cert = opts.cert || this.api_config.cert,
|
||||||
key = opts.key || this.api_config.key;
|
key = opts.key || this.api_config.key;
|
||||||
|
|
||||||
|
@ -108,7 +110,8 @@ var Cylon = (function() {
|
||||||
host: host,
|
host: host,
|
||||||
port: port,
|
port: port,
|
||||||
cert: cert,
|
cert: cert,
|
||||||
key: key
|
key: key,
|
||||||
|
auth: auth
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.api_config;
|
return this.api_config;
|
||||||
|
|
|
@ -47,7 +47,8 @@ describe("Cylon", function() {
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
port: '3000',
|
port: '3000',
|
||||||
cert: null,
|
cert: null,
|
||||||
key: null
|
key: null,
|
||||||
|
auth: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// this is the shortest, cheapest way to dup an object in JS.
|
// this is the shortest, cheapest way to dup an object in JS.
|
||||||
|
@ -102,6 +103,16 @@ describe("Cylon", function() {
|
||||||
expect(cylon.api_config).to.be.eql(expectedConfig);
|
expect(cylon.api_config).to.be.eql(expectedConfig);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
context("specifying an auth strategy", function() {
|
||||||
|
it("changes the auth strategy", function() {
|
||||||
|
var auth = { type: 'basic', user: 'user', pass: 'pass'}
|
||||||
|
expectedConfig.auth = auth;
|
||||||
|
cylon.api({ auth: auth })
|
||||||
|
|
||||||
|
expect(cylon.api_config).to.be.eql(expectedConfig);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#findRobot", function() {
|
describe("#findRobot", function() {
|
||||||
|
|
Loading…
Reference in New Issue