Repository navigation
Support a dedicated backend (BFF) - #118
brionmario wants to merge 1 commit into
Conversation
Setting endpoints.backend hands sign-in to the app's backend (the Backend for Frontend pattern). The browser client then signs in, reads the user, and signs out through the backend, and sends API calls through its proxy with the session cookie, so the browser never holds a token. React and Vue pick it up through the browser client. The client reports loading until the first session read settles, so route guards do not start a sign-in before it is known whether the user is signed in. A session that ends elsewhere fires the sign-out hook, found by a 401 login_required from the proxy, a check when the page regains focus, or polling /checksession when syncSession is on. Signed-off-by: Brion <info@brionmario.com>
🔀 Cross-SDK feature parityDoes this change need to ship in the other ThunderID SDKs too? This check stays red until one of these labels answers that:
Ports (DO NOT EDIT)
No sibling SDKs accounted for on this thread yet. Important Reply to this comment with this block, filled in. The boxes above tick A link can be a pull request or a tracked issue, written in full or as The contract is in the SDK development specification. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Purpose
Browser apps built on
@thunderid/browser,@thunderid/reactand@thunderid/vuekeep their tokens in browser storage, where any script that runs on the page can read them. This adds an opt-in mode where sign-in runs on the app's own backend (the Backend for Frontend pattern from RFC 10017). The backend keeps the tokens behind anHttpOnlycookie, and the SDK never holds one.Setting
endpoints.backendturns it on. Unset paths default under/api/auth:Apps that do not set it keep working exactly as today.
Approach
endpoints.backendtakessignIn,session,checkSession,refresh,signOutandproxy.resolveBackendEndpointsfills in the defaults. The key stays out of the OIDC discovery metadata.BackendClienttalks to the backend.BackendHttpClientis registered as the instance's HTTP client, so every existinghttp.requestcall and the provider's/users/mefetch go through the backend's proxy with the session cookie and anX-Requested-Withheader, and never with a token. A request to a URL outside the API base is refused rather than sent without credentials.signIn,signOut,isSignedIn,getUserandgetDecodedIdTokengo through the backend.getAccessToken,getIdToken,exchangeTokenandrevokeAccessTokenreject with a clear error, because the browser holds no token.initializeand reports loading until that read settles. Without this, route guards saw "not loading, not signed in" and started a sign-in, which the SSO session completed straight away, in a loop.401 session_expired. Any other401is the API's own answer and is returned as is.sign-outhook when the proxy answers401 login_required, when a check on page focus finds the session gone, or when pollingcheckSessiondoes. Polling uses the existingsyncSessionandcheckSessionIntervalkeys. The React and Vue providers now listen to the hook and clear the user, so a route guard sends the user to sign in. A sign-out the app starts itself does not fire it.The backend contract, and the server implementation the ThunderID Console uses, are in the linked product PR.
Related Issues
Related PRs
Checklist
breaking changelabel added.parity/prs-raisedorparity/prs-not-neededadded.parity/prs-raised, the port links are posted as a reply on the parity check's comment.Security checks