Skip to content

Commit 1f7682d

Browse files
docs(auth): complete public API docstrings
1 parent 596f15b commit 1f7682d

3 files changed

Lines changed: 85 additions & 0 deletions

File tree

‎aws_lambda_powertools/utilities/auth_alpha/jwt/_internal/base.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ def verify_authorization_header(self, value: str | None) -> dict[str, Any]:
3030
3131
The scheme is case-insensitive. Missing headers, malformed values, and
3232
schemes other than Bearer raise ``InvalidTokenError``.
33+
34+
Parameters
35+
----------
36+
value : str | None
37+
Raw HTTP Authorization header value.
38+
39+
Returns
40+
-------
41+
dict[str, Any]
42+
Claims after token verification.
43+
44+
Raises
45+
------
46+
InvalidTokenError
47+
Header or token is missing, malformed, or invalid.
48+
JWKSFetchError
49+
Current trusted signing keys could not be obtained.
50+
51+
Examples
52+
--------
53+
```python
54+
authorization = event.get("headers", {}).get("authorization")
55+
claims = verifier.verify_authorization_header(authorization)
56+
```
3357
"""
3458
from aws_lambda_powertools.utilities.auth_alpha.jwt._internal.authorization import bearer_token
3559

‎aws_lambda_powertools/utilities/auth_alpha/jwt/integrations/api_gateway.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@ def authorize_event(
3232
context_claims: list[str] | None,
3333
on_error: Callable[[AuthError], None] | None,
3434
) -> dict[str, Any]:
35+
"""Build an API Gateway authorizer response after verifying its bearer token.
36+
37+
Parameters
38+
----------
39+
verifier : Verifier
40+
Verifier used for the request token.
41+
event : dict[str, Any] | DictWrapper
42+
API Gateway TOKEN or REQUEST authorizer event.
43+
scopes : list[str] | None
44+
Scopes required for an Allow response.
45+
response_format : Literal["iam", "simple"]
46+
IAM policy or HTTP API 2.0 simple response.
47+
context_claims : list[str] | None
48+
Verified scalar claims copied into authorizer context.
49+
on_error : Callable | None
50+
Callback notified with a sanitized authentication error.
51+
52+
Returns
53+
-------
54+
dict[str, Any]
55+
Deny/Allow IAM policy or simple authorization response.
56+
57+
Raises
58+
------
59+
ValueError
60+
Event or response configuration is invalid.
61+
JWKSFetchError
62+
Current trusted signing keys could not be obtained.
63+
"""
64+
3565
raw = event.raw_event if isinstance(event, DictWrapper) else event
3666
_validate_event(raw, response_format)
3767
arn = _request_arn(raw) if response_format == "iam" else None

‎aws_lambda_powertools/utilities/auth_alpha/jwt/integrations/event_handler.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ class AuthErrorContext:
3434

3535

3636
class AuthMiddleware(BaseMiddlewareHandler[ApiGatewayResolver]):
37+
"""Event Handler middleware that verifies JWTs before invoking a route.
38+
39+
Create this middleware with ``Verifier.require()``.
40+
41+
Parameters
42+
----------
43+
verifier : Verifier
44+
Verifier used for incoming bearer tokens.
45+
scopes : list[str] | None
46+
Scopes required by the protected route.
47+
authorize : Callable | None
48+
Additional policy receiving verified claims.
49+
on_error : Callable | None
50+
Callback that maps a safe error context to an Event Handler response.
51+
"""
52+
3753
def __init__(
3854
self,
3955
verifier: Verifier,
@@ -47,6 +63,21 @@ def __init__(
4763
self._on_error = on_error
4864

4965
def handler(self, app: ApiGatewayResolver, next_middleware: NextMiddleware) -> Response:
66+
"""Verify the request and expose claims while downstream code executes.
67+
68+
Parameters
69+
----------
70+
app : ApiGatewayResolver
71+
Resolver handling the current request.
72+
next_middleware : NextMiddleware
73+
Next middleware or route handler in the chain.
74+
75+
Returns
76+
-------
77+
Response
78+
Downstream response or an authentication failure response.
79+
"""
80+
5081
try:
5182
raw = app.current_event.raw_event
5283
token = header_token(raw.get("headers"), raw.get("multiValueHeaders"))

0 commit comments

Comments
 (0)