diff --git a/packages/authentication-oauth/src/strategy.ts b/packages/authentication-oauth/src/strategy.ts index cf4ef9dbda..e5ca187db9 100644 --- a/packages/authentication-oauth/src/strategy.ts +++ b/packages/authentication-oauth/src/strategy.ts @@ -79,7 +79,8 @@ export class OAuthStrategy extends AuthenticationBaseStrategy { return null; } - const separator = redirect.endsWith('?') ? '' : '#'; + const separator = redirect.endsWith('?') ? '' : + (redirect.indexOf('#') !== -1 ? '?' : '#'); const authResult: AuthenticationResult = data; const query = authResult.accessToken ? { access_token: authResult.accessToken diff --git a/packages/authentication-oauth/test/strategy.test.ts b/packages/authentication-oauth/test/strategy.test.ts index 9217a0f1ed..8a52190cf5 100644 --- a/packages/authentication-oauth/test/strategy.test.ts +++ b/packages/authentication-oauth/test/strategy.test.ts @@ -39,6 +39,11 @@ describe('@feathersjs/authentication-oauth/strategy', () => { redirect = await strategy.getRedirect({ accessToken: 'testing' }); assert.equal(redirect, null); + + app.get('authentication').oauth.redirect = '/#dashboard'; + + redirect = await strategy.getRedirect({ accessToken: 'testing' }); + assert.equal(redirect, '/#dashboard?access_token=testing'); }); it('getProfile', async () => {