Skip to content

Commit 4d09873

Browse files
PiquelChipsclaude
andcommitted
test(sdk): the failed step-up's retry crosses the reload in the stored login
The restore's callback is finished by a new client, as a new page load is, and the docs say what spends a session's retry and for how long. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e6fd82a commit 4d09873

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎docs/architecture/sdk.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ only. Only the pending login crosses a redirect, in `sessionStorage`, and its
213213
callback deletes it. After a reload they authorize again with `prompt=none`; once
214214
that comes back without a session, or a callback finds no login waiting, the page
215215
load does not try again, so a user signed out at auth does not loop. A restore
216-
after a failed step-up keeps the step-up's one retry spent.
216+
after a failed step-up keeps the step-up's one retry spent for the minute after its
217+
return.
217218

218219
Applications choose where sessions live by implementing a small storage backend:
219220
load, an insert that stores only where no record is, a compare-and-swap replace, and

‎packages/auth/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ const notes = await session.fetch('https://notes.example/notes');
177177
`handleCallback` returns `null`, and `restore` does not try again on that page
178178
load, nor after a callback that found no login waiting, so a signed-out user does
179179
not loop. A restore after a step-up that failed keeps that step-up's retry spent,
180-
so a page whose request asked for it does not ask again.
180+
so a page whose request asked for it does not ask again within a minute of that
181+
restore's return.
181182
- `signInWithPasskey` signs in on the page itself, through WebAuthn related
182183
origins, for a trusted client whose origin auth approved (see auth's README,
183184
"Passkey sign-in on an application's own pages"). When it needs auth's pages, it

‎packages/auth/src/browser.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ export class Session {
266266
#tokens: SessionTokens;
267267
/** The refresh under way, which concurrent requests share. */
268268
#refreshing: Promise<void> | undefined;
269-
/** When this session returned from a step-up, until a refused step-up uses it. */
269+
/**
270+
* When this session started with its step-up retry spent: a step-up's return, or a
271+
* restore after a step-up that failed. Refusals within `STEP_UP_RETRY` of it throw.
272+
*/
270273
#steppedUpAt: number | undefined;
271274

272275
private constructor(owner: BrowserClient, tokens: SessionTokens, steppedUp: boolean) {
@@ -275,7 +278,7 @@ export class Session {
275278
this.#steppedUpAt = steppedUp ? this.#clock() : undefined;
276279
}
277280

278-
/** @internal `steppedUp` marks a session returning from a step-up login. */
281+
/** @internal `steppedUp` marks a session whose step-up retry is spent, as `StoredLogin.steppedUp` says. */
279282
static from(owner: BrowserClient, tokens: SessionTokens, steppedUp: boolean): Session {
280283
return new Session(owner, tokens, steppedUp);
281284
}

‎packages/auth/test/browser.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,16 @@ describe('a session', () => {
513513
const { state } = auth.authorization(page.redirectedWith ?? '');
514514
page.callback({ error: 'access_denied', state: state ?? '', iss: ISSUER });
515515
await assert.rejects(client.handleCallback(), { code: 'oauth' });
516-
// The page restores the session the step-up's navigation dropped.
516+
// The page restores the session the step-up's navigation dropped; its callback is
517+
// a new page load, with a new client, so only the stored login carries the retry.
517518
await leaving(client.restore(), page);
518519
page.callback(auth.authorization(page.redirectedWith ?? ''));
519-
const restored = await client.handleCallback();
520+
const reloaded = browserClient(await auth.issuer(), {
521+
clientId: 'notes-web',
522+
redirectUri: REDIRECT_URI,
523+
platform: page.platform
524+
});
525+
const restored = await reloaded.handleCallback();
520526
assert.ok(restored);
521527
const navigations = page.navigations.length;
522528
await Promise.race([

0 commit comments

Comments
 (0)