Skip to content

Commit 9cc11b2

Browse files
author
sachin-maheshwari
authored
Merge pull request #109 from topcoder-platform/dev
Fix for legacy forum broken link for non logged-in user
2 parents 68fdc22 + ef364c3 commit 9cc11b2

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

web-assets/js/setupAuth0WithRedirect.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const authSetup = function () {
4242
const IframeLogoutRequestType = "LOGOUT_REQUEST";
4343
const enterpriseCustomers = ['zurich', 'cs'];
4444
const mode = qs['mode'] || 'signIn';
45-
let returnAppUrl = qs['retUrl'];
45+
let returnAppUrl = handleSpecificReturnUrl(qs['retUrl'], 'retUrl');
4646
let appUrl = qs['appUrl'] || false;
4747

4848
if (utmSource &&
@@ -88,7 +88,7 @@ const authSetup = function () {
8888
logger('handleRedirectCallback() error: ', e);
8989
});
9090
} else if (shouldLogout) {
91-
host = returnAppUrl ? returnAppUrl : host;
91+
host = returnAppUrl ? decodeURIComponent(returnAppUrl) : host;
9292
logout();
9393
return;
9494
} else if (!isLoggedIn() && returnAppUrl) {
@@ -179,6 +179,7 @@ const authSetup = function () {
179179
};
180180

181181
const login = function () {
182+
logger('returnUrl', returnAppUrl);
182183
auth0
183184
.loginWithRedirect({
184185
redirect_uri: host + '?appUrl=' + returnAppUrl,
@@ -622,6 +623,45 @@ const authSetup = function () {
622623
document.cookie = cname + "=" + cvalue + cdomain + expires + ";path=/";
623624
}
624625

626+
function handleSpecificReturnUrl(value, param) {
627+
try {
628+
let hostdomain = "";
629+
if (location.hostname !== 'localhost') {
630+
hostdomain = "." + location.hostname.split('.').reverse()[1] +
631+
"." + location.hostname.split('.').reverse()[0];
632+
}
633+
const prefixArray = ['apps', 'software'];
634+
if (hostdomain && value) {
635+
for (let i = 0; i < prefixArray.length; i++) {
636+
if (value.indexOf(prefixArray[i] + hostdomain) > -1) {
637+
const queryParam = window.location.search.substr(1);
638+
if (queryParam) {
639+
const indx = queryParam.indexOf(param);
640+
if (indx > -1) {
641+
//assuming queryParam value like retUrl=xxxxxx
642+
const result = queryParam.substring(indx + param.length + 1);
643+
// verify broken url : https://abc.com/&utm=abc
644+
logger('handleSpecificReturnUrl: match query result', result);
645+
if (result.indexOf('&') > -1 && result.indexOf('?') === -1) {
646+
return value;
647+
}
648+
return encodeURIComponent(decodeURIComponent(result));
649+
} else {
650+
return value;
651+
}
652+
} else {
653+
return value;
654+
}
655+
}
656+
}
657+
return value;
658+
}
659+
return value;
660+
} catch (e) {
661+
logger('Issue while handling specific query param function', e.message);
662+
return value;
663+
}
664+
};
625665

626666
// execute
627667
init();

web-assets/local/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Open index.html to get the token locally.

web-assets/local/index.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>Auth0</title>
6+
<meta charset="utf-8" />
7+
<script language="javascript" type="text/javascript"
8+
src="https://accounts-auth0.topcoder-dev.com/setupAuth0WithRedirect.js"></script>
9+
</head>
10+
11+
<body>
12+
<script>
13+
window.onload = authSetup;
14+
15+
function doLogin() {
16+
window.location = './?retUrl=http://' + location.host
17+
}
18+
19+
function doLogout() {
20+
window.location = './?logout=true&retUrl=http://' + location.host
21+
}
22+
</script>
23+
<div>
24+
<p>Instructions:</p>
25+
<p>
26+
Run this index.html as local server like - http://localhost:3000 and keep open in seperate tab for
27+
refreshing token.
28+
</p>
29+
</div>
30+
<p>----------------------------------</p>
31+
<div>
32+
<span>Click Here To Login! </span><span><a href="#" onclick="doLogin();">Login</a></span>
33+
</div>
34+
<p>----------------------------------</p>
35+
<div>
36+
<span>Click Here To Logout! </span> <span> <a href="#" onclick="doLogout();">Logout</a> </span>
37+
</div>
38+
</body>
39+
40+
</html>

0 commit comments

Comments
 (0)