fix(native-auth): send the app's SSO sign-in through the identity provider every time

The app signs in through a browser sheet that shares the system browser's
cookies. When that browser still held a TREK session from an earlier
sign-in, the hand-off page skipped the identity provider and offered to
continue at once, so a provider set to demand re-authentication (Pocket ID's
"requires re-authentication") was never asked, and signing out of the app
and in again with SSO asked for nothing.

The SSO button now always goes through the identity provider. It decides as
before: a provider with a running session lets the user through, one that
demands re-authentication asks for it. A sign-in with a password or passkey
still continues with the browser's session after the explicit tap.

Refs #3014
This commit is contained in:
Maurice
2026-11-25 10:52:34 +01:00
parent d9d901e52d
commit 434baaf6fd
2 changed files with 20 additions and 5 deletions
@@ -1,4 +1,4 @@
// FE-NATIVE-HANDOFF-001 to FE-NATIVE-HANDOFF-011
// FE-NATIVE-HANDOFF-001 to FE-NATIVE-HANDOFF-012
import React from 'react';
import { MemoryRouter } from 'react-router';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -93,6 +93,16 @@ describe('useNativeHandoff', () => {
expect(rememberHandoffReturn).toHaveBeenCalledWith(`/native-handoff?challenge=${challenge}`);
});
it('FE-NATIVE-HANDOFF-012: goes through the identity provider for SSO even when this browser is still signed in', () => {
// A session left from an earlier sign-in skipped the provider, and with it the
// re-authentication it demands (#3014).
setSearch(`?challenge=${challenge}&start=oidc`);
const { result } = renderHandoff();
expect(window.location.replace).toHaveBeenCalledWith('/api/auth/oidc/login?remember=1');
expect(result.current.ready).toBe(false);
expect(mockNavigate).not.toHaveBeenCalled();
});
it('FE-NATIVE-HANDOFF-005: waits while the session is still being checked', () => {
useAuthStore.setState({ isAuthenticated: false, isLoading: true });
const { result } = renderHandoff();
@@ -35,17 +35,22 @@ export function useNativeHandoff() {
// Back here once signed in, without `start`, so an SSO round trip cannot loop.
const returnPath = `${HANDOFF_PATH}?challenge=${challenge}`;
// The app's SSO button always goes through the identity provider, even when this
// browser still holds a TREK session from an earlier sign-in. That session would
// otherwise skip the provider, and with it a re-authentication it demands.
const startOidc = valid && params.get('start') === 'oidc';
useEffect(() => {
if (!valid || isLoading || isAuthenticated || passkeyStep) return;
if (params.get('start') === 'oidc') {
if (!valid || isLoading || passkeyStep) return;
if (startOidc) {
sessionStorage.setItem('oidc_redirect', returnPath);
rememberHandoffReturn(returnPath);
window.location.replace('/api/auth/oidc/login?remember=1');
return;
}
if (isAuthenticated) return;
void navigate(`/login?redirect=${encodeURIComponent(returnPath)}`, { replace: true });
}, [valid, isLoading, isAuthenticated, passkeyStep, params, returnPath, navigate]);
}, [valid, isLoading, isAuthenticated, passkeyStep, startOidc, returnPath, navigate]);
const openApp = async (): Promise<void> => {
setStatus('sending');
@@ -90,7 +95,7 @@ export function useNativeHandoff() {
passkeyStep: valid && !isLoading && !isAuthenticated && passkeyStep,
continueWithPasskey,
otherSignIn,
ready: valid && !isLoading && isAuthenticated,
ready: valid && !isLoading && isAuthenticated && !startOidc,
userName,
status,
openApp,