From 5d1ae8763cacf4e49c2c554df105480d088b5ef6 Mon Sep 17 00:00:00 2001 From: Aymeric <34040599+afoyer@users.noreply.github.com> Date: Thu, 19 Nov 2020 20:08:39 -0600 Subject: [PATCH 1/4] Fixed Reddit Authentication --- src/server/lib/oauth/callback.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server/lib/oauth/callback.js b/src/server/lib/oauth/callback.js index 474efd4c74..7f69d1214d 100644 --- a/src/server/lib/oauth/callback.js +++ b/src/server/lib/oauth/callback.js @@ -213,7 +213,12 @@ async function _getOAuthAccessToken (code, provider, callback) { // Added as a fix to accomodate change in Twitch oAuth API if (!headers['Client-ID']) { headers['Client-ID'] = provider.clientId } - + + //Added as a fix for Reddit Authentication + if (provider.id == 'reddit') { + headers.Authorization = 'Basic ' + Buffer((provider.clientId + ":" + provider.clientSecret)).toString('base64'); + } + // Okta errors when this is set. Maybe there are other Providers that also wont like this. if (setGetAccessTokenAuthHeader) { if (!headers.Authorization) { headers.Authorization = `Bearer ${code}` } From 77e8266c2b3944c8a191cd524348c31bde23e1bc Mon Sep 17 00:00:00 2001 From: Aymeric <34040599+afoyer@users.noreply.github.com> Date: Thu, 19 Nov 2020 20:26:31 -0600 Subject: [PATCH 2/4] updated fix for build test --- src/server/lib/oauth/callback.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/server/lib/oauth/callback.js b/src/server/lib/oauth/callback.js index 7f69d1214d..3cece35377 100644 --- a/src/server/lib/oauth/callback.js +++ b/src/server/lib/oauth/callback.js @@ -210,14 +210,12 @@ async function _getOAuthAccessToken (code, provider, callback) { if (!params.redirect_uri) { params.redirect_uri = provider.callbackUrl } if (!headers['Content-Type']) { headers['Content-Type'] = 'application/x-www-form-urlencoded' } - // Added as a fix to accomodate change in Twitch oAuth API if (!headers['Client-ID']) { headers['Client-ID'] = provider.clientId } - - //Added as a fix for Reddit Authentication - if (provider.id == 'reddit') { - headers.Authorization = 'Basic ' + Buffer((provider.clientId + ":" + provider.clientSecret)).toString('base64'); - } + // Added as a fix for Reddit Authentication + if (provider.id === 'reddit') { + headers.Authorization = 'Basic ' + Buffer((provider.clientId + ':' + provider.clientSecret)).toString('base64') + } // Okta errors when this is set. Maybe there are other Providers that also wont like this. if (setGetAccessTokenAuthHeader) { From b438809fc0d3b61b5121035d1cf766eafa18da48 Mon Sep 17 00:00:00 2001 From: Aymeric <34040599+afoyer@users.noreply.github.com> Date: Thu, 19 Nov 2020 20:28:06 -0600 Subject: [PATCH 3/4] updated buffer to avoid deprecation message --- src/server/lib/oauth/callback.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/lib/oauth/callback.js b/src/server/lib/oauth/callback.js index 3cece35377..3dbd7d07e9 100644 --- a/src/server/lib/oauth/callback.js +++ b/src/server/lib/oauth/callback.js @@ -214,7 +214,7 @@ async function _getOAuthAccessToken (code, provider, callback) { if (!headers['Client-ID']) { headers['Client-ID'] = provider.clientId } // Added as a fix for Reddit Authentication if (provider.id === 'reddit') { - headers.Authorization = 'Basic ' + Buffer((provider.clientId + ':' + provider.clientSecret)).toString('base64') + headers.Authorization = 'Basic ' + Buffer.from((provider.clientId + ':' + provider.clientSecret)).toString('base64') } // Okta errors when this is set. Maybe there are other Providers that also wont like this. From 1c052930ef9e6aaef93da7bcc36b87e7dcaed4b8 Mon Sep 17 00:00:00 2001 From: Aymeric <34040599+afoyer@users.noreply.github.com> Date: Thu, 19 Nov 2020 20:31:42 -0600 Subject: [PATCH 4/4] Updated for passing tests --- src/server/lib/oauth/callback.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/server/lib/oauth/callback.js b/src/server/lib/oauth/callback.js index 3dbd7d07e9..121799fddd 100644 --- a/src/server/lib/oauth/callback.js +++ b/src/server/lib/oauth/callback.js @@ -214,9 +214,8 @@ async function _getOAuthAccessToken (code, provider, callback) { if (!headers['Client-ID']) { headers['Client-ID'] = provider.clientId } // Added as a fix for Reddit Authentication if (provider.id === 'reddit') { - headers.Authorization = 'Basic ' + Buffer.from((provider.clientId + ':' + provider.clientSecret)).toString('base64') + headers.Authorization = 'Basic ' + Buffer.from((provider.clientId + ':' + provider.clientSecret)).toString('base64') } - // Okta errors when this is set. Maybe there are other Providers that also wont like this. if (setGetAccessTokenAuthHeader) { if (!headers.Authorization) { headers.Authorization = `Bearer ${code}` }