Skip to content

Commit 52c62ab

Browse files
committed
Fix #36445: make auth-success page work independently of scheme
1 parent 1b92567 commit 52c62ab

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/ui/AuthController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ public Object getLoginPage(@RequestParam Optional<String> error, ModelMap map) {
8484
@RequestMapping(value = AUTH_SUCCESS_URL, method = RequestMethod.GET)
8585
public String authSuccess(ModelMap map, HttpServletRequest request) {
8686
prepareMap(map);
87-
map.put("url", ServletUriComponentsBuilder.fromCurrentContextPath().path("/").build().toUriString()); // default url
87+
// protocol is added to the url on the client-side
88+
map.put("url", ServletUriComponentsBuilder.fromCurrentContextPath().path("/").build().toUriString().replace("https://", "//").replace("http://", "//")); // default url
8889

8990
Object redirectUrl = request.getSession().getAttribute(AUTH_SUCCESS_URL_SESSION_ATTR);
9091
if (redirectUrl instanceof String sRedirectUrl) {
9192
request.getSession().removeAttribute(AUTH_SUCCESS_URL_SESSION_ATTR);
9293
// sanity check: does the redirect url start with the url of this current request
9394
if (sRedirectUrl.startsWith(ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString())) {
94-
map.put("url", redirectUrl);
95+
map.put("url", sRedirectUrl.replace("https://", "//").replace("http://", "//"));
9596
}
9697
}
9798
return "auth-success";

src/main/resources/templates/auth-success.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
<script th:inline="javascript" type="text/javascript">
3131
history.forward();
3232
history.pushState({}, "", new URL(location));
33-
history.pushState({}, "", new URL([[${url}]]));
34-
window.location.href = [[${url}]];
33+
const fullUrl = location.protocol + [[${url}]];
34+
history.pushState({}, "", new URL(fullUrl));
35+
window.location.href = fullUrl;
3536
</script>
3637
<script>
3738
console.log("This page should redirect you to the main ShinyProxy page after authentication.");

0 commit comments

Comments
 (0)