Add Bearer token (JWT) authentication via PAS plugin#88
Draft
xispa wants to merge 3 commits into
Draft
Conversation
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.
Description of the issue/feature this PR addresses
Adds Bearer token (JWT) authentication to SENAITE.JSONAPI via a dedicated PAS plugin, so external clients (CI scripts, dashboards, AI assistants, mobile apps) can authenticate stateless requests without juggling Plone session cookies.
Current behavior before PR
/loginreturns the user info but no token; clients must keep the session cookie alive for every subsequent request.Desired behavior after PR is merged
JWTAuthenticationPluginPAS plugin (registered on top forIExtractionPlugin+IAuthenticationPlugin) installed via asenaite.jsonapi:defaultGenericSetup profile.Authorization: Bearer <token>headertokencookie (HttpOnly)X-JWT-Auth-TokenheaderOOBTreeannotation on the portal.rotate_secret(userid)invalidates every token issued for that user — the revocation primitive that was missing./loginnow accepts either HTTP Basic or__ac_name/__ac_passwordform fields and returns{token, expires, ...user info}. The token is also set as an HttpOnly cookie so cookie-based clients keep working transparently./logoutexpires the cookie on the client; full server-side invalidation is done withrotate_secret.pyjwt<2.0.0pinned (Python 2.7 compatibility).Tests
Two new doctests under
src/senaite/jsonapi/tests/doctests/:bearer.rst— covers extraction, valid/invalid/forged/expired tokens and secret rotation against the PAS plugin directly.login.rst— exercises the full/login→/auth→/users/currentflow with Bearer tokens, plus rejection of invalid/expired/revoked tokens.Run with:
I confirm I have tested the PR thoroughly and coded it according to PEP8 standards.