Compare commits

..

2 Commits

Author SHA1 Message Date
e5641b8068 🐛 Fix guard generate redirect uri ignore query strings 2024-02-01 21:42:47 +08:00
ae915babe6 🚚 Move oauth url 2024-02-01 21:36:46 +08:00
6 changed files with 12 additions and 11 deletions

View File

@ -78,8 +78,8 @@ func NewServer() {
api.Post("/auth/token", exchangeToken)
api.Post("/auth/factors/:factorId", requestFactorToken)
api.Get("/auth/oauth/connect", auth, preConnect)
api.Post("/auth/oauth/connect", auth, doConnect)
api.Get("/auth/o/connect", auth, preConnect)
api.Post("/auth/o/connect", auth, doConnect)
}
A.Use("/", cache.New(cache.Config{

View File

@ -20,7 +20,7 @@ func getOidcConfiguration(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"issuer": basepath,
"authorization_endpoint": fmt.Sprintf("%s/auth/oauth/connect", basepath),
"authorization_endpoint": fmt.Sprintf("%s/auth/o/connect", basepath),
"token_endpoint": fmt.Sprintf("%s/api/auth/token", basepath),
"userinfo_endpoint": fmt.Sprintf("%s/api/users/me", basepath),
"response_types_supported": []string{"code", "token"},

View File

@ -23,8 +23,8 @@ render(() => (
<Route path="/personalise" component={lazy(() => import("./pages/personalise.tsx"))} />
<Route path="/auth/login" component={lazy(() => import("./pages/auth/login.tsx"))} />
<Route path="/auth/register" component={lazy(() => import("./pages/auth/register.tsx"))} />
<Route path="/auth/oauth/connect" component={lazy(() => import("./pages/auth/connect.tsx"))} />
<Route path="/auth/oauth/callback" component={lazy(() => import("./pages/auth/callback.tsx"))} />
<Route path="/auth/o/connect" component={lazy(() => import("./pages/auth/connect.tsx"))} />
<Route path="/auth/o/callback" component={lazy(() => import("./pages/auth/callback.tsx"))} />
<Route path="/users/me/confirm" component={lazy(() => import("./pages/users/confirm.tsx"))} />
</Router>
</UserinfoProvider>

View File

@ -21,15 +21,16 @@ export default function RootLayout(props: any) {
}, [ready, userinfo]);
function keepGate(path: string, e?: BeforeLeaveEventArgs) {
const pathname = path.split("?")[0];
const whitelist = ["/auth/login", "/auth/register", "/users/me/confirm"];
if (!userinfo?.isLoggedIn && !whitelist.includes(path)) {
if (!userinfo?.isLoggedIn && !whitelist.includes(pathname)) {
if (!e?.defaultPrevented) e?.preventDefault();
navigate(`/auth/login?redirect_uri=${path}`);
navigate(`/auth/login?redirect_uri=${encodeURIComponent(path)}`);
}
}
useBeforeLeave((e: BeforeLeaveEventArgs) => keepGate(e.to.toString().split("?")[0], e));
useBeforeLeave((e: BeforeLeaveEventArgs) => keepGate(e.to.toString(), e));
return (
<Show when={ready()} fallback={

View File

@ -18,7 +18,7 @@ export default function OauthConnectPage() {
const location = useLocation();
async function preConnect() {
const res = await fetch(`/api/auth/oauth/connect${location.search}`, {
const res = await fetch(`/api/auth/o/connect${location.search}`, {
headers: { "Authorization": `Bearer ${getAtk()}` }
});
@ -51,7 +51,7 @@ export default function OauthConnectPage() {
setLoading(true);
setStatus("Approving...");
const res = await fetch("/api/auth/oauth/connect?" + new URLSearchParams({
const res = await fetch("/api/auth/o/connect?" + new URLSearchParams({
client_id: searchParams["client_id"] as string,
redirect_uri: encodeURIComponent(searchParams["redirect_uri"] as string),
response_type: "code",

View File

@ -89,7 +89,7 @@ export default function LoginPage() {
if (data["is_finished"]) {
await grantToken(data["session"]["grant_token"]);
await readProfiles();
navigate(searchParams["redirect_uri"] ?? "/");
navigate(searchParams["redirect_uri"] ? decodeURIComponent(searchParams["redirect_uri"]) : "/");
} else {
setError(null);
setStage("choosing");