docs(api): document the current authentication flow, comment non-obvi… - #393
Merged
Conversation
…ous auth code Add a new diagram covering the authentication mechanism: a session-based /SASLogon/login + /SASLogon/authorize handshake that mints a short-lived auth code, exchanged at /SASjsApi/auth/token for a revocable JWT pair, with optional LDAP-backed credential verification. Add WHY comments (not present before) at the handful of spots in the auth code whose behaviour isn't obvious from reading them in isolation: why /auth/token can return an existing token pair instead of rotating it, why the auth-code exchange never checks a client's clientSecret, how verifyTokenInDB turns self-verifying JWTs into revocable ones, why two /SASjsApi/user routes stay reachable in desktop mode, why the static authorized-route list exists on top of plain authentication, and why /SASjsApi/client's real protection lives at its router mount point in routes/api/index.ts rather than in client.ts itself.
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.
Issue
The authentication flow (session login, auth-code exchange, JWT issuance/refresh/revocation, LDAP, desktop mode, permission checks) had no diagram, and several non-obvious behaviours in the auth code were undocumented - e.g. why a client's
clientSecretisn't checked during token exchange, how token revocation actually works despite using JWTs, and where/SASjsApi/client's access control is actually enforced.Intent
Make the authentication flow easy to understand from the docs alone, and leave WHY comments at the specific spots in the code where the behaviour would otherwise be surprising or easy to misread in isolation.
Implementation
docs/diagrams/authentication-flow.md: a sequence diagram plus description covering the full flow -GET /(CSRF token) →POST /SASLogon/login(password or LDAP bind, establishes a session) →POST /SASLogon/authorize(session + clientId → short-lived auth code) →POST /SASjsApi/auth/token(code → access/refresh JWT pair) → authenticatedSASjsApirequests → refresh → logout. Also documents the two-credential model (session cookie vs bearer JWT), the public-route fallback, desktop-mode bypass, and theauthorizemiddleware's permission-lookup order./auth/tokencan return an existing token pair instead of always rotating it (controllers/auth.ts)clientSecret(controllers/auth.ts)verifyTokenInDBturns self-verifying JWTs into revocable ones (utils/verifyTokenInDB.ts)/SASjsApi/userroutes stay reachable in desktop mode (middlewares/desktop.ts)utils/getAuthorizedRoutes.ts)publicUseron public routes (middlewares/authenticateToken.ts)/SASjsApi/client's actual access control comes from its router mount point inroutes/api/index.ts, not from anything inclient.tsitself (routes/api/client.ts)Checks
npm run lint:fix).npm test).