From 74967d0b01b986c6d3f38250988351a7c208f15b Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Fri, 18 Feb 2022 14:02:23 +0530 Subject: [PATCH 1/8] plat-700, discord redirect --- web-assets/js/setupAuth0WithRedirect.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/web-assets/js/setupAuth0WithRedirect.js b/web-assets/js/setupAuth0WithRedirect.js index b6404b7..63acbc5 100644 --- a/web-assets/js/setupAuth0WithRedirect.js +++ b/web-assets/js/setupAuth0WithRedirect.js @@ -46,6 +46,7 @@ const authSetup = function () { const mode = qs['mode'] || 'signIn'; let returnAppUrl = handleSpecificReturnUrl(qs['retUrl'], 'retUrl'); let appUrl = qs['appUrl'] || false; + const discord_pattern = 'https://tc-topbot-1.herokuapp.com/'; if (utmSource && (utmSource != 'undefined') && @@ -237,10 +238,22 @@ const authSetup = function () { } const redirectToApp = function () { - logger("redirect to app", appUrl); - if (appUrl) { - window.location = appUrl; + logger("redirect to app", appUrl); + if (appUrl) { + if (appUrl.indexOf(discord_pattern) > -1) { + try { + var newUrl = new URL(appUrl); + window.location = newUrl.searchParams.append( + "token", + getCookie(v3JWTCookie) + ).href; + } catch (e) { + logger("Error in redirect to discord", e.message) + } + } else { + window.location = appUrl; } + } }; const postLogin = function () { From f76e7e080eaa199818574fa5b27f27eabcdb1a0d Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Fri, 18 Feb 2022 14:05:01 +0530 Subject: [PATCH 2/8] plat-700, deploying... --- .circleci/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3f8a712..6b9e738 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -70,8 +70,7 @@ workflows: branches: only: - dev - - hotfix/resendActivationEmail - - feat/plat-320 + - jira-plat-700 # Production builds are exectuted only on tagged commits to the # master branch. From 9a4ded1b9f86a20a955381a569fd73e92118ff99 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Fri, 18 Feb 2022 14:14:51 +0530 Subject: [PATCH 3/8] plat-700 --- web-assets/js/setupAuth0WithRedirect.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/web-assets/js/setupAuth0WithRedirect.js b/web-assets/js/setupAuth0WithRedirect.js index 63acbc5..4524407 100644 --- a/web-assets/js/setupAuth0WithRedirect.js +++ b/web-assets/js/setupAuth0WithRedirect.js @@ -243,12 +243,14 @@ const authSetup = function () { if (appUrl.indexOf(discord_pattern) > -1) { try { var newUrl = new URL(appUrl); - window.location = newUrl.searchParams.append( + newUrl.searchParams.append( "token", getCookie(v3JWTCookie) - ).href; + ); + window.location = newUrl.href; } catch (e) { - logger("Error in redirect to discord", e.message) + logger("Error in redirect to discord", e.message); + window.location = appUrl; } } else { window.location = appUrl; From eae5e664aa10aa46a8b59856e560f532fa571aa7 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Mon, 21 Feb 2022 16:57:41 +0530 Subject: [PATCH 4/8] redirect with token once user is already logged in --- web-assets/js/setupAuth0WithRedirect.js | 36 ++++++++++++++----------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/web-assets/js/setupAuth0WithRedirect.js b/web-assets/js/setupAuth0WithRedirect.js index 4524407..8a61555 100644 --- a/web-assets/js/setupAuth0WithRedirect.js +++ b/web-assets/js/setupAuth0WithRedirect.js @@ -240,21 +240,7 @@ const authSetup = function () { const redirectToApp = function () { logger("redirect to app", appUrl); if (appUrl) { - if (appUrl.indexOf(discord_pattern) > -1) { - try { - var newUrl = new URL(appUrl); - newUrl.searchParams.append( - "token", - getCookie(v3JWTCookie) - ); - window.location = newUrl.href; - } catch (e) { - logger("Error in redirect to discord", e.message); - window.location = appUrl; - } - } else { - window.location = appUrl; - } + hookRedirect(appUrl); } }; @@ -262,7 +248,7 @@ const authSetup = function () { if (isLoggedIn() && returnAppUrl) { auth0.isAuthenticated().then(function (isAuthenticated) { if (isAuthenticated) { - window.location = returnAppUrl; + hookRedirect(returnAppUrl); } else { login(); // old session exist case } @@ -718,6 +704,24 @@ const authSetup = function () { } }; + function hookRedirect(redirect_url) { + if (redirect_url && (redirect_url.indexOf(discord_pattern) > -1)) { + try { + var newUrl = new URL(redirect_url); + newUrl.searchParams.append( + "token", + getCookie(v3JWTCookie) + ); + window.location = newUrl.href; + } catch (e) { + logger("Error in redirecting to discord", e.message); + window.location = redirect_url; + } + } else { + window.location = redirect_url; + } + } + // execute init(); }; From 08578b319b980d70b25e15d994ed4aa8b07ec133 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Mon, 21 Feb 2022 17:17:54 +0530 Subject: [PATCH 5/8] query param issue --- web-assets/js/setupAuth0WithRedirect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-assets/js/setupAuth0WithRedirect.js b/web-assets/js/setupAuth0WithRedirect.js index 8a61555..14f44ee 100644 --- a/web-assets/js/setupAuth0WithRedirect.js +++ b/web-assets/js/setupAuth0WithRedirect.js @@ -671,7 +671,7 @@ const authSetup = function () { hostdomain = "." + location.hostname.split('.').reverse()[1] + "." + location.hostname.split('.').reverse()[0]; } - const prefixArray = ['apps', 'software']; + const prefixArray = ['apps', 'software', 'herokuapp']; if (hostdomain && value) { for (let i = 0; i < prefixArray.length; i++) { if (value.indexOf(prefixArray[i] + hostdomain) > -1) { From 024e981c32cf462e030a09ef773dcc338a60d94c Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Mon, 21 Feb 2022 19:26:31 +0530 Subject: [PATCH 6/8] adding pattern for local testing --- web-assets/js/setupAuth0WithRedirect.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web-assets/js/setupAuth0WithRedirect.js b/web-assets/js/setupAuth0WithRedirect.js index 14f44ee..1312804 100644 --- a/web-assets/js/setupAuth0WithRedirect.js +++ b/web-assets/js/setupAuth0WithRedirect.js @@ -46,7 +46,7 @@ const authSetup = function () { const mode = qs['mode'] || 'signIn'; let returnAppUrl = handleSpecificReturnUrl(qs['retUrl'], 'retUrl'); let appUrl = qs['appUrl'] || false; - const discord_pattern = 'https://tc-topbot-1.herokuapp.com/'; + const discord_patterns = ['https://tc-topbot-1.herokuapp.com/', 'webhooks']; if (utmSource && (utmSource != 'undefined') && @@ -705,7 +705,7 @@ const authSetup = function () { }; function hookRedirect(redirect_url) { - if (redirect_url && (redirect_url.indexOf(discord_pattern) > -1)) { + if (redirect_url && ((redirect_url.indexOf(discord_patterns[0]) > -1) || (redirect_url.indexOf(discord_patterns[1]) > -1) ) ) { try { var newUrl = new URL(redirect_url); newUrl.searchParams.append( From 344255e4386a29d9e147f83aa96fd35cdf07ee54 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 22 Feb 2022 13:44:31 +0530 Subject: [PATCH 7/8] cleaning up --- web-assets/js/setupAuth0WithRedirect.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web-assets/js/setupAuth0WithRedirect.js b/web-assets/js/setupAuth0WithRedirect.js index 1312804..8a61555 100644 --- a/web-assets/js/setupAuth0WithRedirect.js +++ b/web-assets/js/setupAuth0WithRedirect.js @@ -46,7 +46,7 @@ const authSetup = function () { const mode = qs['mode'] || 'signIn'; let returnAppUrl = handleSpecificReturnUrl(qs['retUrl'], 'retUrl'); let appUrl = qs['appUrl'] || false; - const discord_patterns = ['https://tc-topbot-1.herokuapp.com/', 'webhooks']; + const discord_pattern = 'https://tc-topbot-1.herokuapp.com/'; if (utmSource && (utmSource != 'undefined') && @@ -671,7 +671,7 @@ const authSetup = function () { hostdomain = "." + location.hostname.split('.').reverse()[1] + "." + location.hostname.split('.').reverse()[0]; } - const prefixArray = ['apps', 'software', 'herokuapp']; + const prefixArray = ['apps', 'software']; if (hostdomain && value) { for (let i = 0; i < prefixArray.length; i++) { if (value.indexOf(prefixArray[i] + hostdomain) > -1) { @@ -705,7 +705,7 @@ const authSetup = function () { }; function hookRedirect(redirect_url) { - if (redirect_url && ((redirect_url.indexOf(discord_patterns[0]) > -1) || (redirect_url.indexOf(discord_patterns[1]) > -1) ) ) { + if (redirect_url && (redirect_url.indexOf(discord_pattern) > -1)) { try { var newUrl = new URL(redirect_url); newUrl.searchParams.append( From f0df5648180e6a13dbe3c831907f431a3f34af8d Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 22 Feb 2022 13:49:21 +0530 Subject: [PATCH 8/8] clean up --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6b9e738..5a31496 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -70,7 +70,6 @@ workflows: branches: only: - dev - - jira-plat-700 # Production builds are exectuted only on tagged commits to the # master branch.