From 65ced91e9ca5752157e29dc97b910a96a03e5a25 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 15 Dec 2020 19:20:29 +0530 Subject: [PATCH 1/5] matching cookie expiry time with token expiry and introducing 'mode' to distinguish between signIn and signUp --- web-assets/js/.DS_Store | Bin 0 -> 6148 bytes web-assets/js/setupAuth0WithRedirect.js | 71 +++++++++++++++++++++--- 2 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 web-assets/js/.DS_Store diff --git a/web-assets/js/.DS_Store b/web-assets/js/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 0) { + return diff; // in milliseconds + } + return false; + } + + function setDomainCookie(cname, cvalue, exMilliSeconds) { + const cdomain = getHostDomain(); + + let d = new Date(); + d.setTime(d.getTime() + exMilliSeconds); + + let expires = ";expires=" + d.toUTCString(); + document.cookie = cname + "=" + cvalue + cdomain + expires + ";path=/"; + } + + // execute init(); }; From 97beb75e715b237bb10892f7e0638fcf10d36d0d Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 15 Dec 2020 19:23:25 +0530 Subject: [PATCH 2/5] cleanup --- web-assets/js/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 web-assets/js/.DS_Store diff --git a/web-assets/js/.DS_Store b/web-assets/js/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Tue, 15 Dec 2020 19:36:17 +0530 Subject: [PATCH 3/5] correcting changes for dev env --- web-assets/js/setupAuth0WithRedirect.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web-assets/js/setupAuth0WithRedirect.js b/web-assets/js/setupAuth0WithRedirect.js index 8a6d433..1598bd5 100644 --- a/web-assets/js/setupAuth0WithRedirect.js +++ b/web-assets/js/setupAuth0WithRedirect.js @@ -23,8 +23,8 @@ const qs = (function (a) { const authSetup = function () { - let domain = 'auth.topcoder.com'; - const clientId = 'UW7BhsnmAQh0itl56g1jUPisBO9GoowD'; + let domain = 'auth.topcoder-dev.com'; + const clientId = 'BXWXUWnilVUPdN01t2Se29Tw2ZYNGZvH'; const useLocalStorage = false; const useRefreshTokens = false; const v3JWTCookie = 'v3jwt'; @@ -38,7 +38,7 @@ const authSetup = function () { const utmSource = qs['utm_source']; const utmMedium = qs['utm_medium']; const utmCampaign = qs['utm_campaign']; - const loggerMode = "prod"; + const loggerMode = "dev"; const IframeLogoutRequestType = "LOGOUT_REQUEST"; const enterpriseCustomers = ['zurich', 'cs']; const mode = qs['mode'] || 'signIn'; @@ -48,7 +48,7 @@ const authSetup = function () { if (utmSource && (utmSource != 'undefined') && (enterpriseCustomers.indexOf(utmSource) > -1)) { - domain = "topcoder.auth0.com"; + domain = "topcoder-dev.auth0.com"; returnAppUrl += '&utm_source=' + utmSource; } From e21bcb0ffc9ae7b3c1d5e45a7d66d93e270b5475 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Wed, 16 Dec 2020 13:26:19 +0530 Subject: [PATCH 4/5] fetch cookie value dynamically --- src/connector-wrapper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connector-wrapper.js b/src/connector-wrapper.js index 6622a04..b9f4eab 100644 --- a/src/connector-wrapper.js +++ b/src/connector-wrapper.js @@ -49,7 +49,7 @@ const proxyCall = function () { if (safeFormat) { window.removeEventListener('message', receiveMessage) if (e.data.type === "SUCCESS") { - token ? resolve({ token: token }) : reject("v3jwt cookie not found") + getToken('v3jwt') ? resolve({ token: getToken('v3jwt') }) : reject("v3jwt cookie not found") } else { reject("unable to get refesh token") } From 6afc604b54adec0cce22b89ed1ec8416a153faba Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Thu, 17 Dec 2020 13:05:16 +0530 Subject: [PATCH 5/5] sliently retrying login if auth0 session avaialble --- web-assets/js/setupAuth0WithRedirect.js | 26 ++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/web-assets/js/setupAuth0WithRedirect.js b/web-assets/js/setupAuth0WithRedirect.js index 1598bd5..8f6bdaf 100644 --- a/web-assets/js/setupAuth0WithRedirect.js +++ b/web-assets/js/setupAuth0WithRedirect.js @@ -515,7 +515,31 @@ const authSetup = function () { if (token && !isTokenExpired(token)) { informIt(success); } else if (!token) { - informIt(failed); + const auth0Session = getCookie('auth0.is.authenticated'); + logger('auth0 session available ?', auth0Session); + if (auth0Session) { + logger('auth session true', 1); + if (!auth0) { + createAuth0Client({ + domain: domain, + client_id: clientId, + cacheLocation: useLocalStorage + ? 'localstorage' + : 'memory', + useRefreshTokens: useRefreshTokens + }).then(function (newAuth0Obj) { + getToken(newAuth0Obj); + }).catch(function (e) { + logger("Error occurred in re-initializing auth0 object: ", e); + informIt(failed); + }); + } else { + getToken(auth0); + } + } else { + informIt(failed); + } + } else { if (auth0) { getToken(auth0);