Repository navigation
Conversation
`fasthtml.oauth_server`, from nbs/api/08a_oauth_server.ipynb, adds `OAuthServer`. It lets apps such as Claude act as a FastHTML app's signed-in users at a protected route such as `/mcp`, following the MCP authorization spec. It serves the discovery documents, app registration, an Allow page, the token endpoint and revocation. It keeps registered apps, codes and tokens in a store object, and `FastliteStore` is a store on a fastlite database the app passes in. After sign-in, `OAuth` now redirects to a same-site path saved in `session['next']`. The Allow page saves its own path there before sending a signed-out visitor to sign in. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012ywYrYMjp5MDq7g7oV5dmS
With no store, OAuthServer signs client ids, one-time codes and access tokens with the app's `secret_key` and stores nothing. Registration then needs no daily cap. Access tokens last 30 days, there are no refresh tokens or `/oauth/revoke`, and `apps` and `disconnect` raise NotImplementedError. A code can be redeemed again within its 60 seconds, and PKCE still refuses anyone without the verifier. Passing a store turns on grants, one row for each app a user connects. Redeeming a code creates a grant whose id comes from the code, so a second redemption is refused and revokes the grant. Refresh tokens carry the grant's counter, and `advance` rotates them, so a replayed one revokes its grant. The store needs five methods, and `FastliteStore` is one table, down from 11 methods and three tables. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012ywYrYMjp5MDq7g7oV5dmS
The 18 exported cells now carry {"nbdev": {"export": "true"}} instead of a `#| export` line, as the newest cells in 00_core and 01_components do. The exported module is unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012ywYrYMjp5MDq7g7oV5dmS
This branch has not been deployed
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.
DO NOT REVIEW
What this does (written by Claude)
fasthtml.oauth_server, a new module fromnbs/api/08a_oauth_server.ipynb, addsOAuthServer: an OAuth 2.1 authorization server that lets apps such as Claude act as a FastHTML app's signed-in users at a protected route, usually an MCP endpoint at/mcp. It follows the MCP authorization spec. It serves the discovery documents (RFC 9728 and RFC 8414), dynamic registration (RFC 7591, up to 5 https or loopback return addresses), an Allow page that requires PKCE S256, checks a session nonce and sendsX-Frame-Options: DENY, and a token endpoint. The app passescurrent_user(session), and optionally its ownallow_pageand atoken_user(uid, issued_at)hook that can refuse tokens, for example after a sign-out from all devices. Its protected route callssrv.user(req)and returnssrv.unauthorized(req)when that isNone, andsrv.skiplists the paths for the sign-in Beforeware to skip.By default the server stores nothing. It signs client ids, one-time codes and access tokens with the app's
secret_keythrough itsdangerous, with a salt per kind, the way FastHTML signs session cookies. A client id is the signed registration, so registration needs no cap. Access tokens last 30 days. There are no refresh tokens and no/oauth/revoke, andappsanddisconnectraiseNotImplementedError. A code lasts 60 seconds and isn't refused on a second redemption within that time, which RFC 6749 forbids. PKCE still refuses anyone without the verifier. Changingsecret_keycancels every registration and token.Passing a
storeturns on grants, one row for each app a user connects. A store has five methods:add_grant(insert if absent),grant,advance(move the refresh counter fromnton+1),revokeandgrants(uid).FastliteStoreis one fastlite table, and fastlite stays a dev-only dependency because the module never imports it. Redeeming a code creates a grant whose id comes from the code, so a second redemption is refused and revokes the grant. Refresh tokens carry the grant's counter and rotate throughadvance, so a replayed one revokes its grant (RFC 9700 requires rotation for public clients). With a store, access tokens last an hour,userchecks the grant on each request so Disconnect takes effect at once, a new grant replaces the user's older grant to the same app, and/oauth/revokeimplements RFC 7009.OAuthin08_oauthnow redirects to a same-site path saved insession['next']after sign-in, in place ofget_auth's response. The Allow page saves its own path there before sending a signed-out visitor tologin_path.The server is extracted from two copies that had drifted apart: seedlist's
app/oauth.py, which runs the seedlist claude.ai connector, and the one in AnswerDotAI/solve-lp#538. Both used three tables and an 11-method store. The notebook walks a full sign-in with and without a store through Starlette'sTestClient, plus sign-in throughOAuthwith a stub provider, andnbdev-testpasses for the whole repo locally. Nothing has been tried with real claude.ai or Claude Code clients yet. The server has its own notebook because08_oauthisskip_exec, so its examples never run in CI. Unrelated and unchanged:redir_urlinfasthtml/oauth.pyignores itsschemeargument and always recomputes it from the host.🤖 Generated with Claude Code
https://claude.ai/code/session_012ywYrYMjp5MDq7g7oV5dmS