mirror of
https://github.com/directus/directus.git
synced 2026-01-31 15:57:57 -05:00
39 lines
813 B
TypeScript
39 lines
813 B
TypeScript
/**
|
|
* Grant is the oAuth library
|
|
*/
|
|
|
|
import env from './env';
|
|
import { toArray } from './utils/to-array';
|
|
|
|
const enabledProviders = toArray(env.OAUTH_PROVIDERS).map((provider) => provider.toLowerCase());
|
|
|
|
const config: any = {
|
|
defaults: {
|
|
origin: env.PUBLIC_URL,
|
|
transport: 'session',
|
|
prefix: '/auth/oauth',
|
|
response: ['tokens', 'profile'],
|
|
},
|
|
};
|
|
|
|
for (const [key, value] of Object.entries(env)) {
|
|
if (key.startsWith('OAUTH') === false) continue;
|
|
|
|
const parts = key.split('_');
|
|
const provider = parts[1].toLowerCase();
|
|
|
|
if (enabledProviders.includes(provider) === false) continue;
|
|
|
|
// OAUTH <PROVIDER> SETTING = VALUE
|
|
parts.splice(0, 2);
|
|
|
|
const configKey = parts.join('_').toLowerCase();
|
|
|
|
config[provider] = {
|
|
...(config[provider] || {}),
|
|
[configKey]: value,
|
|
};
|
|
}
|
|
|
|
export default config;
|