From abdc383ae149a8f0f74bb812fb9b7bac84ba36d5 Mon Sep 17 00:00:00 2001 From: Sadrinho27 Date: Fri, 12 Sep 2025 14:29:28 +0200 Subject: [PATCH] fix(idnot): ensure env variables are treated as strings for fetch and URLSearchParams --- src/services/idnot/index.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/services/idnot/index.ts b/src/services/idnot/index.ts index 8b82265..e3d2a88 100644 --- a/src/services/idnot/index.ts +++ b/src/services/idnot/index.ts @@ -5,20 +5,28 @@ dotenv.config(); export class IdNotService { static async exchangeCodeForTokens(code: string) { + + const tokenUrl = process.env.IDNOT_TOKEN_URL; + const clientId = process.env.IDNOT_CLIENT_ID; + const clientSecret = process.env.IDNOT_CLIENT_SECRET; + const redirectUri = process.env.IDNOT_REDIRECT_URI; + + if (!tokenUrl || !clientId || !clientSecret || !redirectUri) { + throw new Error("Missing required IDNOT environment variables"); + } + const params = { - client_id: process.env.IDNOT_CLIENT_ID, - client_secret: process.env.IDNOT_CLIENT_SECRET, - redirect_uri: process.env.IDNOT_REDIRECT_URI, - grant_type: 'authorization_code', + client_id: clientId, + client_secret: clientSecret, + redirect_uri: redirectUri, + grant_type: "authorization_code", code: code }; const tokens = await ( - await fetch(process.env.IDNOT_TOKEN_URL, { - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, + await fetch(tokenUrl, { + method: "POST", + headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams(params).toString() }) ).json();