Skip to content

Validate API version families and pin SDK auth flow rules - #158

Merged
sergioteula merged 1 commit into
masterfrom
claude/amazon-api-version-compatibility-agyrln
Sep 4, 2026
Merged

Validate API version families and pin SDK auth flow rules#158
sergioteula merged 1 commit into
masterfrom
claude/amazon-api-version-compatibility-agyrln

Conversation

@sergioteula

Copy link
Copy Markdown
Owner

Summary

This PR strengthens version validation by distinguishing between unsupported versions within known families (2.x, 3.x) and versions from completely unknown families (4.x+). It also centralizes auth flow logic to ensure the library and bundled SDK stay in sync.

Key Changes

  • Version family validation: The library now rejects versions from unknown families (e.g., 4.x) even when a custom auth_endpoint is provided, since the auth flow (scope, encoding, headers) for that family is unknown. Only versions from known families (2.x, 3.x) can be used with a custom endpoint.

  • Centralized auth flow logic:

    • Introduced get_flow() function to determine the auth flow (Cognito or LWA) based on version family
    • Introduced build_authorization_header() function to construct the version-appropriate Authorization header in one place
    • Updated is_lwa() and get_scope() to use the new get_flow() function
    • Updated AsyncAmazonCreatorsApi._build_authorization_header() to use the new centralized function
  • SDK parity tests: Added comprehensive test suite (sdk_parity_test.py) that validates the library's version rules match those in the bundled SDK:

    • Verifies the SDK knows exactly the same versions as the library
    • Confirms endpoints match for all versions
    • Validates auth flow (LWA vs Cognito) matches
    • Ensures Authorization headers are identical
  • Improved error messages: Version validation errors now clearly distinguish between:

    • Versions out of the supported list but within a known family (suggest using auth_endpoint)
    • Versions from unknown families (explain that library support is needed, not just a custom endpoint)
  • Documentation updates: Updated docstrings and README to clarify that custom endpoints only work for known version families.

Implementation Details

  • The FAMILY_FLOWS dictionary maps major version numbers to their auth flows, making it easy to validate new versions belong to a known family
  • The SDK parity tests probe candidate versions (1.0-5.9) to detect when the bundled SDK is bumped with new version support, ensuring the library's rules are updated accordingly
  • All existing tests updated to use realistic version numbers (3.4 instead of 4.0) for testing custom endpoints

https://claude.ai/code/session_01GvgJW17WQYEJgPRXye826b

A custom auth_endpoint used to make any version valid, so a version of a
family out of the known ones was sent with the Cognito flow: form encoded
body, its scope and the version in the Authorization header. Amazon rejects
that without explaining why, which is worse than not accepting the version.

The flow of a version is now taken from a map of families, which also
decides the endpoint validation, and a version of a family that is not in
it is rejected even with a custom endpoint. A new version of a known family
keeps working with an endpoint, as it only changes where the token is asked
for, and the error of an unsupported version says so.

Both clients also build the Authorization header with the same helper, and
the version rules bundled in the SDK, which the library never uses because
it resolves the endpoint and the flow on its own, are pinned by tests so a
bump of the SDK cannot leave both halves disagreeing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GvgJW17WQYEJgPRXye826b
@sergioteula
sergioteula merged commit 945e2e9 into master Sep 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant