Skip to content

GetTokensFromRefreshToken Requires AWS Credentials in Browser Environment #7030

@xspirus

Description

@xspirus

Checkboxes for prior research

Describe the bug

When using the GetTokensFromRefreshToken operation from the @aws-sdk/client-cognito-identity-provider package in a browser environment, the SDK requires AWS credentials to be set. This is unexpected, as the operation is intended to be used with a refresh token and client ID, without necessitating AWS credentials.

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Browser

Details of the browser/Node.js/ReactNative version

[email protected]

Reproduction Steps

This is the code that I am using

import {
  CognitoIdentityProviderClient,
  GetTokensFromRefreshTokenCommand,
} from "@aws-sdk/client-cognito-identity-provider";

const client = new CognitoIdentityProviderClient({
  region: "eu-north-1",
});

export const refreshTokens = async (refreshToken) => {
  const command = new GetTokensFromRefreshTokenCommand({
    ClientId: "your-client-id",
    RefreshToken: refreshToken,
  });

  try {
    const response = await client.send(command);
    return response.AuthenticationResult;
  } catch (error) {
    console.error("Error refreshing tokens:", error);
    throw error;
  }
};

Observed Behavior

Error: Credential is missing
credentialDefaultProvider runtimeConfig.browser.js:22
fn resolveAwsSdkSigV4Config.js:127
httpAuthSchemeMiddleware httpAuthSchemeMiddleware.js:31
loggerMiddleware loggerMiddleware.js:3
send client.js:35
refreshTokens chisels.ts:146
initializeAuth slice.ts:86
Redux 3
createImmutableStateInvariantMiddleware Immutable
createActionCreatorInvariantMiddleware Redux
dispatch :6
App app.tsx:36
React 7
workLoop scheduler.development.js:266
flushWork scheduler.development.js:239
performWorkUntilDeadline scheduler.development.js:533
js scheduler.development.js:571
js scheduler.development.js:633
__require chunk-DC5AMYBS.js:9
js index.js:6
__require chunk-DC5AMYBS.js:9
React 2
__require chunk-DC5AMYBS.js:9
js React
__require chunk-DC5AMYBS.js:9
js React
__require chunk-DC5AMYBS.js:9
react-dom_client.js:38
:1:145535

Expected Behavior

The GetTokensFromRefreshToken operation should not require AWS credentials when used in the browser, as it operates with a refresh token and client ID. Requiring AWS credentials in this context is inconsistent with the intended use of the operation.

The AWS documentation for GetTokensFromRefreshToken does not specify the need for AWS credentials:​

This behavior differs from other operations like InitiateAuth, which do not require AWS credentials in similar contexts.

Possible Solution

Specify optionalAuth in cognito smithy configuration file for this operation.

Additional Information/Context

If the client is initialized as follows:

const client = new CognitoIdentityProviderClient({
  credentials: {
    accessKeyId: "123",
    secretAccessKey: "123",
  },
  region: "eu-north-1",
});

, then the operation succeeds.

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.p3This is a minor priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions