-
Notifications
You must be signed in to change notification settings - Fork 0
Fix for some JWT checks done as well as adding a new field to the SFDC payments report needed for handling cancelled payments #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b594b4d
7b52e44
f8057e7
605fea4
726cb59
71f124f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,15 +31,25 @@ recent_payments AS ( | |
| WHERE w.type = 'PAYMENT' | ||
| AND p.installment_number = 1 | ||
| AND p.payment_status = 'PAID' | ||
| AND COALESCE(p.date_paid, p.created_at) >= (CURRENT_DATE - INTERVAL '3 months') | ||
| AND p.created_at >= (CURRENT_DATE - INTERVAL '3 months') | ||
| ) | ||
| SELECT | ||
| cl."name" AS customer, | ||
| cl."codeName" AS client_codename, | ||
| COALESCE( | ||
| NULLIF(TRIM(proj.details::jsonb #>> '{taasDefinition,oppurtunityDetails,customerName}'), ''), | ||
| NULLIF(TRIM(proj.details::jsonb #>> '{project_data,group_customer_name}'), ''), | ||
| ba."name" | ||
| ) AS customer_name, | ||
| COALESCE(c."projectId"::text, ba."projectId") AS project_id, | ||
| proj.name AS project_name, | ||
| ba.id::text AS billing_account_id, | ||
| ba."name" AS billing_account_name, | ||
| COALESCE( | ||
| NULLIF(TRIM(proj.details::jsonb #>> '{taasDefinition,oppurtunityDetails,customerName}'), ''), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| NULLIF(TRIM(proj.details::jsonb #>> '{project_data,group_customer_name}'), ''), | ||
| ba."name" | ||
| ) AS customer_name, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| rp.challenge_id, | ||
| c."name" AS challenge_name, | ||
| c."createdAt" AS challenge_created_at, | ||
|
|
@@ -73,4 +83,4 @@ LEFT JOIN projects.projects proj | |
| ON proj.id = c."projectId"::bigint | ||
| LEFT JOIN members.member mem | ||
| ON mem."userId"::text = rp.winner_id | ||
| ORDER BY payment_created_at DESC; | ||
| ORDER BY payment_created_at DESC; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,31 @@ import { | |
| Injectable, | ||
| NestMiddleware, | ||
| UnauthorizedException, | ||
| Logger, | ||
| } from "@nestjs/common"; | ||
| import { Response, NextFunction } from "express"; | ||
| import { ConfigService } from "@nestjs/config"; | ||
| import { middleware } from "tc-core-library-js"; | ||
| const { jwtAuthenticator: authenticator } = middleware; | ||
|
|
||
| const logger = new Logger("AuthMiddleware"); | ||
|
|
||
| function decodeTokenPayload(token: string): Record<string, unknown> | null { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| try { | ||
| const parts = token.split("."); | ||
| if (parts.length < 2) { | ||
| return null; | ||
| } | ||
| const payload = parts[1].replace(/-/g, "+").replace(/_/g, "/"); | ||
| const padded = | ||
| payload + "=".repeat((4 - (payload.length % 4)) % 4); | ||
| const decoded = Buffer.from(padded, "base64").toString("utf8"); | ||
| return JSON.parse(decoded); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| @Injectable() | ||
| export class AuthMiddleware implements NestMiddleware { | ||
| private jwtAuthenticator; | ||
|
|
@@ -19,7 +38,7 @@ export class AuthMiddleware implements NestMiddleware { | |
| ); | ||
| let issuersValue = this.configService.get<string>( | ||
| "VALID_ISSUERS", | ||
| '["https://api.topcoder.com","https://topcoder-dev.auth0.com/"]', | ||
| '["https://api.topcoder.com","https://api.topcoder-dev.com","https://topcoder-dev.auth0.com/","https://auth.topcoder-dev.com/","https://topcoder.auth0.com/","https://auth.topcoder.com/"]', | ||
| ); | ||
|
|
||
| // The tc-core-library-js authenticator expects a string that is a valid JSON array. | ||
|
|
@@ -39,6 +58,15 @@ export class AuthMiddleware implements NestMiddleware { | |
| if (req.headers.authorization) { | ||
| this.jwtAuthenticator(req, res, (err) => { | ||
| if (err) { | ||
| const token = req.headers.authorization?.replace(/^Bearer\s+/i, ""); | ||
| const payload = token ? decodeTokenPayload(token) : null; | ||
| logger.warn({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| message: "JWT authentication failed", | ||
| error: err?.message, | ||
| tokenIss: payload?.["iss"], | ||
| tokenAud: payload?.["aud"], | ||
| validIssuers: this.configService.get<string>("VALID_ISSUERS"), | ||
| }); | ||
| return next(new UnauthorizedException(err.message)); | ||
| } | ||
| next(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[❗❗
correctness]The JSON path
'{taasDefinition,oppurtunityDetails,customerName}'contains a typo inoppurtunityDetails. It should likely beopportunityDetails. This could lead to incorrect data retrieval if the JSON structure is not as expected.