2015-11-04 17:31:07 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Public node modules.
|
|
|
|
const _ = require('lodash');
|
|
|
|
const Grant = require('grant-koa');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grant hook
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = function (strapi) {
|
|
|
|
const hook = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default options
|
|
|
|
*/
|
|
|
|
|
|
|
|
defaults: {
|
2016-03-02 14:44:45 +01:00
|
|
|
authentication: {
|
|
|
|
server: {
|
|
|
|
protocol: strapi.config.ssl ? 'https' : 'http',
|
|
|
|
host: strapi.config.host + ':' + strapi.config.port
|
|
|
|
}
|
|
|
|
}
|
2015-11-04 17:31:07 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the hook
|
|
|
|
*/
|
|
|
|
|
|
|
|
initialize: function (cb) {
|
2016-03-02 14:44:45 +01:00
|
|
|
if (_.isPlainObject(strapi.config.authentication) && !_.isEmpty(strapi.config.authentication)) {
|
|
|
|
const grant = new Grant(strapi.config.authentication);
|
2016-01-20 16:26:31 +01:00
|
|
|
strapi.app.use(strapi.middlewares.mount(grant));
|
|
|
|
}
|
2015-11-04 17:31:07 +01:00
|
|
|
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return hook;
|
|
|
|
};
|