Identity
CurrentUser
CurrentUser is a frozen dataclass with this constructor:
CurrentUser(subject: str, username: Optional[str], claims: Mapping[str, Any])
| Field | Value |
|---|---|
subject | Non-empty sub claim |
username | Non-empty cognito:username, otherwise non-empty username, otherwise None |
claims | Read-only MappingProxyType copy returned by current_user |
CurrentUserError
CurrentUserError(ValueError) is raised by current_user when
the event does not contain a supported, structurally valid identity.
current_user
Signature: current_user(event: Mapping[str, Any]) -> CurrentUser
Example:
from lambda_api_decorators import current_user
def handler(event, context):
user = current_user(event)
return {"statusCode": 200, "body": user.subject}
Extract claims from an already-authorized API Gateway event. REST-style events
use event["requestContext"]["authorizer"]["claims"]; HTTP API JWT events use
event["requestContext"]["authorizer"]["jwt"]["claims"]. The event,
requestContext, authorizer, JWT object (when present), and claims must be
mappings. Claims must contain a non-empty string sub, otherwise
CurrentUserError is raised.
The helper does not authenticate tokens, validate them, or authorize an action. It returns a copy of claims exposed through a read-only mapping.