mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
fix(native): a failed SSO round trip from the app still hands back on the retry
A sign-in the app starts runs through the server's handoff page in the system browser. When the SSO callback failed (an expired or overwritten state), the login page dropped the way back to that page, so the retry from there was a plain web login and ended in the web app inside the app's browser sheet instead of signing in the app. The login page now keeps a way back that points at the handoff page, and only that, and renews its fallback copy for a slow retry. State, nonce, PKCE and the handoff verifier are unchanged; the handoff page still asks for a tap before it passes anything on.
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
BrowserSignInCancelled,
|
||||
createHandoffSecret,
|
||||
handoffUrl,
|
||||
isHandoffReturn,
|
||||
rememberHandoffReturn,
|
||||
requestHandoffCode,
|
||||
resumeBrowserSignIn,
|
||||
@@ -199,6 +200,14 @@ describe('the remembered handoff return', () => {
|
||||
localStorage.setItem('trek_native_handoff_return', 'not json');
|
||||
expect(takeHandoffReturn()).toBeNull();
|
||||
});
|
||||
|
||||
it('tells a way back to the handoff page from any other stored path', () => {
|
||||
expect(isHandoffReturn(path)).toBe(true);
|
||||
expect(isHandoffReturn('/native-handoff')).toBe(false);
|
||||
expect(isHandoffReturn('/oauth/consent?client_id=foo')).toBe(false);
|
||||
expect(isHandoffReturn(null)).toBe(false);
|
||||
expect(isHandoffReturn(42)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('signInWithPasskey', () => {
|
||||
|
||||
@@ -50,6 +50,11 @@ export function rememberHandoffReturn(path: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** A path back to the handoff page itself, and nothing else a stored value could point at. */
|
||||
export function isHandoffReturn(path: unknown): path is string {
|
||||
return typeof path === 'string' && path.startsWith(`${HANDOFF_PATH}?challenge=`);
|
||||
}
|
||||
|
||||
/** The remembered handoff page, once: only a fresh path to the handoff page itself. */
|
||||
export function takeHandoffReturn(): string | null {
|
||||
try {
|
||||
@@ -57,9 +62,9 @@ export function takeHandoffReturn(): string | null {
|
||||
localStorage.removeItem(HANDOFF_RETURN_KEY);
|
||||
if (!raw) return null;
|
||||
const { path, at } = JSON.parse(raw) as { path?: unknown; at?: unknown };
|
||||
if (typeof path !== 'string' || typeof at !== 'number') return null;
|
||||
if (!isHandoffReturn(path) || typeof at !== 'number') return null;
|
||||
if (Date.now() - at > HANDOFF_RETURN_TTL_MS) return null;
|
||||
return path.startsWith(`${HANDOFF_PATH}?challenge=`) ? path : null;
|
||||
return path;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user