Skip to content

feat(auth): add custom headers support for Cognito Auth requests#14756

Open
piotrekwitkowski wants to merge 4 commits intoaws-amplify:mainfrom
piotrekwitkowski:feat/auth-custom-headers
Open

feat(auth): add custom headers support for Cognito Auth requests#14756
piotrekwitkowski wants to merge 4 commits intoaws-amplify:mainfrom
piotrekwitkowski:feat/auth-custom-headers

Conversation

@piotrekwitkowski
Copy link

Summary

  • Adds optional headers async function to LibraryAuthOptions, enabling custom headers on all Auth requests to Cognito
  • Follows the existing pattern used by REST (libraryOptions.API.REST.headers) and GraphQL (libraryOptions.API.GraphQL.headers)
  • Enables integration with AWS WAF intelligent threat protection (CAPTCHA, Challenge, Bot Control) and other custom header use cases

Usage

Amplify.configure(resourcesConfig, {
  Auth: {
    headers: async () => ({
      'x-aws-waf-token': await window.AwsWafIntegration.getToken(),
    }),
  },
});

Changes

  • packages/core/src/singleton/Auth/types.ts — Added headers to LibraryAuthOptions
  • packages/auth/.../cognitoUserPoolTransferHandler.ts — Read and apply custom headers from Amplify.libraryOptions.Auth.headers in the existing middleware
  • packages/auth/.../__tests__/.../cognitoUserPoolTransferHandler.test.ts — Added tests for custom headers

Closes #12308
Closes #13197

Test plan

  • Existing tests pass (96/101 suites, 5 pre-existing failures unrelated to this change)
  • New test: custom headers are attached when headers function is configured
  • New test: no-op when headers is not configured
  • Verified no regressions across 1118 passing tests

🤖 Generated with Claude Code

piotrekwitkowski and others added 2 commits March 22, 2026 21:48
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add optional `headers` function to `LibraryAuthOptions` that allows
attaching custom headers to all Auth requests to Cognito, consistent
with the existing REST and GraphQL custom headers pattern.

Closes aws-amplify#12308
Closes aws-amplify#13197

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Mar 22, 2026

🦋 Changeset detected

Latest commit: 821ec0a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@aws-amplify/auth Minor
@aws-amplify/core Patch
@aws-amplify/pubsub Patch
aws-amplify Patch
@aws-amplify/api-graphql Patch
@aws-amplify/api Patch
@aws-amplify/datastore Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@piotrekwitkowski piotrekwitkowski requested a review from a team as a code owner March 22, 2026 22:25
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@piotrekwitkowski piotrekwitkowski force-pushed the feat/auth-custom-headers branch from 80810e5 to 85d377a Compare March 22, 2026 22:26
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.

[v6] Intercept authentication Cognito requests with custom headers Amplify JS to create 'aws-waf-token' header and send with Auth requests

1 participant