Skip to content

Commit 5119cf3

Browse files
committed
feat: Improve authentication adapter interface to support multi-factor authentication (MFA), authentication challenges, and provide a more powerful interface for writing custom authentication adapters (parse-community#8156)
1 parent 3ab7373 commit 5119cf3

20 files changed

+2394
-267
lines changed

DEPRECATIONS.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The following is a list of deprecations, according to the [Deprecation Policy](h
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 | - |
1212
| 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 | - |
1313
| DEPPS7 | Remove file trigger syntax `Parse.Cloud.beforeSaveFile((request) => {})` | [#7966](https://github.com/parse-community/parse-server/pull/7966) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - |
14+
| DEPPS8 | Login with expired 3rd party authentication token defaults to `false` | [#7079](https://github.com/parse-community/parse-server/pull/7079) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - |
1415

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

spec/AuthenticationAdapters.spec.js

+62-11
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,49 @@ describe('AuthenticationProviders', function () {
256256
.catch(done.fail);
257257
});
258258

259+
it('should support loginWith with session token and with/without mutated authData', async () => {
260+
const fakeAuthProvider = {
261+
validateAppId: () => Promise.resolve(),
262+
validateAuthData: () => Promise.resolve(),
263+
};
264+
const payload = { authData: { id: 'user1', token: 'fakeToken' } };
265+
const payload2 = { authData: { id: 'user1', token: 'fakeToken2' } };
266+
await reconfigureServer({ auth: { fakeAuthProvider } });
267+
const user = await Parse.User.logInWith('fakeAuthProvider', payload);
268+
const user2 = await Parse.User.logInWith('fakeAuthProvider', payload, {
269+
sessionToken: user.getSessionToken(),
270+
});
271+
const user3 = await Parse.User.logInWith('fakeAuthProvider', payload2, {
272+
sessionToken: user2.getSessionToken(),
273+
});
274+
expect(user.id).toEqual(user2.id);
275+
expect(user.id).toEqual(user3.id);
276+
});
277+
278+
it('should support sync/async validateAppId', async () => {
279+
const syncProvider = {
280+
validateAppId: () => true,
281+
appIds: 'test',
282+
validateAuthData: () => Promise.resolve(),
283+
};
284+
const asyncProvider = {
285+
appIds: 'test',
286+
validateAppId: () => Promise.resolve(true),
287+
validateAuthData: () => Promise.resolve(),
288+
};
289+
const payload = { authData: { id: 'user1', token: 'fakeToken' } };
290+
const syncSpy = spyOn(syncProvider, 'validateAppId');
291+
const asyncSpy = spyOn(asyncProvider, 'validateAppId');
292+
293+
await reconfigureServer({ auth: { asyncProvider, syncProvider } });
294+
const user = await Parse.User.logInWith('asyncProvider', payload);
295+
const user2 = await Parse.User.logInWith('syncProvider', payload);
296+
expect(user.getSessionToken()).toBeDefined();
297+
expect(user2.getSessionToken()).toBeDefined();
298+
expect(syncSpy).toHaveBeenCalledTimes(1);
299+
expect(asyncSpy).toHaveBeenCalledTimes(1);
300+
});
301+
259302
it('unlink and link with custom provider', async () => {
260303
const provider = getMockMyOauthProvider();
261304
Parse.User._registerAuthenticationProvider(provider);
@@ -339,10 +382,10 @@ describe('AuthenticationProviders', function () {
339382
});
340383

341384
validateAuthenticationHandler(authenticationHandler);
342-
const validator = authenticationHandler.getValidatorForProvider('customAuthentication');
385+
const { validator } = authenticationHandler.getValidatorForProvider('customAuthentication');
343386
validateValidator(validator);
344387

345-
validator(validAuthData).then(
388+
validator(validAuthData, {}, {}).then(
346389
() => {
347390
expect(authDataSpy).toHaveBeenCalled();
348391
// AppIds are not provided in the adapter, should not be called
@@ -362,12 +405,15 @@ describe('AuthenticationProviders', function () {
362405
});
363406

364407
validateAuthenticationHandler(authenticationHandler);
365-
const validator = authenticationHandler.getValidatorForProvider('customAuthentication');
408+
const { validator } = authenticationHandler.getValidatorForProvider('customAuthentication');
366409
validateValidator(validator);
367-
368-
validator({
369-
token: 'my-token',
370-
}).then(
410+
validator(
411+
{
412+
token: 'my-token',
413+
},
414+
{},
415+
{}
416+
).then(
371417
() => {
372418
done();
373419
},
@@ -387,12 +433,16 @@ describe('AuthenticationProviders', function () {
387433
});
388434

389435
validateAuthenticationHandler(authenticationHandler);
390-
const validator = authenticationHandler.getValidatorForProvider('customAuthentication');
436+
const { validator } = authenticationHandler.getValidatorForProvider('customAuthentication');
391437
validateValidator(validator);
392438

393-
validator({
394-
token: 'valid-token',
395-
}).then(
439+
validator(
440+
{
441+
token: 'valid-token',
442+
},
443+
{},
444+
{}
445+
).then(
396446
() => {
397447
done();
398448
},
@@ -541,6 +591,7 @@ describe('AuthenticationProviders', function () {
541591
});
542592

543593
it('can depreciate', async () => {
594+
await reconfigureServer();
544595
const Deprecator = require('../lib/Deprecator/Deprecator');
545596
const spy = spyOn(Deprecator, 'logRuntimeDeprecation').and.callFake(() => {});
546597
const provider = getMockMyOauthProvider();

0 commit comments

Comments
 (0)