diff --git a/packages/authentication-oauth/src/express.ts b/packages/authentication-oauth/src/express.ts index c15b16063b..0825ca37c2 100644 --- a/packages/authentication-oauth/src/express.ts +++ b/packages/authentication-oauth/src/express.ts @@ -38,14 +38,15 @@ export default (options: OauthSetupSettings) => { authApp.use(expressSession); authApp.get('/:name', (req, res) => { - const { feathers_token, ...query } = req.query; + const { feathers_token, redirect, ...query } = req.query; const { name } = req.params as any; if (feathers_token) { debug(`Got feathers_token query parameter to link accounts`, feathers_token); req.session.accessToken = feathers_token; - req.session.query = query; } + req.session.redirect = redirect; + req.session.query = query; res.redirect(`${path}/connect/${name}?${qs.stringify(query)}`); }); @@ -56,7 +57,7 @@ export default (options: OauthSetupSettings) => { authApp.get('/:name/authenticate', async (req, res, next) => { const { name } = req.params as any; - const { accessToken, grant, query = {} } = req.session; + const { accessToken, grant, query = {}, redirect } = req.session; const service = app.defaultAuthentication(authService); const [ strategy ] = service.getStrategies(name) as OAuthStrategy[]; const params = { @@ -65,7 +66,8 @@ export default (options: OauthSetupSettings) => { strategy: linkStrategy, accessToken } : null, - query + query, + redirect }; const sendResponse = async (data: AuthenticationResult|Error) => { try { diff --git a/packages/authentication-oauth/src/strategy.ts b/packages/authentication-oauth/src/strategy.ts index d86ec9967a..0cbf047932 100644 --- a/packages/authentication-oauth/src/strategy.ts +++ b/packages/authentication-oauth/src/strategy.ts @@ -73,7 +73,7 @@ export class OAuthStrategy extends AuthenticationBaseStrategy { } async getRedirect (data: AuthenticationResult|Error, params?: Params) { - const queryRedirect = (params && params.query && params.query.redirect) || ''; + const queryRedirect = (params && params.redirect) || ''; const { redirect } = this.authentication.configuration.oauth; if (!redirect) { diff --git a/packages/authentication-oauth/test/strategy.test.ts b/packages/authentication-oauth/test/strategy.test.ts index a0967719b6..7f178a34a9 100644 --- a/packages/authentication-oauth/test/strategy.test.ts +++ b/packages/authentication-oauth/test/strategy.test.ts @@ -25,7 +25,7 @@ describe('@feathersjs/authentication-oauth/strategy', () => { assert.equal(redirect, '/home#access_token=testing'); redirect = await strategy.getRedirect({ accessToken: 'testing' }, { - query: { redirect: '/hi-there' } + redirect: '/hi-there' }); assert.strictEqual('/home/hi-there#access_token=testing', redirect);