Skip to content

Commit 230efdd

Browse files
committed
wip
1 parent 21fc502 commit 230efdd

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/AuthenticationAdapters.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const responses = {
1818
microsoft: { id: 'userId', mail: 'userMail' },
1919
};
2020

21-
describe('AuthenticationProviders', function () {
21+
fdescribe('AuthenticationProviders', function () {
2222
[
2323
'apple',
2424
'gcenter',

spec/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ on_db(
8383
);
8484

8585
let logLevel;
86-
let silent = true;
86+
let silent = false;
8787
if (process.env.VERBOSE) {
8888
silent = false;
8989
logLevel = 'verbose';

src/Adapters/Auth/index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import loadAdapter from '../AdapterLoader';
22
import Parse from 'parse/node';
33
import AuthAdapter from './AuthAdapter';
4-
4+
import Config from '../../Config';
55
const apple = require('./apple');
66
const gcenter = require('./gcenter');
77
const gpgames = require('./gpgames');
@@ -63,8 +63,6 @@ const providers = {
6363
ldap,
6464
};
6565

66-
let authAdapters = {};
67-
6866
// Indexed auth policies
6967
const authAdapterPolicies = {
7068
default: true,
@@ -138,6 +136,7 @@ function authDataValidator(provider, adapter, appIds, options) {
138136
}
139137

140138
function loadAuthAdapter(provider, authOptions, cached) {
139+
const config = Config.get(Parse.applicationId);
141140
if (!cached) {
142141
let defaultAdapter = providers[provider];
143142
// authOptions can contain complete custom auth adapters or
@@ -189,10 +188,13 @@ function loadAuthAdapter(provider, authOptions, cached) {
189188
if (adapter.validateOptions) {
190189
adapter.validateOptions(providerOptions);
191190
}
192-
authAdapters[provider] = adapter;
191+
if (!config.authCache) {
192+
config.authCache = new Map();
193+
}
194+
config.authCache.set(provider, adapter);
193195
}
194196
}
195-
const adapter = authAdapters[provider];
197+
const adapter = config.authCache?.get(provider);
196198
if (!adapter) {
197199
return;
198200
}
@@ -202,11 +204,15 @@ function loadAuthAdapter(provider, authOptions, cached) {
202204
}
203205

204206
function validateAuthConfig(auth) {
205-
authAdapters = {};
207+
const authCache = new Map();
206208
if (!auth.anonymous) {
207209
auth.anonymous = { enabled: true };
208210
}
209-
Object.keys(auth).forEach(key => loadAuthAdapter(key, auth));
211+
Object.keys(auth).forEach(key => {
212+
const adapter = loadAuthAdapter(key, auth);
213+
authCache.set(key, adapter);
214+
});
215+
return authCache;
210216
}
211217

212218
module.exports = function (authOptions = {}, enableAnonymousUsers = true) {

src/Config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export class Config {
5858
Config.validateControllers(serverConfiguration);
5959
AppCache.put(serverConfiguration.appId, serverConfiguration);
6060
Config.setupPasswordValidator(serverConfiguration.passwordPolicy);
61+
if (serverConfiguration.auth) {
62+
serverConfiguration.authStore = AuthAdapter.validateAuthConfig(serverConfiguration.auth);
63+
}
6164
return serverConfiguration;
6265
}
6366

@@ -87,7 +90,6 @@ export class Config {
8790
logLevels,
8891
rateLimit,
8992
databaseOptions,
90-
auth,
9193
extendSessionOnUse,
9294
}) {
9395
if (masterKey === readOnlyMasterKey) {
@@ -131,9 +133,6 @@ export class Config {
131133
this.validateRateLimit(rateLimit);
132134
this.validateLogLevels(logLevels);
133135
this.validateDatabaseOptions(databaseOptions);
134-
if (auth) {
135-
AuthAdapter.validateAuthConfig(auth);
136-
}
137136
}
138137

139138
static validateControllers({

0 commit comments

Comments
 (0)