Skip to content

Commit

Permalink
fix: Rename jwtStrategies option to authStrategies (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Apr 23, 2019
1 parent 5ac826b commit 4aee151
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/authentication-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export { AuthenticationClient, AuthenticationClientOptions, Storage, MemoryStora

export type ClientConstructor = new (app: Application, options: AuthenticationClientOptions) => AuthenticationClient;

export const defaultStorage: Storage = typeof window !== 'undefined' && window.localStorage ?
export const defaultStorage: Storage = typeof window !== 'undefined' ?
new StorageWrapper(window.localStorage) : new MemoryStorage();

export const defaults: AuthenticationClientOptions = {
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication-client/test/integration/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default (app: Application) => {
service: 'users',
secret: 'supersecret',
httpStrategies: [ 'jwt' ],
jwtStrategies: [ 'local', 'jwt' ],
authStrategies: [ 'local', 'jwt' ],
local: {
usernameField: 'email',
passwordField: 'password'
Expand Down
9 changes: 5 additions & 4 deletions packages/authentication-local/src/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ export class LocalStrategy extends AuthenticationBaseStrategy {
};
}

getEntityQuery (query: Query, _params: Params) {
return Promise.resolve(Object.assign({
$limit: 1
}, query));
async getEntityQuery (query: Query, _params: Params) {
return {
$limit: 1,
...query
};
}

async findEntity (username: string, params: Params) {
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication-local/test/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = (app = feathers()) => {
entity: 'user',
service: 'users',
secret: 'supersecret',
jwtStrategies: [ 'local', 'jwt' ],
authStrategies: [ 'local', 'jwt' ],
httpStrategies: [ 'jwt' ],
local: {
usernameField: 'email',
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication-oauth/src/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default (options: OauthSetupSettings) => {

const params = {
provider: 'rest',
jwtStrategies: [ name ],
authStrategies: [ name ],
authentication: accessToken ? {
strategy: linkStrategy,
accessToken
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/src/options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
httpStrategies: [],
jwtStrategies: [],
authStrategies: [],
jwtOptions: {
header: { typ: 'access' }, // by default is an access token but can be any type
audience: 'https://yourdomain.com', // The resource server where the token is processed
Expand Down
12 changes: 6 additions & 6 deletions packages/authentication/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ export class AuthenticationService extends AuthenticationBase implements Service
* @param params Service call parameters
*/
async create (data: AuthenticationRequest, params: Params) {
const jwtStrategies = params.jwtStrategies || this.configuration.jwtStrategies;
const authStrategies = params.authStrategies || this.configuration.authStrategies;

if (!jwtStrategies.length) {
throw new NotAuthenticated('No authentication strategies allowed for creating a JWT (`jwtStrategies`)');
if (!authStrategies.length) {
throw new NotAuthenticated('No authentication strategies allowed for creating a JWT (`authStrategies`)');
}

const authResult = await this.authenticate(data, params, ...jwtStrategies);
const authResult = await this.authenticate(data, params, ...authStrategies);

debug('Got authentication result', authResult);

Expand Down Expand Up @@ -88,7 +88,7 @@ export class AuthenticationService extends AuthenticationBase implements Service
*/
async remove (id: null|string, params: Params) {
const { authentication } = params;
const { jwtStrategies } = this.configuration;
const { authStrategies } = this.configuration;

// When an id is passed it is expected to be the authentication `accessToken`
if (id !== null && id !== authentication.accessToken) {
Expand All @@ -97,7 +97,7 @@ export class AuthenticationService extends AuthenticationBase implements Service

debug('Verifying authentication strategy in remove');

return this.authenticate(authentication, params, ...jwtStrategies);
return this.authenticate(authentication, params, ...authStrategies);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication/test/hooks/authenticate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ describe('authentication/hooks/authenticate', () => {
entity: 'user',
service: 'users',
secret: 'supersecret',
jwtStrategies: [ 'first' ]
authStrategies: [ 'first' ]
}));
app.use('/auth-v2', new AuthenticationService(app, 'auth-v2', {
entity: 'user',
service: 'users',
secret: 'supersecret',
jwtStrategies: [ 'test' ]
authStrategies: [ 'test' ]
}));
app.use('/users', {
async find () {
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/test/jwt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('authentication/jwt', () => {
entity: 'user',
service: 'users',
secret: 'supersecret',
jwtStrategies: [ 'jwt' ]
authStrategies: [ 'jwt' ]
});

authService.register('jwt', new JWTStrategy());
Expand Down
10 changes: 5 additions & 5 deletions packages/authentication/test/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('authentication/service', () => {
entity: 'user',
service: 'users',
secret: 'supersecret',
jwtStrategies: [ 'first' ]
authStrategies: [ 'first' ]
}));
app.use('/users', memory());

Expand Down Expand Up @@ -149,7 +149,7 @@ describe('authentication/service', () => {
const service = app.service('authentication');
const configuration = service.configuration;

delete configuration.jwtStrategies;
delete configuration.authStrategies;

app.set('authentication', configuration);

Expand All @@ -161,7 +161,7 @@ describe('authentication/service', () => {
assert.fail('Should never get here');
} catch (error) {
assert.strictEqual(error.name, 'NotAuthenticated');
assert.strictEqual(error.message, 'No authentication strategies allowed for creating a JWT (`jwtStrategies`)');
assert.strictEqual(error.message, 'No authentication strategies allowed for creating a JWT (`authStrategies`)');
}
});
});
Expand Down Expand Up @@ -233,7 +233,7 @@ describe('authentication/service', () => {

otherApp.use('/authentication', new AuthenticationService(otherApp, 'authentication', {
secret: 'supersecret',
jwtStrategies: [ 'first' ]
authStrategies: [ 'first' ]
}));

try {
Expand All @@ -251,7 +251,7 @@ describe('authentication/service', () => {
entity: 'user',
service: 'users',
secret: 'supersecret',
jwtStrategies: [ 'first' ]
authStrategies: [ 'first' ]
}));

try {
Expand Down

0 comments on commit 4aee151

Please sign in to comment.