mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-01-30 14:30:08 +08:00
fix(front+backend): properly generate logout urls with token
This commit is contained in:
parent
825fb5f8f3
commit
f1bd2387fa
@ -94,19 +94,20 @@ public class LoginController extends HangarComponent {
|
||||
}
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping(path = "/logout", params = "returnUrl")
|
||||
public RedirectView logout(@RequestParam(defaultValue = "/logged-out") String returnUrl) {
|
||||
public String logout(@RequestParam(defaultValue = "/?loggedOut") String returnUrl) {
|
||||
if (config.fakeUser.enabled()) {
|
||||
response.addCookie(new Cookie("url", returnUrl));
|
||||
return new RedirectView("/fake-logout");
|
||||
return "/fake-logout";
|
||||
} else {
|
||||
response.addCookie(new Cookie("url", returnUrl));
|
||||
Optional<HangarPrincipal> principal = getOptionalHangarPrincipal();
|
||||
if (principal.isPresent()) {
|
||||
return redirectToSso(ssoService.getLogoutUrl(config.getBaseUrl() + "/handle-logout", principal.get()));
|
||||
return ssoService.getLogoutUrl(config.getBaseUrl() + "/handle-logout", principal.get()).getUrl();
|
||||
} else {
|
||||
tokenService.invalidateToken(null);
|
||||
return addBaseAndRedirect(returnUrl);
|
||||
return addBase(returnUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -175,6 +176,10 @@ public class LoginController extends HangarComponent {
|
||||
}
|
||||
|
||||
private RedirectView addBaseAndRedirect(String url) {
|
||||
return new RedirectView(addBase(url));
|
||||
}
|
||||
|
||||
private String addBase(String url) {
|
||||
if (!url.startsWith("http")) {
|
||||
if (url.startsWith("/")) {
|
||||
url = config.getBaseUrl() + url;
|
||||
@ -182,7 +187,7 @@ public class LoginController extends HangarComponent {
|
||||
url = config.getBaseUrl() + "/" + url;
|
||||
}
|
||||
}
|
||||
return new RedirectView(url);
|
||||
return url;
|
||||
}
|
||||
|
||||
private RedirectView redirectToSso(URLWithNonce urlWithNonce) {
|
||||
|
@ -6,8 +6,9 @@ import { useCookies } from "~/composables/useCookies";
|
||||
import { useInternalApi } from "~/composables/useApi";
|
||||
import { authLog } from "~/lib/composables/useLog";
|
||||
import { useConfig } from "~/lib/composables/useConfig";
|
||||
import { useRequestEvent } from "#imports";
|
||||
import { handleRequestError, useRequestEvent } from "#imports";
|
||||
import { useAxios } from "~/composables/useAxios";
|
||||
import { useNotificationStore } from "~/lib/store/notification";
|
||||
|
||||
class Auth {
|
||||
loginUrl(redirectUrl: string): string {
|
||||
@ -17,8 +18,15 @@ class Auth {
|
||||
return `/login?returnUrl=${useConfig().publicHost}${redirectUrl}`;
|
||||
}
|
||||
|
||||
logout() {
|
||||
location.replace(`/logout?returnUrl=${useConfig().publicHost}?loggedOut`);
|
||||
async logout() {
|
||||
const result = await useAxios()
|
||||
.get(`/logout?returnUrl=${useConfig().publicHost}?loggedOut`)
|
||||
.catch((e) => handleRequestError(e));
|
||||
if ("status" in result && result?.status === 200 && result?.data) {
|
||||
location.replace(result?.data);
|
||||
} else {
|
||||
useNotificationStore().error("Error while logging out?!");
|
||||
}
|
||||
}
|
||||
|
||||
validateToken(token: unknown): token is string {
|
||||
|
Loading…
Reference in New Issue
Block a user