Conversation
Add JWT verification, coordinated JWKS caching, API Gateway authorization, and OAuth client credentials with optional dependencies, documentation, examples, and tests. Include exception-safe claims cleanup, sanitized provider errors, and lazy imports for OAuth-only clients and static-key verification.
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
| if not isinstance(token, str) or not token: | ||
| raise InvalidTokenError() | ||
| try: | ||
| header = jwt.get_unverified_header(token) |
| try: | ||
| # This payload selects a configured verifier. No unverified claim | ||
| # is returned to callers or used to discover another provider. | ||
| payload = jwt.decode(token, options={"verify_signature": False}) |
|
I reviewed the two SonarCloud findings in
I reran the verifier and profile tests: 63 passed, including rejection of tampered signatures, tokens signed with another issuer’s key, and unknown issuers. Could you review these as potential false positives in SonarCloud? The issuer-routing code already documents this behavior; I can add a similar explanation beside the header parsing. |




Add JWT verification, coordinated JWKS caching, API Gateway authorization, and OAuth client credentials with optional dependencies, documentation, examples, and tests.
Include exception-safe claims cleanup, sanitized provider errors, and lazy imports for OAuth-only clients and static-key verification.
Issue number: closes #8466
Summary
Changes
client_secret_basic, per-resource token caches, callable secrets, coordinated acquisition, bounded retries, and authenticated HTTPS requests.User experience
Applications configure the issuer, resource audience, and permitted algorithms, then use
verify()directly, attachrequire()to a route, or returnauthorize()from a Lambda authorizer. Outbound clients useauth_headers()with their own HTTP client or callrequest()for a separate downstream resource.Validation
Functional tests use real asymmetric signatures and in-memory HTTP endpoints, without external services. They cover expiration and key removal, failed refresh, concurrent acquisition, async thread offloading during initial fetch/expiry/rotation, Cognito token purpose and resource binding, authorizer event fixtures, scope precedence, secret rotation, retry limits, and error redaction.
Regression tests exercise an unhandled protected handler followed by public, denied, and authenticated invocations, verifying that claims never survive the failed request. Error tests inspect
__context__,__cause__, rendered tracebacks, and Powertools Logger output for public verification, prefetch, authorizer, and OAuth operations, including failing secret loaders invoked inside an existing exception handler.Fresh-process tests block JWT/cryptography imports while constructing an OAuth client, and block urllib3 while verifying valid and invalid signatures against static JWKS. They also check that remote-cache construction loads the transport and that public exports retain introspection, unknown-attribute errors, and star-import behavior. Four of these checks failed before the optimization; all five pass afterward.
HTTPS integration tests run the production urllib3 transport against a loopback TLS server with a generated test certificate. They verify discovery/JWKS retrieval, signed-token verification, token exchange and downstream authentication, untrusted-certificate rejection before credentials are sent, response-size limits, stalled and slowly arriving bodies, separate downstream timeouts, and redirect/retry behavior.
Additional deployment checks used the SAM example with temporary AWS-hosted HTTPS fixtures. They exercised REST and HTTP Gateway decisions, middleware challenges, disabled authorizer caching, OAuth acquisition/concurrency/downstream requests, exception cleanup, and remote key rotation/removal/outages on both architectures. A real HTTP API
$defaultroute supplied a concrete method/path ARN, which the existing IAM helper successfully authorized. All three test stacks were deleted, with resource cleanup independently verified. These checks ran through a standalone harness; they do not represent the entire repository's AWS end-to-end suite or live Cognito/Keycloak interoperability testing.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.