From 9b3a127f6a46d8eabc4c967686d0961dbbb6e25c Mon Sep 17 00:00:00 2001 From: "rodrigo.zamboni" Date: Tue, 12 Apr 2022 16:15:04 -0300 Subject: [PATCH 1/2] fixed authorization on case of missing Authorization header --- src/middlewares/authentication.ts | 46 ++++++++++++++++--------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/middlewares/authentication.ts b/src/middlewares/authentication.ts index 83abf9d..64bb5c0 100644 --- a/src/middlewares/authentication.ts +++ b/src/middlewares/authentication.ts @@ -94,29 +94,31 @@ const verifyToken = async (accessToken: string) => { try { await setUp(awsRegion, awsPoolId); - if (accessToken) { - const user: any = decode(accessToken, { complete: true }); - - if (user === null) { - throw new UnauthorizedException(); - } - - const { kid } = user.header; - const pem = pems.filter((item: any) => item[kid]); - const pemValue: any = pem[0][kid]; - - if (!pem) { - throw new UnauthorizedException(); - } - - verify(accessToken, pemValue, (err: any) => { - if (err) { - throw new UnauthorizedException(); - } - - return; - }); + if (!accessToken) { + throw new UnauthorizedException(); } + + const user: any = decode(accessToken, { complete: true }); + + if (user === null) { + throw new UnauthorizedException(); + } + + const { kid } = user.header; + const pem = pems.filter((item: any) => item[kid]); + const pemValue: any = pem[0][kid]; + + if (!pem) { + throw new UnauthorizedException(); + } + + verify(accessToken, pemValue, (err: any) => { + if (err) { + throw new UnauthorizedException(); + } + + return; + }); } catch (error) { throw new UnauthorizedException(); } From 740be1d98b867fe59d2f86694a9e2a815e18b12e Mon Sep 17 00:00:00 2001 From: "rodrigo.zamboni" Date: Tue, 12 Apr 2022 16:20:03 -0300 Subject: [PATCH 2/2] FIX: CI --- .github/workflows/deploy.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e1672b7..fd4b5d6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,6 +7,22 @@ on: - main jobs: + extract_environment: + runs-on: ubuntu-latest + outputs: + environment: ${{ steps.extract_environment.outputs.environment }} + steps: + - name: Extract Environment + run: | + if [ ${GITHUB_REF} == "refs/heads/main" ]; then + echo "##[set-output name=environment;]$(echo "prd")" + elif [ ${GITHUB_REF} == "refs/heads/alpha" ]; then + echo "##[set-output name=environment;]$(echo "dev")" + elif [ ${GITHUB_REF} == "refs/heads/beta" ]; then + echo "##[set-output name=environment;]$(echo "stg")" + fi + id: extract_environment + deploy: runs-on: self-hosted steps: