Skip to content

Commit

Permalink
fixup!: fix
Browse files Browse the repository at this point in the history
Signed-off-by: jannyHou <[email protected]>
  • Loading branch information
jannyHou committed Aug 26, 2020
1 parent c1b5995 commit 79a3b40
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 62 deletions.
3 changes: 1 addition & 2 deletions extensions/authentication-jwt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"@loopback/service-proxy": "^2.3.7",
"@types/bcryptjs": "2.4.2",
"bcryptjs": "^2.4.3",
"jsonwebtoken": "^8.5.1",
"@loopback/context": "^3.8.1"
"jsonwebtoken": "^8.5.1"
},
"devDependencies": {
"@loopback/boot": "^2.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('jwt authentication', () => {
it(`user login and token granted successfully`, async () => {
const credentials = {email: '[email protected]', password: 'opensesame'};
const res = await client
.post('/users/refresh/login')
.post('/users/refresh-token')
.send(credentials)
.expect(200);
refreshToken = res.body.refreshToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import {
UserService,
} from '@loopback/authentication';
import {inject} from '@loopback/core';
import {model, property} from '@loopback/repository';
import {get, post, requestBody} from '@loopback/rest';
import {SecurityBindings, securityId, UserProfile} from '@loopback/security';
import {genSalt, hash} from 'bcryptjs';
import {
RefreshGrant,
RefreshGrantRequestBody,
RefreshTokenServiceBindings,
TokenObject,
TokenServiceBindings,
User,
UserServiceBindings,
TokenObject,
RefreshGrantRequestBody,
RefreshGrant,
RefreshTokenServiceBindings,
} from '../../../';
import {model, property} from '@loopback/repository';
import {genSalt, hash} from 'bcryptjs';
import {UserRepository} from '../../../repositories';
import {Credentials} from '../../../services/user.service';
import {RefreshTokenService} from '../../../keys';
import {RefreshTokenService} from '../../../types';

const CredentialsSchema = {
type: 'object',
Expand Down Expand Up @@ -154,7 +154,7 @@ export class UserController {
return this.user[securityId];
}
// Routes using refreshtoken
@post('/users/refresh/login', {
@post('/users/refresh-token', {
responses: {
'200': {
description: 'Token',
Expand Down
1 change: 1 addition & 0 deletions extensions/authentication-jwt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './keys';
export * from './models';
export * from './repositories';
export * from './services';
export * from './types';
41 changes: 1 addition & 40 deletions extensions/authentication-jwt/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {TokenService, UserService} from '@loopback/authentication';
import {BindingKey} from '@loopback/core';
import {User} from './models';
import {Credentials} from './services/user.service';
import {UserProfile} from '@loopback/security';
import {RefreshTokenService} from './types';

export namespace TokenServiceConstants {
export const TOKEN_SECRET_VALUE = 'myjwts3cr3t';
Expand Down Expand Up @@ -57,42 +57,3 @@ export namespace RefreshTokenServiceBindings {
export const DATASOURCE_NAME = 'refreshdb';
export const REFRESH_REPOSITORY = 'repositories.RefreshTokenRepository';
}

export type RefreshGrant = {
refreshToken: string;
};

export const RefreshGrantSchema = {
type: 'object',
required: ['refreshToken'],
properties: {
refreshToken: {
type: 'string',
},
},
};
export const RefreshGrantRequestBody = {
description: 'Reissuing Acess Token',
required: true,
content: {
'application/json': {schema: RefreshGrantSchema},
},
};

export type TokenObject = {
accessToken: string;
expiresIn?: string | undefined;
refreshToken?: string | undefined;
};

export interface RefreshTokenService {
/**
* Generate Token and return the Token Object
*/
generateToken(userProfile: UserProfile, token: string): Promise<TokenObject>;
/**
* Verifies the validity of a token string and returns a new Token
*
*/
refreshToken(refreshToken: string): Promise<TokenObject>;
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {bind, inject, BindingScope, uuid} from '@loopback/core';
import {TokenService} from '@loopback/authentication';
import {bind, BindingScope, inject, uuid} from '@loopback/core';
import {repository} from '@loopback/repository';
import {HttpErrors} from '@loopback/rest';
import {securityId, UserProfile} from '@loopback/security';
import {promisify} from 'util';
import {
RefreshTokenServiceBindings,
TokenObject,
UserServiceBindings,
TokenServiceBindings,
UserServiceBindings,
} from '../keys';
import {repository} from '@loopback/repository';
import {UserProfile, securityId} from '@loopback/security';
import {promisify} from 'util';
import {HttpErrors} from '@loopback/rest';
import {TokenService} from '@loopback/authentication';
import {RefreshTokenRepository} from '../repositories';
import {TokenObject} from '../types';
import {MyUserService} from './user.service';
/* eslint-disable*/

import {RefreshToken, RefreshTokenRelations} from '../models';
/* eslint-enable */
const jwt = require('jsonwebtoken');
Expand Down
45 changes: 45 additions & 0 deletions extensions/authentication-jwt/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright IBM Corp. 2020. All Rights Reserved.
// Node module: @loopback/authentication-jwt
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {UserProfile} from '@loopback/security';

export type RefreshGrant = {
refreshToken: string;
};

export const RefreshGrantSchema = {
type: 'object',
required: ['refreshToken'],
properties: {
refreshToken: {
type: 'string',
},
},
};
export const RefreshGrantRequestBody = {
description: 'Reissuing Acess Token',
required: true,
content: {
'application/json': {schema: RefreshGrantSchema},
},
};

export type TokenObject = {
accessToken: string;
expiresIn?: string | undefined;
refreshToken?: string | undefined;
};

export interface RefreshTokenService {
/**
* Generate Token and return the Token Object
*/
generateToken(userProfile: UserProfile, token: string): Promise<TokenObject>;
/**
* Verifies the validity of a token string and returns a new Token
*
*/
refreshToken(refreshToken: string): Promise<TokenObject>;
}
3 changes: 0 additions & 3 deletions extensions/authentication-jwt/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
{
"path": "../../packages/boot/tsconfig.json"
},
{
"path": "../../packages/context/tsconfig.json"
},
{
"path": "../../packages/core/tsconfig.json"
},
Expand Down

0 comments on commit 79a3b40

Please sign in to comment.