Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 15 commits into from
Mar 3, 2023
29 changes: 19 additions & 10 deletions src/Adapters/Auth/index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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];
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -43,4 +44,5 @@ export {
ParseGraphQLServer,
_ParseServer as ParseServer,
SchemaMigrations,
AuthAdapter,
};