andrechristikan / ack-nestjs-boilerplate

NestJs v10.x Boilerplate. Repository Design Pattern. MongoDB (Mongoose). Containerization.
MIT License
522 stars 180 forks source link

Api Key Issue #283

Closed yavuzgunay closed 1 year ago

yavuzgunay commented 1 year ago

Hello, When I want to fetch the settings information, it gives an x-api-key error. I am currently using the most recent version you posted on September 28. Sometimes when I make a request on localhost, the project terminates itself. What can I do for its solution? I have given all the necessary information below. Thank you for your project.

========================================== "userAgent": { "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36 Edg/104.0.1293.47", "browser": { "name": "Edge", "version": "104.0.1293.47", "major": "104" }, "engine": { "name": "Blink", "version": "104.0.5112.81" }, "os": { "name": "Mac OS", "version": "10.15.7" }, "device": {}, "cpu": {} },

authapis record { "_id": "6332f995377f9750cd2c06c8", "name": "auth api key migration", "description": "From migration", "key": "qwertyuiop12345zxcvbnmkjh", "hash": "e11a023bc0ccf713cb50de9baa5140e59d3d4c52ec8952d9ca60326e040eda54", "encryptionKey": "opbUwdiS1FBsrDUoPgZdx", "passphrase": "cuwakimacojulawu", "isActive": true, "createdAt": ISODate('2022-09-27T13:24:37.808Z'), "updatedAt": ISODate('2022-09-27T13:24:37.808Z') } x-api-key : qwertyuiop12345zxcvbnmkjh

curl -X 'GET' \ 'http://127.0.0.1:3000/api/v1/setting/list?page=1&perPage=20&sort=createdAt%40desc' \ -H 'accept: application/json' \ -H 'x-timestamp: 1662876305642' \ -H 'x-custom-lang: en' \ -H 'user-agent: Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion' \ -H 'x-api-key: qwertyuiop12345zxcvbnmkjh'

API Key Error : /Users/yavuzgunay/Projects/ack-nestjs-boilerplate-mongoose/node_modules/crypto-js/cipher-core.js:876 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); ^ TypeError: Cannot read properties of undefined (reading 'salt') at Object.decrypt (/Users/yavuzgunay/Projects/ack-nestjs-boilerplate-mongoose/node_modules/crypto-js/cipher-core.js:876:102) at Object.decrypt (/Users/yavuzgunay/Projects/ack-nestjs-boilerplate-mongoose/node_modules/crypto-js/cipher-core.js:205:59) at HelperEncryptionService.aes256Decrypt (/Users/yavuzgunay/Projects/ack-nestjs-boilerplate-mongoose/src/common/helper/services/helper.encryption.service.ts:45:28) at AuthApiService.decryptApiKey (/Users/yavuzgunay/Projects/ack-nestjs-boilerplate-mongoose/src/common/auth/services/auth.api.service.ts:281:56) at ApiKeyStrategy.validate (/Users/yavuzgunay/Projects/ack-nestjs-boilerplate-mongoose/src/common/auth/guards/api-key/auth.api-key.strategy.ts:59:43) at processTicksAndRejections (node:internal/process/task_queues:96:5)

==================================================== .env

APP_NAME=ACK APP_ENV=development APP_LANGUAGE=en

HTTP_ENABLE=true HTTP_HOST=localhost HTTP_PORT= 3000 HTTP_VERSIONING_ENABLE=true HTTP_VERSION=1

DEBUGGER_HTTP_WRITE_INTO_FILE=false DEBUGGER_SYSTEM_WRITE_INTO_FILE=false

MIDDLEWARE_TIMESTAMP_TOLERANCE=3h MIDDLEWARE_TIMEOUT=30s

DOC_NAME=ACK APIs Spec DOC_VERSION=1

JOB_ENABLE=false

DATABASE_HOST=mongodb://xxxxx DATABASE_NAME=xxxxxDB DATABASE_USER=xxxxxUser DATABASE_PASSWORD=xxxxxx DATABASE_DEBUG=false DATABASE_OPTIONS=readPreference=primary&ssl=false

AUTH_JWT_SUBJECT=AckDevelopment AUTH_JWT_ISSUER=ack AUTH_JWT_AUDIENCE=https://example.com

AUTH_JWT_ACCESS_TOKEN_SECRET_KEY=123456 AUTH_JWT_ACCESS_TOKEN_EXPIRED=3h

AUTH_JWT_REFRESH_TOKEN_SECRET_KEY=01001231 AUTH_JWT_REFRESH_TOKEN_EXPIRED=7d AUTH_JWT_REFRESH_TOKEN_REMEMBER_ME_EXPIRED=30d AUTH_JWT_REFRESH_TOKEN_NOT_BEFORE_EXPIRATION=30m

SERVERLESS_AWS_API_GATEWAY=baibay SERVERLESS_AWS_PROFILE=baibay SERVERLESS_AWS_S3_BUCKET=baibay-development

AWS_S3_REGION=ap-southeast-3 AWS_S3_BUCKET=baibay-development

andrechristikan commented 1 year ago

Hi @yavuzgunay , Sorry for that. I realized that because I forgot to put some documentation about ApiKeyEncryption.

I already updated the readme in the main branch.  Please check the new update. Thank you