feat(security): persistent OAuth2 token store — Redis + Postgres (v26.06.69)#96
Merged
Conversation
…gres) + bump v26.06.69 The authz server's TokenStore was InMemoryTokenStore only -> refresh tokens lost on restart + no cross-instance revocation (multi-instance production blocker, per the ports/adapters audit). Now pluggable via pyfly.security.oauth2.token-store.provider=memory|redis|postgres: - RedisTokenStore (security/adapters/redis_token_store.py): JSON + EX ttl (refresh-token lifetime). - PostgresTokenStore (security/adapters/postgres_token_store.py): durable table, lazy idempotent create, table-name validated. Lazy injected AsyncEngine. Hexagonal: drivers obtained in the composition root + injected; no module-scope driver imports. Tests: tests/security/test_persistent_token_store.py (unit, fake clients) + tests/integration/ test_token_store_integration.py (real Redis + real Postgres). Gates: mypy --strict (636), ruff + format, full suite 3938 passed.
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.
Fixes the audit's multi-instance production blocker: the OAuth2 authorization server's
TokenStorewas in-memory only (refresh tokens lost on restart; no cross-instance revocation). Now pluggable viapyfly.security.oauth2.token-store.provider:RedisTokenStore(redis) — JSON values with TTL = refresh-token lifetime (self-evicting); fast distributed revocation.PostgresTokenStore(postgres) — durable/auditable rows; lazy idempotent table create; table name validated against injection.memory(default) unchanged.Hexagonal: Redis client / SQLAlchemy engine obtained in the composition root + injected; adapters import no driver at module scope. Validated against real Redis + real Postgres (testcontainers: store/find/upsert/revoke). Unit + integration tests. Gates: mypy --strict (636), ruff+format, full suite 3938.