feat: Export AuthAdapter to make it available for extension with custom authentication adapters (#8443)

This commit is contained in:
Daniel
2023-03-04 03:51:45 +11:00
committed by GitHub
parent 656bca6132
commit 40c196153b
2 changed files with 21 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
import loadAdapter from '../AdapterLoader';
import Parse from 'parse/node';
import AuthAdapter from './AuthAdapter';
const apple = require('./apple');
const gcenter = require('./gcenter');
@@ -153,22 +154,30 @@ function loadAuthAdapter(provider, authOptions) {
return;
}
const adapter = Object.assign({}, defaultAdapter);
const adapter = defaultAdapter instanceof AuthAdapter ? defaultAdapter : Object.assign({}, defaultAdapter);
const keys = [
'validateAuthData',
'validateAppId',
'validateSetUp',
'validateLogin',
'validateUpdate',
'challenge',
'policy'
];
const defaultAuthAdapter = new AuthAdapter();
keys.forEach(key => {
const existing = adapter?.[key];
if (existing && typeof existing === 'function' && existing.toString() === defaultAuthAdapter[key].toString()) {
adapter[key] = null;
}
});
const appIds = providerOptions ? providerOptions.appIds : undefined;
// Try the configuration methods
if (providerOptions) {
const optionalAdapter = loadAdapter(providerOptions, undefined, providerOptions);
if (optionalAdapter) {
[
'validateAuthData',
'validateAppId',
'validateSetUp',
'validateLogin',
'validateUpdate',
'challenge',
'policy',
].forEach(key => {
keys.forEach(key => {
if (optionalAdapter[key]) {
adapter[key] = optionalAdapter[key];
}

View File

@@ -6,6 +6,7 @@ import RedisCacheAdapter from './Adapters/Cache/RedisCacheAdapter';
import LRUCacheAdapter from './Adapters/Cache/LRUCache.js';
import * as TestUtils from './TestUtils';
import * as SchemaMigrations from './SchemaMigrations/Migrations';
import AuthAdapter from './Adapters/Auth/AuthAdapter';
import { useExternal } from './deprecated';
import { getLogger } from './logger';
@@ -43,4 +44,5 @@ export {
ParseGraphQLServer,
_ParseServer as ParseServer,
SchemaMigrations,
AuthAdapter,
};