From a270d0d5232bc76ad44d2e502f1945cf69d959f7 Mon Sep 17 00:00:00 2001 From: Anders Gustafsson <34234789+anders-photowall@users.noreply.github.com> Date: Wed, 29 Sep 2021 10:43:51 +0200 Subject: [PATCH] 57 basic auth dev only (#58) --- Dockerfile | 2 ++ Dockerfile-dev | 2 ++ src/cognito/cognito-client.ts | 1 - src/index.ts | 6 ++++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 74c199a..42a8b0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,8 @@ EXPOSE 4000 COPY . app/ # Changes working directory to the new directory just created WORKDIR /app +# Set node env +ENV NODE_ENV=production # Installs npm dependencies on container RUN npm ci # Command container will actually run when called diff --git a/Dockerfile-dev b/Dockerfile-dev index eb06f00..7a776ad 100644 --- a/Dockerfile-dev +++ b/Dockerfile-dev @@ -5,5 +5,7 @@ FROM node:14.17.0 EXPOSE 4000 # Changes working directory to the new directory just created WORKDIR /app +# Set node env +ENV NODE_ENV=development # Command container will actually run when called CMD ["npx", "nodemon", "-w", "src", "--ext", "ts", "--exec", "ts-node", "src/index.ts"] diff --git a/src/cognito/cognito-client.ts b/src/cognito/cognito-client.ts index c844789..e009e7e 100644 --- a/src/cognito/cognito-client.ts +++ b/src/cognito/cognito-client.ts @@ -107,7 +107,6 @@ const verifyToken = async ( request: ClaimVerifyRequest, ): Promise => { try { - // console.log(`user claim verify invoked for ${JSON.stringify(request)}`); const token = request.token; const tokenSections = (token || '').split('.'); if (tokenSections.length < 2) { diff --git a/src/index.ts b/src/index.ts index 357187f..e0eff1f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,8 +59,10 @@ const context = async ({ req }) => { const token = authHeader.substring(7, authHeader.length); const res = await verifyToken({ token }); return { auth: res }; - } else if (authHeader == 'Basic ZGV2OmRldg==') { - // dev:dev remove later + } else if ( + process.env.NODE_ENV === 'development' && + authHeader == 'Basic ZGV2OnB2N1VmYSFiZVAzeGk=' + ) { return { auth: 'during development' }; } throw new AuthenticationError('Not authorized');