Can disable a provider

This commit is contained in:
Jim Laurie 2018-01-18 15:45:02 +01:00
parent fc22f13cfc
commit 5e8259af73
2 changed files with 22 additions and 0 deletions

View File

@ -30,24 +30,31 @@ module.exports = cb => {
if (!_.get(strapi.plugins['users-permissions'], 'config.grant')) {
try {
const grant = {
local: {
enabled: true
},
facebook: {
enabled: false,
key: '',
secret: '',
callback: '/auth/facebook/callback',
scope: ['email']
},
google: {
enabled: false,
key: '',
secret: '',
callback: '/auth/google/callback',
scope: ['email']
},
github: {
enabled: false,
key: '',
secret: '',
callback: '/auth/github/callback'
},
linkedin2: {
enabled: false,
key: '',
secret: '',
callback: '/auth/linkedin2/callback',

View File

@ -25,6 +25,21 @@ module.exports = strapi => {
const grant = new Grant(strapi.plugins['users-permissions'].config.grant);
strapi.app.use(async (ctx, next) => {
if (_.startsWith(ctx.request.url, '/connect') && ctx.request.method === 'GET') {
const provider = _.last(ctx.request.url.split('/'));
const config = strapi.plugins['users-permissions'].config.grant[provider];
if (_.get(config, 'enabled')) {
await next();
} else {
return ctx.badRequest(null, 'This provider is disabled.');
}
} else {
await next();
}
});
strapi.app.use(mount(grant));
cb();