diff --git a/packages/authentication/src/service.ts b/packages/authentication/src/service.ts index 9d05f21b63..f611845ecb 100644 --- a/packages/authentication/src/service.ts +++ b/packages/authentication/src/service.ts @@ -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'); @@ -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) + } + }); } /** diff --git a/packages/authentication/test/service.test.ts b/packages/authentication/test/service.test.ts index 932e7b6b62..de41aaf1a8 100644 --- a/packages/authentication/test/service.test.ts +++ b/packages/authentication/test/service.test.ts @@ -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); diff --git a/packages/express/test/authentication.test.js b/packages/express/test/authentication.test.js index a96ba63d83..cc457a1d34 100644 --- a/packages/express/test/authentication.test.js +++ b/packages/express/test/authentication.test.js @@ -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({ @@ -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);