Skip to content

Commit

Permalink
fixup! update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
nabdelgadir authored and jannyHou committed Jan 14, 2019
1 parent 5b6defb commit da1b97f
Show file tree
Hide file tree
Showing 10 changed files with 1,594 additions and 1,503 deletions.
3,009 changes: 1,556 additions & 1,453 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
"src"
],
"dependencies": {
"@loopback/authentication": "^1.0.8",
"@loopback/boot": "^1.0.8",
"@loopback/context": "^1.4.0",
"@loopback/core": "^1.1.3",
"@loopback/openapi-v3": "^1.1.5",
"@loopback/repository": "^1.1.1",
"@loopback/rest": "^1.5.1",
"@loopback/service-proxy": "^1.0.5",
"@loopback/authentication": "^1.0.9",
"@loopback/boot": "^1.0.9",
"@loopback/context": "^1.4.1",
"@loopback/core": "^1.1.4",
"@loopback/openapi-v3": "^1.1.6",
"@loopback/repository": "^1.1.2",
"@loopback/rest": "^1.5.2",
"@loopback/service-proxy": "^1.0.6",
"@types/jsonwebtoken": "^8.3.0",
"@types/passport": "^1.0.0",
"bcryptjs": "^2.4.3",
Expand All @@ -75,8 +75,9 @@
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "^7.1.2",
"@commitlint/travis-cli": "^7.2.1",
"@loopback/build": "^1.0.1",
"@loopback/testlab": "^1.0.1",
"@loopback/build": "^1.2.0",
"@loopback/testlab": "^1.0.4",
"@loopback/tslint-config": "^2.0.0",
"@types/bcryptjs": "^2.4.2",
"@types/debug": "0.0.31",
"@types/express": "^4.16.0",
Expand All @@ -88,7 +89,9 @@
"cz-conventional-changelog": "^2.1.0",
"husky": "^1.1.3",
"mocha": "^5.2.0",
"source-map-support": "^0.5.9"
"source-map-support": "^0.5.9",
"typescript": "3.2.2",
"tslint": "5.12.1"
},
"copyright.owner": "IBM Corp.",
"config": {
Expand Down
4 changes: 2 additions & 2 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
AuthenticationComponent,
} from '@loopback/authentication';
import {StrategyResolverProvider} from './providers/strategy.resolver.provider';
import {MyAuthenticateActionProvider} from './providers/custom.authentication.provider';
import {AuthenticateActionProvider} from './providers/custom.authentication.provider';

/**
* Information from package.json
Expand All @@ -40,7 +40,7 @@ export class ShoppingApplication extends BootMixin(

this.component(AuthenticationComponent);
this.bind(AuthenticationBindings.AUTH_ACTION).toProvider(
MyAuthenticateActionProvider,
AuthenticateActionProvider,
);
this.bind(AuthenticationBindings.STRATEGY).toProvider(
StrategyResolverProvider,
Expand Down
5 changes: 4 additions & 1 deletion src/authentication-strategies/JWT.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export class JWTStrategy implements AuthenticationStrategy {
if (token) {
try {
const decoded = await verifyAsync(token, SECRET);
return _.pick(decoded, ['id', 'email']);
let user = _.pick(decoded, ['id', 'email', 'firstName']);
(user as UserProfile).name = user.firstName;
delete user.firstName;
return user;
} catch (err) {
throw new HttpErrors.Unauthorized('Could not decode the JWT token!');
}
Expand Down
9 changes: 9 additions & 0 deletions src/authentication-strategies/authentication.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import {UserProfile} from '@loopback/authentication';
import {Request} from '@loopback/rest';

/**
* An interface describes the common authentication strategy.
*
* An authentication strategy is usually a class with an
* authenticate method that verifies a user's identity and
* returns the corresponding user profile.
*
* Please note this file should be moved to @loopback/authentication
*/
export interface AuthenticationStrategy {
authenticate(request: Request): Promise<UserProfile | undefined>;
}
38 changes: 5 additions & 33 deletions src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import {
AuthenticationBindings,
} from '@loopback/authentication';
import {Credentials} from '../repositories/user.repository';
import * as _ from 'lodash';

const hashAsync = promisify(hash);

// TODO(jannyHou): This should be moved to @loopback/authentication
const UserProfileSchema = {
type: 'object',
required: ['id'],
Expand Down Expand Up @@ -103,38 +103,10 @@ export class UserController {
return Promise.resolve(currentUser);
}

// @post('users/logout', {
// responses: {
// '200': {
// description: 'Logging out successfully',
// content: {
// 'application/json': {
// schema: {
// type: 'object',
// properties: {
// success: {type: 'boolean'},
// },
// },
// },
// },
// },
// },
// })
// @authenticate('jwt')
// async logout(
// @inject('authentication.currentUser', {optional: true})
// currentUser: UserProfile,
// ): Promise<{success: boolean}> {
// if (currentUser) {
// const AnonymousUser = {
// id: 'ANONYMOUS',
// };
// this.setCurrentUser(AnonymousUser);
// return Promise.resolve({success: true});
// }

// return Promise.reject(new Error('No user logged in'));
// }
// TODO(@jannyHou): missing logout function.
// as a stateless authentication method, JWT doesn't actually
// have a logout operation. See article for details:
// https://medium.com/devgorilla/how-to-log-out-when-using-jwt-a8c7823e8a6

@get('/users/{userId}/recommend', {
responses: {
Expand Down
2 changes: 1 addition & 1 deletion src/providers/custom.authentication.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {AuthenticationStrategy} from '../authentication-strategies/authenticatio
* @example `context.bind('authentication_key')
* .toProvider(AuthenticateActionProvider)`
*/
export class MyAuthenticateActionProvider implements Provider<AuthenticateFn> {
export class AuthenticateActionProvider implements Provider<AuthenticateFn> {
constructor(
// The provider is instantiated for Sequence constructor,
// at which time we don't have information about the current
Expand Down
1 change: 1 addition & 0 deletions src/providers/strategy.resolver.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class StrategyResolverProvider
}

const name = this.metadata.strategy;
// This should be extensible
if (name === 'jwt') {
return new JWTStrategy();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class UserRepository extends DefaultCrudRepository<
throw new HttpErrors.Unauthorized('Wrong credentials!');
}

const currentUser = _.pick(toJSON(foundUser), ['id', 'email']);
const currentUser = _.pick(toJSON(foundUser), ['id', 'email', 'firstName']);

// Generate user token using JWT
const token = await signAsync(currentUser, 'secretforjwt', {
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/user.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// License text available at https://opensource.org/licenses/MIT

import {Client, expect, toJSON} from '@loopback/testlab';
import {Response} from 'supertest';
import {Response} from 'superagent';
import {ShoppingApplication} from '../..';
import {UserRepository, OrderRepository} from '../../src/repositories';
import {MongoDataSource} from '../../src/datasources';
Expand Down

0 comments on commit da1b97f

Please sign in to comment.