Repository navigation
feat: JWT authentication with PyJWT and Ory Hydra - #5
Merged
Merged
Conversation
…n unhandled exception test
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
/usersroutes, validated against Ory Hydra (local/test environment) using PyJWT.app/api/dependencies/auth.py:get_current_user: verifies the access token (RS256) against Hydra's JWKS endpoint, checks theissclaim, returns 401 (problem+json,WWW-Authenticate: Bearer) on missing/invalid/expired token.require_scopes(*scopes): factory returning a dependency that checks the token'sscp/scopeclaim and returns 403 when scopes are insufficient.users:readfor GET routes,users:writefor POST/PUT/DELETE./healthand/user_eventsremain public.AuthenticationSettings(issuer, jwks_url) wired intoconfig.yamlandtests/config.yaml.compose.yml: addhydra+hydra-migrateservices (Ory Hydra v2.2.0, ports 4444/4445).pyproject.toml: addpyjwt[crypto]>=2.10.1.Tests
tests/api/users/test_authentication.py: for each of the 5/usersroutes — 401 (no token, malformed token, expired token), 403 (read-only token on write route and vice versa), plus a 201 happy path with a valid token.conftest.py:rsa_private_key,make_token(RS256 tokens with Hydra-like claims) andauth_headersfixtures; JWKS client is mocked, tests never call Hydra./userstests updated to send validAuthorizationheaders.uv.lockmust be regenerated locally (uv lock) and pushed, since CI and the Dockerfile useuv sync --lockedandpyjwtis a new dependency.