Skip to content

Add bearer token auth and a default token identity chain - #982

Open
Alan4506 wants to merge 13 commits into
developfrom
token-identity
Open

Alan4506 wants to merge 13 commits into
developfrom
token-identity

Conversation

@Alan4506

@Alan4506 Alan4506 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Generated clients can now authenticate with a bearer token. For a service that models smithy.api#httpBearerAuth:

  • the generated config includes token and token_identity_resolver;
  • when bearer auth is the auth scheme selected for an operation, the request carries an Authorization: Bearer <token> header;
  • an AWS client configured with neither token nor token_identity_resolver resolves the token through a default identity chain (the SSO token provider that joins the chain will be added in aws-sdk-python repo).

Auth scheme selection is unchanged: a service that lists SigV4 before bearer auth keeps signing with SigV4 unless an auth_scheme_resolver selects bearer auth. Both code generators (the Java codegen under codegen/ and the Python client generator in packages/smithy-python) emit the same config fields, scheme and _post_setup wiring.

Changes by package

  • smithy-core: adds HTTPBearerAuthTrait, the runtime representation of smithy.api#httpBearerAuth, alongside existingHTTPAPIKeyAuthTrait.
  • smithy-http: adds TokenIdentity, StaticTokenResolver/AsyncStaticTokenResolver, BearerAuthScheme/AsyncBearerAuthScheme, and BearerSigner, next to the API key equivalents.
  • smithy-aws-core: changes the identity chain so it can serve TokenIdentity as well as credentials. Changes AwsConfig to treat token / api_key as secrets like the access key fields, and adds _SHARED_FIELDS so deep copies share identity resolvers. Adds SSO feature IDs r and s; the legacy IDs (t, u) are not added because new SDKs should not support legacy SSO profiles (no sso_session) as per the spec, as in the Ruby v4 SDK.
  • smithy-test: changes the HTTP mock to also replace token / token_identity_resolver with static fakes on AWS configs that have them, so a mocked AWS bearer client never builds the real chain.
  • codegen/core: adds an HttpBearerAuth integration that registers the scheme and the two config properties for services with @httpBearerAuth; non-AWS clients default to a static resolver (same shape as API key auth).
  • codegen/aws/core: changes AwsIdentityIntegration so _post_setup wires token_identity_resolver the way it already wires aws_credentials_identity_resolver (see table), and so generated configs extend _SHARED_FIELDS. The integration applies only to AWS services (aws.api#service) with SigV4 or bearer auth; a non-AWS service with @httpBearerAuth keeps the core generator's static resolver, since the chains read an AWS config's profile and region.
  • smithy-python (Python client generator): mirrors the Java codegen: @httpBearerAuth registers the scheme and the two config properties, and an AwsIdentityIntegration (replacing the SigV4-only one) emits the same _post_setup wiring and _SHARED_FIELDS for AWS services. Regenerates the committed codegen-output-py snapshots, with @httpBearerAuth added to the features-client model, and documents the integration in designs/codegen/client.md.
Config on an AWS @httpBearerAuth client token_identity_resolver after setup
token_identity_resolver=... used as given
token="..." StaticTokenResolver
neither default token identity chain

Testing

Adds unit tests for the new trait, identity, resolvers, scheme, signer and chain changes; smithy-test functional tests for the mock (sync and async); and Java and Python codegen tests for the generated bearer config and _post_setup wiring. Ran make test-unit, make build-java, make test-integration and make static-analysis; CI also passes.

Also generated the bedrock (SigV4 + bearer) and sqs (SigV4 only) clients with both generators and ran them against the live services, sync and async. SigV4 works as before with env credentials, static keys and a shared-config profile. On bedrock, token= or an explicit token_identity_resolver sends Authorization: Bearer and succeeds with a short-term Bedrock API key; with neither set, the client builds the token chain, which fails until a token provider is installed and succeeds once one is. The sqs config has no bearer fields.

Adds changelog fragments for smithy-core, smithy-http, smithy-aws-core, smithy-test and smithy-python, and a codegen entry under ## Unreleased in CHANGELOG.md.

Follow-ups (separate PRs)

  • aws-sdk-python: regenerate the clients against the smithy-python release that carries this change, so bedrock / bedrock-runtime pick up the bearer config, scheme and _post_setup wiring.
  • aws-sdk-python: add the SSO token provider (aws-credentials-sso) that joins the token identity chain.
  • smithy-python: add auth_scheme_preference (env AWS_AUTH_SCHEME_PREFERENCE / profile auth_scheme_preference) to the AWS config and the generated auth scheme resolver, so a user can put bearer auth ahead of SigV4 without writing an auth_scheme_resolver.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Alan4506
Alan4506 marked this pull request as ready for review November 24, 2026 01:25
@Alan4506
Alan4506 requested a review from a team as a code owner November 24, 2026 01:25
kuhe
kuhe previously approved these changes Nov 24, 2026
# Conflicts:
#	scripts/api-snapshot/mirrors.txt
#	scripts/verifications/import-cost.json

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to see what gets generated when we add new features. Can you see if you can add httpBearerAuth to the features-client model and then regenerate it? The pagination work recently updated it to show what gets generated in #979.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done in 76e6e93: added @httpBearerAuth to the features-client model. Since codegen-output-py comes from the Python client generator, this PR now also adds bearer auth there (the token / token_identity_resolver config fields, the scheme, and the same _post_setup token chain the Java codegen emits), so the snapshot shows the real output.

return
This step registers no resolvers; it only makes the shared config and the
active profile name available to the profile-based providers that follow it,
whatever identity type the chain resolves (for example ``TokenIdentity``

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: last two lines repeat the same info that this works for all identity types from the main line. lets trim it down.

CREDENTIALS_STS_ASSUME_ROLE_WEB_ID = "k"
CREDENTIALS_PROFILE = "n"
CREDENTIALS_PROFILE_STS_WEB_ID_TOKEN = "q" # noqa: S105
CREDENTIALS_PROFILE_SSO = "r"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add BEARER_SERVICE_ENV_VARS? Or is that a separate feature?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a separate feature. BEARER_SERVICE_ENV_VARS is emitted when the token comes from the AWS_BEARER_TOKEN_BEDROCK environment variable, which is out of scope for this PR.

stobrien89
stobrien89 previously approved these changes Nov 24, 2026
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.

4 participants