mirror of
https://github.com/strapi/strapi.git
synced 2025-10-03 04:13:51 +00:00
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
const passport = require('koa-passport');
|
||
|
|
||
|
const createProviderRegistry = require('./passport/provider-registry');
|
||
|
const createLocalStrategy = require('./passport/local-strategy');
|
||
|
|
||
|
const providerRegistry = createProviderRegistry();
|
||
|
|
||
|
const getProviderCallbackUrl = providerName => `/admin/connect/${providerName}/callback`;
|
||
|
|
||
|
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,
|
||
|
};
|