Skip to content

Commit c1e808f

Browse files
authored
feat: selectively enable / disable default authentication adapters (#7953)
1 parent 88b4d9d commit c1e808f

File tree

6 files changed

+59
-4
lines changed

6 files changed

+59
-4
lines changed

DEPRECATIONS.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The following is a list of deprecations, according to the [Deprecation Policy](h
99
| DEPPS3 | Config option `enforcePrivateUsers` defaults to `true` | [#7319](https://github.com/parse-community/parse-server/pull/7319) | 5.0.0 (2022) | 6.0.0 (2023) | deprecated | - |
1010
| DEPPS4 | Remove convenience method for http request `Parse.Cloud.httpRequest` | [#7589](https://github.com/parse-community/parse-server/pull/7589) | 5.0.0 (2022) | 6.0.0 (2023) | deprecated | - |
1111
| DEPPS5 | Config option `allowClientClassCreation` defaults to `false` | [#7925](https://github.com/parse-community/parse-server/pull/7925) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - |
12+
| DEPPS6 | Auth providers disabled by default | [#7953](https://github.com/parse-community/parse-server/pull/7953) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - |
1213

1314
[i_deprecation]: ## "The version and date of the deprecation."
1415
[i_removal]: ## "The version and date of the planned removal."

spec/AuthenticationAdapters.spec.js

+26
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,32 @@ describe('AuthenticationProviders', function () {
477477
expect(appIds).toEqual(['a', 'b']);
478478
expect(providerOptions).toEqual(options.custom);
479479
});
480+
481+
it('can disable provider', async () => {
482+
await reconfigureServer({
483+
auth: {
484+
myoauth: {
485+
enabled: false,
486+
module: path.resolve(__dirname, 'support/myoauth'), // relative path as it's run from src
487+
},
488+
},
489+
});
490+
const provider = getMockMyOauthProvider();
491+
Parse.User._registerAuthenticationProvider(provider);
492+
await expectAsync(Parse.User._logInWith('myoauth')).toBeRejectedWith(
493+
new Parse.Error(Parse.Error.UNSUPPORTED_SERVICE, 'This authentication method is unsupported.')
494+
);
495+
});
496+
497+
it('can depreciate', async () => {
498+
const Deprecator = require('../lib/Deprecator/Deprecator');
499+
const spy = spyOn(Deprecator, 'logRuntimeDeprecation').and.callFake(() => {});
500+
const provider = getMockMyOauthProvider();
501+
Parse.User._registerAuthenticationProvider(provider);
502+
await Parse.User._logInWith('myoauth');
503+
expect(spy).toHaveBeenCalledWith({ usage: 'auth.myoauth', solution: 'auth.myoauth.enabled: true' });
504+
});
505+
480506
});
481507

482508
describe('instagram auth adapter', () => {

src/Options/Definitions.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports.ParseServerOptions = {
9595
env: 'PARSE_SERVER_AUTH_PROVIDERS',
9696
help:
9797
'Configuration for your authentication providers, as stringified JSON. See http://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication',
98-
action: parsers.objectParser,
98+
action: parsers.arrayParser,
9999
},
100100
cacheAdapter: {
101101
env: 'PARSE_SERVER_CACHE_ADAPTER',
@@ -876,3 +876,10 @@ module.exports.DatabaseOptions = {
876876
default: false,
877877
},
878878
};
879+
module.exports.AuthAdapter = {
880+
enabled: {
881+
help: 'Is `true` if the auth adapter is enabled, `false` otherwise.',
882+
action: parsers.booleanParser,
883+
default: true,
884+
},
885+
};

src/Options/docs.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @property {Adapter<AnalyticsAdapter>} analyticsAdapter Adapter module for the analytics
2020
* @property {String} appId Your Parse Application ID
2121
* @property {String} appName Sets the app name
22-
* @property {Any} auth Configuration for your authentication providers, as stringified JSON. See http://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication
22+
* @property {AuthAdapter[]} auth Configuration for your authentication providers, as stringified JSON. See http://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication
2323
* @property {Adapter<CacheAdapter>} cacheAdapter Adapter module for the cache
2424
* @property {Number} cacheMaxSize Sets the maximum size for the in memory cache, defaults to 10000
2525
* @property {Number} cacheTTL Sets the TTL for the in memory cache (in ms), defaults to 5000 (5 seconds)
@@ -208,3 +208,8 @@
208208
* @interface DatabaseOptions
209209
* @property {Boolean} enableSchemaHooks Enables database real-time hooks to update single schema cache. Set to `true` if using multiple Parse Servers instances connected to the same database. Failing to do so will cause a schema change to not propagate to all instances and re-syncing will only happen when the instances restart. To use this feature with MongoDB, a replica set cluster with [change stream](https://docs.mongodb.com/manual/changeStreams/#availability) support is required.
210210
*/
211+
212+
/**
213+
* @interface AuthAdapter
214+
* @property {Boolean} enabled Is `true` if the auth adapter is enabled, `false` otherwise.
215+
*/

src/Options/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export interface ParseServerOptions {
140140
allowCustomObjectId: ?boolean;
141141
/* Configuration for your authentication providers, as stringified JSON. See http://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication
142142
:ENV: PARSE_SERVER_AUTH_PROVIDERS */
143-
auth: ?any;
143+
auth: ?(AuthAdapter[]);
144144
/* Max file size for uploads, defaults to 20mb
145145
:DEFAULT: 20mb */
146146
maxUploadSize: ?string;
@@ -506,3 +506,11 @@ export interface DatabaseOptions {
506506
:DEFAULT: false */
507507
enableSchemaHooks: ?boolean;
508508
}
509+
510+
export interface AuthAdapter {
511+
/* Is `true` if the auth adapter is enabled, `false` otherwise.
512+
:DEFAULT: true
513+
:ENV:
514+
*/
515+
enabled: ?boolean;
516+
}

src/RestWrite.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var ClientSDK = require('./ClientSDK');
1515
import RestQuery from './RestQuery';
1616
import _ from 'lodash';
1717
import logger from './logger';
18+
import Deprecator from './Deprecator/Deprecator';
1819
import { requiredColumns } from './Controllers/SchemaController';
1920

2021
// query and data are both provided in REST API format. So data
@@ -430,7 +431,14 @@ RestWrite.prototype.handleAuthDataValidation = function (authData) {
430431
return Promise.resolve();
431432
}
432433
const validateAuthData = this.config.authDataManager.getValidatorForProvider(provider);
433-
if (!validateAuthData) {
434+
const authProvider = (this.config.auth || {})[provider] || {};
435+
if (authProvider.enabled == null) {
436+
Deprecator.logRuntimeDeprecation({
437+
usage: `auth.${provider}`,
438+
solution: `auth.${provider}.enabled: true`,
439+
});
440+
}
441+
if (!validateAuthData || authProvider.enabled === false) {
434442
throw new Parse.Error(
435443
Parse.Error.UNSUPPORTED_SERVICE,
436444
'This authentication method is unsupported.'

0 commit comments

Comments
 (0)