Open
Conversation
Introduce a `persistence.registration` option on the issuer that allows deferring provider-side persistence (e.g. saving a new password) until the authorization code is exchanged for tokens, instead of committing during the provider success callback. Core changes: - Add `persistence.registration: "immediate" | "lazy"` to IssuerInput - Add `commit` option to provider `success()` callback for passing arbitrary data to be persisted later - Add `finalize()` hook to Provider interface, called at token exchange time when lazy mode is active - Implement `finalize()` in PasswordProvider to defer password storage writes until code exchange - Store provider name and commit payload in authorization code state - Add comprehensive tests for both immediate and lazy registration flows Documentation: - Add lazy-registration.mdx concept page with two Mermaid sequence diagrams illustrating the authorize and token exchange phases - Add custom remark plugin (www/src/plugins/mermaid.ts) for rendering Mermaid diagrams via CDN in Starlight
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue#327
Adds a
persistence.registrationoption to the issuer that lets providers defer user persistence until the authorization code is successfully exchanged for tokens, instead of committing during thesuccess()callback.Problem being solved
In the current flow, the user record is written to storage before token exchange completes. Any failure between those two steps (application bug, network error, crash) leaves an "orphaned record" that blocks future registration attempts until the TTL expires.
Concrete case that motivated this PR: a bug in my application code during the auth flow caused the exchange step to fail. Because the user had already been persisted, fixing the bug and retrying hit email already taken — with no recovery path other than waiting for TTL expiry.
How it works
New issuer option
New provider hook
Providers can implement an optional
finalize()hook called at token exchange time. The provider signals intent by passing acommitpayload throughsuccess():Error handling
If
finalize()throws, the issuer returnsserver_errorwithout consuming the authorization code. The client can retry the exchange with the same code.Files changed
src/issuer.tspersistence.registrationtoIssuerInput; callfinalize()at token exchange; storeprovidername andcommitin code statesrc/provider/provider.tsfinalize()toProviderinterface; addcommit?toProviderOptions.success(); exportProviderFinalizeInputsrc/provider/password.tsfinalize()inPasswordProvider; deferStorage.setfromsuccess()tofinalize()test/issuer.test.tsfinalize()failure, and retry with same codewww/src/content/docs/docs/concepts/lazy-registration.mdxwww/src/plugins/mermaid.tswww/src/content/docs/docs/provider/password.mdxPasswordProvider