Compare commits
2 Commits
dbc09bd7af
...
e5641b8068
Author | SHA1 | Date | |
---|---|---|---|
e5641b8068 | |||
ae915babe6 |
@ -78,8 +78,8 @@ func NewServer() {
|
|||||||
api.Post("/auth/token", exchangeToken)
|
api.Post("/auth/token", exchangeToken)
|
||||||
api.Post("/auth/factors/:factorId", requestFactorToken)
|
api.Post("/auth/factors/:factorId", requestFactorToken)
|
||||||
|
|
||||||
api.Get("/auth/oauth/connect", auth, preConnect)
|
api.Get("/auth/o/connect", auth, preConnect)
|
||||||
api.Post("/auth/oauth/connect", auth, doConnect)
|
api.Post("/auth/o/connect", auth, doConnect)
|
||||||
}
|
}
|
||||||
|
|
||||||
A.Use("/", cache.New(cache.Config{
|
A.Use("/", cache.New(cache.Config{
|
||||||
|
@ -20,7 +20,7 @@ func getOidcConfiguration(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
return c.JSON(fiber.Map{
|
return c.JSON(fiber.Map{
|
||||||
"issuer": basepath,
|
"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),
|
"token_endpoint": fmt.Sprintf("%s/api/auth/token", basepath),
|
||||||
"userinfo_endpoint": fmt.Sprintf("%s/api/users/me", basepath),
|
"userinfo_endpoint": fmt.Sprintf("%s/api/users/me", basepath),
|
||||||
"response_types_supported": []string{"code", "token"},
|
"response_types_supported": []string{"code", "token"},
|
||||||
|
@ -23,8 +23,8 @@ render(() => (
|
|||||||
<Route path="/personalise" component={lazy(() => import("./pages/personalise.tsx"))} />
|
<Route path="/personalise" component={lazy(() => import("./pages/personalise.tsx"))} />
|
||||||
<Route path="/auth/login" component={lazy(() => import("./pages/auth/login.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/register" component={lazy(() => import("./pages/auth/register.tsx"))} />
|
||||||
<Route path="/auth/oauth/connect" component={lazy(() => import("./pages/auth/connect.tsx"))} />
|
<Route path="/auth/o/connect" component={lazy(() => import("./pages/auth/connect.tsx"))} />
|
||||||
<Route path="/auth/oauth/callback" component={lazy(() => import("./pages/auth/callback.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"))} />
|
<Route path="/users/me/confirm" component={lazy(() => import("./pages/users/confirm.tsx"))} />
|
||||||
</Router>
|
</Router>
|
||||||
</UserinfoProvider>
|
</UserinfoProvider>
|
||||||
|
@ -21,15 +21,16 @@ export default function RootLayout(props: any) {
|
|||||||
}, [ready, userinfo]);
|
}, [ready, userinfo]);
|
||||||
|
|
||||||
function keepGate(path: string, e?: BeforeLeaveEventArgs) {
|
function keepGate(path: string, e?: BeforeLeaveEventArgs) {
|
||||||
|
const pathname = path.split("?")[0];
|
||||||
const whitelist = ["/auth/login", "/auth/register", "/users/me/confirm"];
|
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();
|
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 (
|
return (
|
||||||
<Show when={ready()} fallback={
|
<Show when={ready()} fallback={
|
||||||
|
@ -18,7 +18,7 @@ export default function OauthConnectPage() {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
async function preConnect() {
|
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()}` }
|
headers: { "Authorization": `Bearer ${getAtk()}` }
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ export default function OauthConnectPage() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
setStatus("Approving...");
|
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,
|
client_id: searchParams["client_id"] as string,
|
||||||
redirect_uri: encodeURIComponent(searchParams["redirect_uri"] as string),
|
redirect_uri: encodeURIComponent(searchParams["redirect_uri"] as string),
|
||||||
response_type: "code",
|
response_type: "code",
|
||||||
|
@ -89,7 +89,7 @@ export default function LoginPage() {
|
|||||||
if (data["is_finished"]) {
|
if (data["is_finished"]) {
|
||||||
await grantToken(data["session"]["grant_token"]);
|
await grantToken(data["session"]["grant_token"]);
|
||||||
await readProfiles();
|
await readProfiles();
|
||||||
navigate(searchParams["redirect_uri"] ?? "/");
|
navigate(searchParams["redirect_uri"] ? decodeURIComponent(searchParams["redirect_uri"]) : "/");
|
||||||
} else {
|
} else {
|
||||||
setError(null);
|
setError(null);
|
||||||
setStage("choosing");
|
setStage("choosing");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user