From 2a2bbf7f8ee6d32b9fac8afab3421286b06e6443 Mon Sep 17 00:00:00 2001 From: Desmond Koh Date: Sat, 5 Dec 2020 08:16:31 +0800 Subject: [PATCH] fix(authentication-client): Allow reAuthentication using specific strategy (#2140) --- packages/authentication-client/src/core.ts | 4 ++-- .../authentication-client/test/index.test.ts | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/authentication-client/src/core.ts b/packages/authentication-client/src/core.ts index 57e604b458..9d7e8da4af 100644 --- a/packages/authentication-client/src/core.ts +++ b/packages/authentication-client/src/core.ts @@ -132,7 +132,7 @@ export class AuthenticationClient { return Promise.reject(error); } - reAuthenticate (force: boolean = false): Promise { + reAuthenticate (force: boolean = false, strategy?: string): Promise { // Either returns the authentication state or // tries to re-authenticate with the stored JWT and strategy const authPromise = this.app.get('authentication'); @@ -144,7 +144,7 @@ export class AuthenticationClient { } return this.authenticate({ - strategy: this.options.jwtStrategy, + strategy: strategy || this.options.jwtStrategy, accessToken }); }); diff --git a/packages/authentication-client/test/index.test.ts b/packages/authentication-client/test/index.test.ts index fb6f669a14..9f44ce736d 100644 --- a/packages/authentication-client/test/index.test.ts +++ b/packages/authentication-client/test/index.test.ts @@ -202,5 +202,27 @@ describe('@feathersjs/authentication-client', () => { assert.ok(!app.get('authentication')); }); }); + + it('reauthenticates using different strategy', async () => { + app.configure(client({ jwtStrategy: 'any' })); + + const data = { + strategy: 'testing' + }; + + let result = await app.authenticate(data); + assert.deepStrictEqual(result, { + accessToken, + data, + user + }); + + result = await app.authentication.reAuthenticate(false, 'jwt'); + assert.deepStrictEqual(result, { + accessToken, + data, + user + }); + }) }); });