Skip to content

Conversation

soberm
Copy link
Contributor

@soberm soberm commented Sep 17, 2025

Description of changes

Adds support for dynamically providing client metadata for Cognito token refresh operations through a ClientMetadataProvider function type. More specifically:

• Added ClientMetadataProvider function type to @aws-amplify/core types
• Added setClientMetadataProvider() method to CognitoUserPoolsTokenProvider
• Integrated ClientMetadataProvider into TokenOrchestrator for token refresh operations
• Added async client metadata provider support to token refresh flow
• Updated tests for new functionality

Usage

// Set global clientMetadata (affects all token refreshes)
import { cognitoUserPoolsTokenProvider } from 'aws-amplify/auth/cognito';

const clientMetadataProvider = () => Promise.resolve({
  'app-version': '1.0.0',
  'device-type': 'mobile'
});

cognitoUserPoolsTokenProvider.setClientMetadataProvider(clientMetadataProvider);

// Per-call clientMetadata (overrides global)
import { fetchAuthSession } from 'aws-amplify/auth';

const session = await fetchAuthSession({
  forceRefresh: true,
  clientMetadata: { 
    'context': 'user-action',
    'operation': 'manual-refresh'
  }
});

// Existing usage remains unchanged (backward compatible)
const session = await fetchAuthSession({ forceRefresh: true });

Issue #, if available

#13379

Description of how you validated changes

• Added unit tests for setClientMetadataProvider functionality

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

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