Skip to content

Commit

Permalink
fix(authentication-oauth): Allow req.feathers to be used in oAuth aut…
Browse files Browse the repository at this point in the history
…hentication requests (#1886)
  • Loading branch information
daffl committed Mar 24, 2020
1 parent 4127834 commit 854c9ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/authentication-oauth/src/express.ts
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/authentication-oauth/test/express.test.ts
Expand Up @@ -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 () => {
Expand Down
17 changes: 16 additions & 1 deletion packages/authentication-oauth/test/fixture.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit 854c9ca

Please sign in to comment.