Skip to content

Commit

Permalink
fix: Bring back params.authenticated (#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored May 2, 2019
1 parent aff9e72 commit a0ffd5e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
5 changes: 1 addition & 4 deletions packages/authentication/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ const debug = Debug('@feathersjs/authentication/base');
const verifyJWT = promisify(jsonwebtoken.verify);
const createJWT = promisify(jsonwebtoken.sign);

// TypeScript hack because it does not allow symbols as indexes!?
export const AUTHENTICATE: string = Symbol('@feathersjs/authentication/internal') as any;

export interface AuthenticationResult {
[key: string]: any;
}
Expand Down Expand Up @@ -210,7 +207,7 @@ export class AuthenticationBase {
const { strategy } = authentication;
const authParams = {
...params,
[AUTHENTICATE]: false
authenticated: true
};

// Throw an error is a `strategy` is indicated but not in the allowed strategies
Expand Down
3 changes: 1 addition & 2 deletions packages/authentication/src/hooks/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { HookContext } from '@feathersjs/feathers';
import { NotAuthenticated } from '@feathersjs/errors';
import Debug from 'debug';
import { AuthenticationService } from '../service';
import { AUTHENTICATE } from '../core';

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

Expand Down Expand Up @@ -45,7 +44,7 @@ export default (originalSettings: string|AuthenticateHookSettings, ...originalSt
throw new NotAuthenticated('The authenticate hook does not need to be used on the authentication service');
}

if (params[AUTHENTICATE] === false) {
if (params.authenticated === true) {
return context;
}

Expand Down
3 changes: 1 addition & 2 deletions packages/authentication/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export {
AuthenticationBase,
AuthenticationRequest,
AuthenticationResult,
AuthenticationStrategy,
AUTHENTICATE
AuthenticationStrategy
} from './core';
export { AuthenticationBaseStrategy } from './strategy';
export { AuthenticationService } from './service';
Expand Down
8 changes: 4 additions & 4 deletions packages/authentication/test/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from 'assert';
import feathers, { Application } from '@feathersjs/feathers';
import jwt from 'jsonwebtoken';

import { AuthenticationBase, AUTHENTICATE } from '../src/core';
import { AuthenticationBase } from '../src/core';
import { Strategy1, Strategy2, MockRequest } from './fixtures';
import { ServerResponse } from 'http';

Expand Down Expand Up @@ -152,7 +152,7 @@ describe('authentication/core', () => {

assert.deepStrictEqual(result, Object.assign({}, Strategy2.result, {
authentication,
params: { [AUTHENTICATE]: false }
params: { authenticated: true }
}));
});

Expand All @@ -170,7 +170,7 @@ describe('authentication/core', () => {

assert.deepStrictEqual(result, Object.assign({
params: Object.assign(params, {
[AUTHENTICATE]: false
authenticated: true
}),
authentication
}, Strategy2.result));
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('authentication/core', () => {

assert.deepStrictEqual(result, Object.assign({
authentication,
params: { [AUTHENTICATE]: false }
params: { authenticated: true }
}, Strategy2.result));
});

Expand Down
8 changes: 4 additions & 4 deletions packages/authentication/test/hooks/authenticate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import feathers, { Application, Params, Service } from '@feathersjs/feathers';

import { Strategy1, Strategy2 } from '../fixtures';
import { AuthenticationService, hooks } from '../../src';
import { AuthenticationResult, AUTHENTICATE } from '../../src/core';
import { AuthenticationResult } from '../../src/core';

const { authenticate } = hooks;

Expand Down Expand Up @@ -147,7 +147,7 @@ describe('authentication/hooks/authenticate', () => {

assert.deepStrictEqual(result, Object.assign({
authentication: params.authentication,
params: {}
params: { authenticated: true }
}, Strategy2.result));
});

Expand Down Expand Up @@ -183,10 +183,10 @@ describe('authentication/hooks/authenticate', () => {
}
});

it('passes with [AUTHENTICATE]: false but external call', async () => {
it('passes with authenticated: true but external call', async () => {
const params = {
provider: 'rest',
[AUTHENTICATE]: false
authenticated: true
};
const result = await app.service('users').get(1, params);

Expand Down

0 comments on commit a0ffd5e

Please sign in to comment.