diff --git a/packages/authentication-oauth/src/express.ts b/packages/authentication-oauth/src/express.ts index 0825ca37c2..f0265430de 100644 --- a/packages/authentication-oauth/src/express.ts +++ b/packages/authentication-oauth/src/express.ts @@ -61,6 +61,7 @@ export default (options: OauthSetupSettings) => { const service = app.defaultAuthentication(authService); const [ strategy ] = service.getStrategies(name) as OAuthStrategy[]; const params = { + ...req.feathers, authStrategies: [ name ], authentication: accessToken ? { strategy: linkStrategy, diff --git a/packages/authentication-oauth/test/express.test.ts b/packages/authentication-oauth/test/express.test.ts index 26c19b3d78..967be8f2f6 100644 --- a/packages/authentication-oauth/test/express.test.ts +++ b/packages/authentication-oauth/test/express.test.ts @@ -27,6 +27,7 @@ describe('@feathersjs/authentication-oauth/express', () => { assert.ok(data.accessToken); assert.equal(data.user.testId, 'expressTest'); + assert.equal(data.fromMiddleware, 'testing'); }); it('oauth/test/authenticate with redirect', async () => { diff --git a/packages/authentication-oauth/test/fixture.ts b/packages/authentication-oauth/test/fixture.ts index a10dc540d1..f2731046fc 100644 --- a/packages/authentication-oauth/test/fixture.ts +++ b/packages/authentication-oauth/test/fixture.ts @@ -11,9 +11,20 @@ export class TestOAuthStrategy extends OAuthStrategy { if (!data.id) { throw new Error('Data needs an id'); } - + return data; } + + async authenticate (data: AuthenticationRequest, params: Params) { + const { fromMiddleware } = params; + const authResult = await super.authenticate(data, params); + + if (fromMiddleware) { + authResult.fromMiddleware = fromMiddleware; + } + + return authResult; + } } const port = 3000; @@ -46,6 +57,10 @@ app.set('authentication', { } }); +app.use((req, _res, next) => { + req.feathers = { fromMiddleware: 'testing' }; + next(); +}); app.use('/authentication', auth); app.use('/users', memory());