From 123188ae7676e99e3303fbe8098d07b5ecbf1c56 Mon Sep 17 00:00:00 2001 From: leandrogilcarrano Date: Fri, 31 May 2024 15:30:23 -0300 Subject: [PATCH] feat: fix util generate code challenge --- src/Utils.js | 2 +- test/oauth2/ServerMock.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utils.js b/src/Utils.js index 0708258..5cb54c4 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -98,7 +98,7 @@ export async function sha256(value) { * @returns */ export function base64Buffer(buffer) { - return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer))); // .replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); + return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); } /** diff --git a/test/oauth2/ServerMock.js b/test/oauth2/ServerMock.js index 59fe1c0..75945d3 100644 --- a/test/oauth2/ServerMock.js +++ b/test/oauth2/ServerMock.js @@ -184,7 +184,7 @@ module.exports.CodeServerMock = { const secret = params.get('client_secret'); const verifier = params.get('code_verifier'); const verifierSettings = codeChallenges[code]; - const challenge = verifier && verifierSettings ? crypto.createHash('sha256').update(verifier).digest('base64') : undefined; + const challenge = verifier && verifierSettings ? crypto.createHash('sha256').update(verifier).digest('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') : undefined; if (params.get('grant_type') !== 'authorization_code') { result.set('error', 'invalid_grant');