From 659a120e5dd6221d32b0132802c381ca819860a0 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 9 Aug 2023 10:51:33 +0400 Subject: [PATCH] fix: Add data reset before each check (#326) * Add data reset before each check * Review comments --- src/controllers/credentials.ts | 6 ++++-- src/middleware/auth/base-auth.ts | 17 +++++++++++++---- src/services/identity/unauthorized.ts | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/controllers/credentials.ts b/src/controllers/credentials.ts index 0524e0ee..b0fbded9 100644 --- a/src/controllers/credentials.ts +++ b/src/controllers/credentials.ts @@ -160,7 +160,8 @@ export class CredentialController { { verifyStatus, policies - } + }, + response.locals.customerId ) if (result.error) { return response.status(StatusCodes.BAD_REQUEST).json({ @@ -394,7 +395,8 @@ export class CredentialController { verifyStatus, policies, domain: verifierDid - } + }, + response.locals.customerId ) if (result.error) { return response.status(StatusCodes.BAD_REQUEST).json({ diff --git a/src/middleware/auth/base-auth.ts b/src/middleware/auth/base-auth.ts index f6ad5fac..64713bae 100644 --- a/src/middleware/auth/base-auth.ts +++ b/src/middleware/auth/base-auth.ts @@ -20,11 +20,11 @@ export abstract class AbstractAuthHandler implements IAuthResourceHandler private routeToScoupe: MethodToScope[] = [] private static pathSkip = [ - '/swagger', - '/user', + '/swagger', '/static', - '/logto', - '/account/set-default-role'] + '/logto', + '/account/set-default-role', + '/auth/user-info'] constructor () { this.nextHandler = {} as IAuthResourceHandler @@ -35,7 +35,16 @@ export abstract class AbstractAuthHandler implements IAuthResourceHandler this.logToHelper = new LogToHelper() } + private reset() { + this.namespace = '' as Namespaces + this.token = '' as string + this.scopes = [] + this.customerId = '' as string + } + public async commonPermissionCheck(request: Request): Promise { + // Reset all variables + this.reset() // Firstly - try to find the rule for the request const rule = this.findRule(request.path, request.method, this.getNamespace()) diff --git a/src/services/identity/unauthorized.ts b/src/services/identity/unauthorized.ts index 02f1e965..a608b412 100644 --- a/src/services/identity/unauthorized.ts +++ b/src/services/identity/unauthorized.ts @@ -68,11 +68,11 @@ export class Unauthorized extends LocalIdentity { return Veramo.instance.getDid(this.initAgent(), did) } - async verifyCredential(credential: VerifiableCredential | string, verificationOptions: VerificationOptions): Promise { + async verifyCredential(credential: VerifiableCredential | string, verificationOptions: VerificationOptions, agentId?: string): Promise { return await Veramo.instance.verifyCredential(this.initAgent(), credential, verificationOptions) } - async verifyPresentation(presentation: VerifiablePresentation | string, verificationOptions: VerificationOptions): Promise { + async verifyPresentation(presentation: VerifiablePresentation | string, verificationOptions: VerificationOptions, agentId?: string): Promise { return await Veramo.instance.verifyPresentation(this.initAgent(), presentation, verificationOptions) }