Sign-in: the mail server page shows the light or dark look in use here #87
No files matched your search
@@ -540,6 +540,9 @@ export function createApp(basePath = config.basePath): Hono<Env> {
|
||||
* `callback` is where the server sends it back. See oauth.ts.
|
||||
*/
|
||||
const OAUTH_STATE_COOKIE = `${config.cookieName}_signin`;
|
||||
/** The look the browser asked the server's sign-in page for, if it is one we pass on. */
|
||||
const signInTheme = (value: string | undefined): "light" | "dark" | undefined =>
|
||||
value === "light" || value === "dark" ? value : undefined;
|
||||
|
||||
api.get("/auth/oauth/start", async (c) => {
|
||||
if (!oauthEnabled()) return c.json({ error: "not_found" }, 404);
|
||||
@@ -561,6 +564,7 @@ export function createApp(basePath = config.basePath): Hono<Env> {
|
||||
base: upstreamFor(username),
|
||||
remember: c.req.query("remember") === "1",
|
||||
adding: front !== null,
|
||||
theme: signInTheme(c.req.query("theme")),
|
||||
});
|
||||
setCookie(c, OAUTH_STATE_COOKIE, state, { httpOnly: true, sameSite: "Lax", secure: isSecureRequest(c), path: `${basePath}/api/auth`, maxAge: 600 });
|
||||
return c.redirect(location, 302);
|
||||
|
||||
@@ -119,6 +119,15 @@ test("start sends the browser to the server's page with PKCE and a bound state",
|
||||
assert.equal(jar.get("ihm_session_signin"), to.searchParams.get("state"), "the state is bound to this browser");
|
||||
});
|
||||
|
||||
test("start passes on the light or dark look for the server's page, and nothing else", async () => {
|
||||
const look = async (theme: string) =>
|
||||
new URL((await call(`/api/auth/oauth/[email protected]&theme=${encodeURIComponent(theme)}`)).headers.get("location")!).searchParams.get("theme");
|
||||
assert.equal(await look("dark"), "dark");
|
||||
assert.equal(await look("light"), "light");
|
||||
assert.equal(await look("<script>"), null);
|
||||
assert.equal(await look(""), null);
|
||||
});
|
||||
|
||||
test("a full sign-in holds tokens, and the session works", async () => {
|
||||
await signIn();
|
||||
const res = await call("/api/auth/session");
|
||||
|
||||
+4
-1
@@ -116,7 +116,7 @@ function challengeOf(verifier: string): string {
|
||||
* Begin a sign-in. Returns where to send the browser, and the state to bind
|
||||
* to it in a cookie.
|
||||
*/
|
||||
export async function start(params: { username: string; base: string; remember: boolean; adding?: boolean }): Promise<{ location: string; state: string }> {
|
||||
export async function start(params: { username: string; base: string; remember: boolean; adding?: boolean; theme?: "light" | "dark" }): Promise<{ location: string; state: string }> {
|
||||
const metadata = await metadataFor(params.base);
|
||||
sweepPending();
|
||||
if (pending.size >= MAX_PENDING) throw new UpstreamError("Too many sign-ins in progress", 503);
|
||||
@@ -136,6 +136,9 @@ export async function start(params: { username: string; base: string; remember:
|
||||
// MA-B: ask again, rather than let the server's page reuse the sign-in of
|
||||
// the account already in front
|
||||
if (params.adding) url.searchParams.set("prompt", "login");
|
||||
// inbuxa-server #375: the server's page shows the light or dark look the
|
||||
// reader has here; a server that doesn't know the parameter ignores it
|
||||
if (params.theme) url.searchParams.set("theme", params.theme);
|
||||
return { location: url.toString(), state };
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* The light or dark look on screen, for the mail server's sign-in page to
|
||||
* match (inbuxa-server #375). `applyTheme` has already resolved "follow the
|
||||
* system" into one of the two, so this is what the reader is looking at.
|
||||
*/
|
||||
export function signInTheme(): "light" | "dark" {
|
||||
return document.documentElement.dataset.theme === "dark" ? "dark" : "light";
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { useEffect, useState, type FormEvent } from "react";
|
||||
import { Dialog } from "@/ui/dialog";
|
||||
import { apiFetch } from "@/jmap/client";
|
||||
import { withBase } from "@/lib/basePath";
|
||||
import { signInTheme } from "@/lib/signInTheme";
|
||||
import { clearSignedInData, isDeviceTrusted } from "@/lib/storage";
|
||||
import { t } from "@/lib/i18n";
|
||||
|
||||
@@ -50,7 +51,7 @@ export function AddAccountDialog({ open, onClose }: { open: boolean; onClose: ()
|
||||
setBusy(true);
|
||||
// What is cached belongs to the account in front, which won't be
|
||||
clearSignedInData();
|
||||
const params = new URLSearchParams({ add: "1", ...(address ? { username: address } : {}), ...(remember ? { remember: "1" } : {}) });
|
||||
const params = new URLSearchParams({ add: "1", ...(address ? { username: address } : {}), ...(remember ? { remember: "1" } : {}), theme: signInTheme() });
|
||||
window.location.assign(withBase(`/api/auth/oauth/start?${params}`));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Eye, EyeOff, LogIn } from "lucide-react";
|
||||
import { useSession } from "@/store/session";
|
||||
import { ApiError } from "@/jmap/client";
|
||||
import { withBase } from "@/lib/basePath";
|
||||
import { signInTheme } from "@/lib/signInTheme";
|
||||
import { APP_VERSION } from "@/lib/version";
|
||||
import { DEFAULT_SOURCE_URL } from "@/lib/source";
|
||||
import { DEFAULT_APP_NAME, brandImage } from "@/lib/brand";
|
||||
@@ -64,7 +65,7 @@ export function LoginPage() {
|
||||
if (!direct && !username.trim()) return;
|
||||
setBusy(true);
|
||||
if (trustDevice && !direct) localStorage.setItem("ihasmail:lastUser", username.trim());
|
||||
const params = new URLSearchParams({ ...(direct ? {} : { username: username.trim() }), ...(trustDevice ? { remember: "1" } : {}) });
|
||||
const params = new URLSearchParams({ ...(direct ? {} : { username: username.trim() }), ...(trustDevice ? { remember: "1" } : {}), theme: signInTheme() });
|
||||
window.location.assign(withBase(`/api/auth/oauth/start?${params}`));
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user