diff --git a/src/app/api/id360/CustomerController.ts b/src/app/api/id360/CustomerController.ts index 475b5bb6..1af0e969 100644 --- a/src/app/api/id360/CustomerController.ts +++ b/src/app/api/id360/CustomerController.ts @@ -4,7 +4,7 @@ import ApiController from "@Common/system/controller-pattern/ApiController"; import { Service } from "typedi"; import Id360Service, { EnrollmentResponse } from "@Services/common/Id360Service/Id360Service"; import CustomersService from "@Services/customer/CustomersService/CustomersService"; -import AuthService from "@Services/common/AuthService/AuthService"; +import AuthService, { ICustomerJwtPayload } from "@Services/common/AuthService/AuthService"; import { Customer } from "le-coffre-resources/dist/SuperAdmin"; @Controller() @@ -88,4 +88,38 @@ export default class CustomerController extends ApiController { return; } } + + @Post("/api/v1/id360/customers/refresh-token") + protected async refreshToken(req: Request, response: Response) { + try { + const authHeader = req.headers["authorization"]; + const token = authHeader && authHeader.split(" ")[1]; + + if (!token) { + this.httpBadRequest(response); + return; + } + + let accessToken; + this.authService.verifyRefreshToken(token, (err, userPayload) => { + if (err) { + console.log(err); + this.httpUnauthorized(response); + return; + } + + const user = userPayload as ICustomerJwtPayload; + delete user.iat; + delete user.exp; + accessToken = this.authService.generateAccessToken(user); + }); + + //success + this.httpSuccess(response, { accessToken }); + } catch (error) { + console.log(error); + this.httpInternalError(response); + return; + } + } } diff --git a/src/app/api/idnot/UserController.ts b/src/app/api/idnot/UserController.ts index 9952e029..cac75ffc 100644 --- a/src/app/api/idnot/UserController.ts +++ b/src/app/api/idnot/UserController.ts @@ -70,12 +70,15 @@ export default class UserController extends ApiController { } const user = userPayload as IUserJwtPayload; + delete user.iat; + delete user.exp; accessToken = this.authService.generateAccessToken(user); }); //success this.httpSuccess(response, { accessToken }); } catch (error) { + console.log(error); this.httpInternalError(response); return; } diff --git a/src/services/admin/DocumentsService/DocumentsService.ts b/src/services/admin/DocumentsService/DocumentsService.ts index 5bdbead9..d76bd983 100644 --- a/src/services/admin/DocumentsService/DocumentsService.ts +++ b/src/services/admin/DocumentsService/DocumentsService.ts @@ -46,7 +46,6 @@ export default class DocumentsService extends BaseService { public async refuse(uid: string, document: Partial, refused_reason: string): Promise { if (document.files) { for (let i = 0; i < document.files.length; i++) { - console.log("archiving file", document.files[i]?.uid); await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string); } } diff --git a/src/services/common/AuthService/AuthService.ts b/src/services/common/AuthService/AuthService.ts index 88ed6af4..ca272d65 100644 --- a/src/services/common/AuthService/AuthService.ts +++ b/src/services/common/AuthService/AuthService.ts @@ -14,6 +14,8 @@ enum PROVIDER_OPENID { export interface ICustomerJwtPayload { customerId: string; email: string; + iat?: number; + exp?: number; } export interface IdNotJwtPayload { @@ -31,6 +33,8 @@ export interface IUserJwtPayload { office_Id: string; role: string; rules: string[]; + iat?: number; + exp?: number; } @Service() diff --git a/src/services/notary/DocumentsService/DocumentsService.ts b/src/services/notary/DocumentsService/DocumentsService.ts index c2260763..8f0819ac 100644 --- a/src/services/notary/DocumentsService/DocumentsService.ts +++ b/src/services/notary/DocumentsService/DocumentsService.ts @@ -46,7 +46,6 @@ export default class DocumentsService extends BaseService { public async refuse(uid: string, document: Partial, refused_reason: string): Promise { if (document.files) { for (let i = 0; i < document.files.length; i++) { - console.log("archiving file", document.files[i]?.uid); await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string); } } diff --git a/src/services/super-admin/DocumentsService/DocumentsService.ts b/src/services/super-admin/DocumentsService/DocumentsService.ts index 41041d7e..90cc405a 100644 --- a/src/services/super-admin/DocumentsService/DocumentsService.ts +++ b/src/services/super-admin/DocumentsService/DocumentsService.ts @@ -46,7 +46,6 @@ export default class DocumentsService extends BaseService { public async refuse(uid: string, document: Partial, refused_reason: string): Promise { if (document.files) { for (let i = 0; i < document.files.length; i++) { - console.log("archiving file", document.files[i]?.uid); await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string); } }