Skip to content

Commit

Permalink
fix(authentication): consistent response return between local and jwt…
Browse files Browse the repository at this point in the history
… strategy (#2042)
  • Loading branch information
bwgjoseph authored Nov 8, 2020
1 parent 46e84b8 commit 8d25be1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/authentication/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AuthenticationBase, AuthenticationResult, AuthenticationRequest } from
import { connection, event } from './hooks';
import '@feathersjs/transport-commons';
import { Application, Params, ServiceMethods, ServiceAddons } from '@feathersjs/feathers';
import jsonwebtoken from 'jsonwebtoken';

const debug = Debug('@feathersjs/authentication/service');

Expand Down Expand Up @@ -112,7 +113,12 @@ export class AuthenticationService extends AuthenticationBase implements Partial

const accessToken = await this.createAccessToken(payload, jwtOptions, params.secret);

return Object.assign({}, { accessToken }, authResult);
return merge({ accessToken }, authResult, {
authentication: {
accessToken,
payload: jsonwebtoken.decode(accessToken)
}
});
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/authentication/test/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ describe('authentication/service', () => {
}

assert.ok(result.accessToken);
assert.deepStrictEqual(omit(result, 'accessToken'), Strategy1.result);
assert.deepStrictEqual(omit(result, 'accessToken', 'authentication'), Strategy1.result);
assert.deepStrictEqual(result.authentication.payload, decoded);
assert.ok(UUID.test(decoded.jti), 'Set `jti` to default UUID');
assert.strictEqual(decoded.aud, settings.audience);
assert.strictEqual(decoded.iss, settings.issuer);
Expand Down
6 changes: 4 additions & 2 deletions packages/express/test/authentication.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _axios = require('axios');
const feathers = require('@feathersjs/feathers');
const getApp = require('@feathersjs/authentication-local/test/fixture');
const { authenticate } = require('@feathersjs/authentication');
const omit = require('lodash/omit');

const expressify = require('../lib');
const axios = _axios.create({
Expand Down Expand Up @@ -63,8 +64,9 @@ describe('@feathersjs/express/authentication', () => {
describe('service authentication', () => {
it('successful local authentication', () => {
assert.ok(authResult.accessToken);
assert.deepStrictEqual(authResult.authentication, {
strategy: 'local'
assert.deepStrictEqual(omit(authResult.authentication, 'payload'), {
strategy: 'local',
accessToken: authResult.accessToken
});
assert.strictEqual(authResult.user.email, email);
assert.strictEqual(authResult.user.password, undefined);
Expand Down

0 comments on commit 8d25be1

Please sign in to comment.