2020-12-21 17:11:48 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const passport = require('koa-passport');
|
|
|
|
|
|
|
|
const createProviderRegistry = require('./passport/provider-registry');
|
|
|
|
const createLocalStrategy = require('./passport/local-strategy');
|
|
|
|
|
|
|
|
const providerRegistry = createProviderRegistry();
|
|
|
|
|
2020-12-23 15:32:42 +01:00
|
|
|
const getProviderCallbackUrl = providerName => `/admin/connect/${providerName}`;
|
2020-12-21 17:11:48 +01:00
|
|
|
|
|
|
|
const syncProviderRegistryWithConfig = () => {
|
|
|
|
const { providers = [] } = strapi.config.get('server.admin.auth', {});
|
|
|
|
|
|
|
|
providerRegistry.registerMany(providers);
|
|
|
|
};
|
|
|
|
|
|
|
|
const init = () => {
|
|
|
|
syncProviderRegistryWithConfig();
|
|
|
|
|
|
|
|
const localStrategy = createLocalStrategy(strapi);
|
|
|
|
|
|
|
|
const providers = providerRegistry.toArray();
|
|
|
|
const strategies = providers.map(provider => provider.createStrategy(strapi));
|
|
|
|
|
|
|
|
// Register the local strategy
|
|
|
|
passport.use(localStrategy);
|
|
|
|
|
|
|
|
// And add the ones provided with the config
|
|
|
|
strategies.forEach(provider => passport.use(provider));
|
|
|
|
|
|
|
|
return passport.initialize();
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init,
|
|
|
|
syncProviderRegistryWithConfig,
|
|
|
|
providerRegistry,
|
|
|
|
getProviderCallbackUrl,
|
|
|
|
};
|