@aws-amplify/auth 6.16.1-unstable.aae2834.0 → 6.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/cjs/providers/cognito/apis/signInWithRedirect.js +14 -3
  2. package/dist/cjs/providers/cognito/apis/signInWithRedirect.js.map +1 -1
  3. package/dist/cjs/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.js +5 -2
  4. package/dist/cjs/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.js.map +1 -1
  5. package/dist/cjs/providers/cognito/tokenProvider/TokenOrchestrator.js +25 -3
  6. package/dist/cjs/providers/cognito/tokenProvider/TokenOrchestrator.js.map +1 -1
  7. package/dist/cjs/providers/cognito/utils/refreshAuthTokens.js +2 -1
  8. package/dist/cjs/providers/cognito/utils/refreshAuthTokens.js.map +1 -1
  9. package/dist/esm/providers/cognito/apis/signInWithRedirect.mjs +14 -3
  10. package/dist/esm/providers/cognito/apis/signInWithRedirect.mjs.map +1 -1
  11. package/dist/esm/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.d.ts +3 -2
  12. package/dist/esm/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.mjs +5 -2
  13. package/dist/esm/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.mjs.map +1 -1
  14. package/dist/esm/providers/cognito/tokenProvider/TokenOrchestrator.d.ts +4 -1
  15. package/dist/esm/providers/cognito/tokenProvider/TokenOrchestrator.mjs +26 -4
  16. package/dist/esm/providers/cognito/tokenProvider/TokenOrchestrator.mjs.map +1 -1
  17. package/dist/esm/providers/cognito/tokenProvider/types.d.ts +5 -3
  18. package/dist/esm/providers/cognito/types/models.d.ts +1 -2
  19. package/dist/esm/providers/cognito/utils/refreshAuthTokens.d.ts +2 -0
  20. package/dist/esm/providers/cognito/utils/refreshAuthTokens.mjs +2 -1
  21. package/dist/esm/providers/cognito/utils/refreshAuthTokens.mjs.map +1 -1
  22. package/dist/esm/types/inputs.d.ts +4 -0
  23. package/package.json +111 -111
  24. package/src/providers/cognito/apis/signInWithRedirect.ts +15 -2
  25. package/src/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.ts +9 -4
  26. package/src/providers/cognito/tokenProvider/TokenOrchestrator.ts +38 -4
  27. package/src/providers/cognito/tokenProvider/types.ts +7 -1
  28. package/src/providers/cognito/types/models.ts +1 -1
  29. package/src/providers/cognito/utils/refreshAuthTokens.ts +4 -0
  30. package/src/types/inputs.ts +4 -1
@@ -1,9 +1,10 @@
1
- import { AuthConfig, AuthTokens, FetchAuthSessionOptions, KeyValueStorageInterface, TokenProvider } from '@aws-amplify/core';
2
- import { CognitoAuthSignInDetails } from '../types';
3
- export type TokenRefresher = ({ tokens, authConfig, username, }: {
1
+ import { AuthConfig, AuthTokens, ClientMetadataProvider, FetchAuthSessionOptions, KeyValueStorageInterface, TokenProvider } from '@aws-amplify/core';
2
+ import { ClientMetadata, CognitoAuthSignInDetails } from '../types';
3
+ export type TokenRefresher = ({ tokens, authConfig, username, clientMetadata, }: {
4
4
  tokens: CognitoAuthTokens;
5
5
  authConfig?: AuthConfig;
6
6
  username: string;
7
+ clientMetadata?: ClientMetadata;
7
8
  }) => Promise<CognitoAuthTokens>;
8
9
  export type AuthKeys<AuthKey extends string> = Record<AuthKey, string>;
9
10
  export declare const AuthTokenStorageKeys: {
@@ -47,6 +48,7 @@ export interface AuthTokenOrchestrator {
47
48
  export interface CognitoUserPoolTokenProviderType extends TokenProvider {
48
49
  setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void;
49
50
  setAuthConfig(authConfig: AuthConfig): void;
51
+ setClientMetadataProvider(clientMetadataProvider: ClientMetadataProvider): void;
50
52
  }
51
53
  export type CognitoAuthTokens = AuthTokens & {
52
54
  refreshToken?: string;
@@ -12,7 +12,7 @@ export declare const cognitoHostedUIIdentityProviderMap: Record<AuthProvider, st
12
12
  /**
13
13
  * Arbitrary key/value pairs that may be passed as part of certain Cognito requests
14
14
  */
15
- export type ClientMetadata = Record<string, string>;
15
+ export type { ClientMetadata } from '@aws-amplify/core';
16
16
  /**
17
17
  * Allowed values for preferredChallenge
18
18
  */
@@ -70,4 +70,3 @@ export interface AuthUser extends AWSAuthUser {
70
70
  * Holds data describing the dispatch of a confirmation code.
71
71
  */
72
72
  export type CodeDeliveryDetails<CognitoUserAttributeKey extends UserAttributeKey = UserAttributeKey> = AuthCodeDeliveryDetails<CognitoUserAttributeKey>;
73
- export {};
@@ -1,8 +1,10 @@
1
1
  import { AuthConfig } from '@aws-amplify/core';
2
2
  import { CognitoAuthTokens, TokenRefresher } from '../tokenProvider/types';
3
+ import { ClientMetadata } from '../types';
3
4
  export declare const refreshAuthTokens: (args_0: {
4
5
  tokens: CognitoAuthTokens;
5
6
  authConfig?: AuthConfig;
6
7
  username: string;
8
+ clientMetadata?: ClientMetadata;
7
9
  }) => Promise<CognitoAuthTokens>;
8
10
  export declare const refreshAuthTokensWithoutDedupe: TokenRefresher;
@@ -15,7 +15,7 @@ import '../types/errors.mjs';
15
15
 
16
16
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
17
17
  // SPDX-License-Identifier: Apache-2.0
18
- const refreshAuthTokensFunction = async ({ tokens, authConfig, username, }) => {
18
+ const refreshAuthTokensFunction = async ({ tokens, authConfig, username, clientMetadata, }) => {
19
19
  assertTokenProviderConfig(authConfig?.Cognito);
20
20
  const { userPoolId, userPoolClientId, userPoolEndpoint } = authConfig.Cognito;
21
21
  const region = getRegionFromUserPoolId(userPoolId);
@@ -29,6 +29,7 @@ const refreshAuthTokensFunction = async ({ tokens, authConfig, username, }) => {
29
29
  ClientId: userPoolClientId,
30
30
  RefreshToken: tokens.refreshToken,
31
31
  DeviceKey: tokens.deviceMetadata?.deviceKey,
32
+ ClientMetadata: clientMetadata,
32
33
  });
33
34
  const accessToken = decodeJWT(AuthenticationResult?.AccessToken ?? '');
34
35
  const idToken = AuthenticationResult?.IdToken
@@ -1 +1 @@
1
- {"version":3,"file":"refreshAuthTokens.mjs","sources":["../../../../../src/providers/cognito/utils/refreshAuthTokens.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertTokenProviderConfig, deDupeAsyncFunction, decodeJWT, } from '@aws-amplify/core/internals/utils';\nimport { getRegionFromUserPoolId } from '../../../foundation/parsers';\nimport { assertAuthTokensWithRefreshToken } from '../utils/types';\nimport { AuthError } from '../../../errors/AuthError';\nimport { createCognitoUserPoolEndpointResolver } from '../factories';\nimport { createGetTokensFromRefreshTokenClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nconst refreshAuthTokensFunction = async ({ tokens, authConfig, username, }) => {\n assertTokenProviderConfig(authConfig?.Cognito);\n const { userPoolId, userPoolClientId, userPoolEndpoint } = authConfig.Cognito;\n const region = getRegionFromUserPoolId(userPoolId);\n assertAuthTokensWithRefreshToken(tokens);\n const getTokensFromRefreshToken = createGetTokensFromRefreshTokenClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { AuthenticationResult } = await getTokensFromRefreshToken({ region }, {\n ClientId: userPoolClientId,\n RefreshToken: tokens.refreshToken,\n DeviceKey: tokens.deviceMetadata?.deviceKey,\n });\n const accessToken = decodeJWT(AuthenticationResult?.AccessToken ?? '');\n const idToken = AuthenticationResult?.IdToken\n ? decodeJWT(AuthenticationResult.IdToken)\n : undefined;\n const { iat } = accessToken.payload;\n // This should never happen. If it does, it's a bug from the service.\n if (!iat) {\n throw new AuthError({\n name: 'iatNotFoundException',\n message: 'iat not found in access token',\n });\n }\n const clockDrift = iat * 1000 - new Date().getTime();\n return {\n accessToken,\n idToken,\n clockDrift,\n refreshToken: AuthenticationResult?.RefreshToken ?? tokens.refreshToken,\n username,\n };\n};\nexport const refreshAuthTokens = deDupeAsyncFunction(refreshAuthTokensFunction);\nexport const refreshAuthTokensWithoutDedupe = refreshAuthTokensFunction;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AAOA,MAAM,yBAAyB,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAG,KAAK;AAC/E,IAAI,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC;AAClD,IAAI,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,UAAU,CAAC,OAAO;AACjF,IAAI,MAAM,MAAM,GAAG,uBAAuB,CAAC,UAAU,CAAC;AACtD,IAAI,gCAAgC,CAAC,MAAM,CAAC;AAC5C,IAAI,MAAM,yBAAyB,GAAG,qCAAqC,CAAC;AAC5E,QAAQ,gBAAgB,EAAE,qCAAqC,CAAC;AAChE,YAAY,gBAAgB,EAAE,gBAAgB;AAC9C,SAAS,CAAC;AACV,KAAK,CAAC;AACN,IAAI,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,yBAAyB,CAAC,EAAE,MAAM,EAAE,EAAE;AACjF,QAAQ,QAAQ,EAAE,gBAAgB;AAClC,QAAQ,YAAY,EAAE,MAAM,CAAC,YAAY;AACzC,QAAQ,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,SAAS;AACnD,KAAK,CAAC;AACN,IAAI,MAAM,WAAW,GAAG,SAAS,CAAC,oBAAoB,EAAE,WAAW,IAAI,EAAE,CAAC;AAC1E,IAAI,MAAM,OAAO,GAAG,oBAAoB,EAAE;AAC1C,UAAU,SAAS,CAAC,oBAAoB,CAAC,OAAO;AAChD,UAAU,SAAS;AACnB,IAAI,MAAM,EAAE,GAAG,EAAE,GAAG,WAAW,CAAC,OAAO;AACvC;AACA,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,MAAM,IAAI,SAAS,CAAC;AAC5B,YAAY,IAAI,EAAE,sBAAsB;AACxC,YAAY,OAAO,EAAE,+BAA+B;AACpD,SAAS,CAAC;AACV,IAAI;AACJ,IAAI,MAAM,UAAU,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;AACxD,IAAI,OAAO;AACX,QAAQ,WAAW;AACnB,QAAQ,OAAO;AACf,QAAQ,UAAU;AAClB,QAAQ,YAAY,EAAE,oBAAoB,EAAE,YAAY,IAAI,MAAM,CAAC,YAAY;AAC/E,QAAQ,QAAQ;AAChB,KAAK;AACL,CAAC;AACW,MAAC,iBAAiB,GAAG,mBAAmB,CAAC,yBAAyB;AAClE,MAAC,8BAA8B,GAAG;;;;"}
1
+ {"version":3,"file":"refreshAuthTokens.mjs","sources":["../../../../../src/providers/cognito/utils/refreshAuthTokens.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertTokenProviderConfig, deDupeAsyncFunction, decodeJWT, } from '@aws-amplify/core/internals/utils';\nimport { getRegionFromUserPoolId } from '../../../foundation/parsers';\nimport { assertAuthTokensWithRefreshToken } from '../utils/types';\nimport { AuthError } from '../../../errors/AuthError';\nimport { createCognitoUserPoolEndpointResolver } from '../factories';\nimport { createGetTokensFromRefreshTokenClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nconst refreshAuthTokensFunction = async ({ tokens, authConfig, username, clientMetadata, }) => {\n assertTokenProviderConfig(authConfig?.Cognito);\n const { userPoolId, userPoolClientId, userPoolEndpoint } = authConfig.Cognito;\n const region = getRegionFromUserPoolId(userPoolId);\n assertAuthTokensWithRefreshToken(tokens);\n const getTokensFromRefreshToken = createGetTokensFromRefreshTokenClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { AuthenticationResult } = await getTokensFromRefreshToken({ region }, {\n ClientId: userPoolClientId,\n RefreshToken: tokens.refreshToken,\n DeviceKey: tokens.deviceMetadata?.deviceKey,\n ClientMetadata: clientMetadata,\n });\n const accessToken = decodeJWT(AuthenticationResult?.AccessToken ?? '');\n const idToken = AuthenticationResult?.IdToken\n ? decodeJWT(AuthenticationResult.IdToken)\n : undefined;\n const { iat } = accessToken.payload;\n // This should never happen. If it does, it's a bug from the service.\n if (!iat) {\n throw new AuthError({\n name: 'iatNotFoundException',\n message: 'iat not found in access token',\n });\n }\n const clockDrift = iat * 1000 - new Date().getTime();\n return {\n accessToken,\n idToken,\n clockDrift,\n refreshToken: AuthenticationResult?.RefreshToken ?? tokens.refreshToken,\n username,\n };\n};\nexport const refreshAuthTokens = deDupeAsyncFunction(refreshAuthTokensFunction);\nexport const refreshAuthTokensWithoutDedupe = refreshAuthTokensFunction;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AAOA,MAAM,yBAAyB,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,GAAG,KAAK;AAC/F,IAAI,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC;AAClD,IAAI,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,UAAU,CAAC,OAAO;AACjF,IAAI,MAAM,MAAM,GAAG,uBAAuB,CAAC,UAAU,CAAC;AACtD,IAAI,gCAAgC,CAAC,MAAM,CAAC;AAC5C,IAAI,MAAM,yBAAyB,GAAG,qCAAqC,CAAC;AAC5E,QAAQ,gBAAgB,EAAE,qCAAqC,CAAC;AAChE,YAAY,gBAAgB,EAAE,gBAAgB;AAC9C,SAAS,CAAC;AACV,KAAK,CAAC;AACN,IAAI,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,yBAAyB,CAAC,EAAE,MAAM,EAAE,EAAE;AACjF,QAAQ,QAAQ,EAAE,gBAAgB;AAClC,QAAQ,YAAY,EAAE,MAAM,CAAC,YAAY;AACzC,QAAQ,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,SAAS;AACnD,QAAQ,cAAc,EAAE,cAAc;AACtC,KAAK,CAAC;AACN,IAAI,MAAM,WAAW,GAAG,SAAS,CAAC,oBAAoB,EAAE,WAAW,IAAI,EAAE,CAAC;AAC1E,IAAI,MAAM,OAAO,GAAG,oBAAoB,EAAE;AAC1C,UAAU,SAAS,CAAC,oBAAoB,CAAC,OAAO;AAChD,UAAU,SAAS;AACnB,IAAI,MAAM,EAAE,GAAG,EAAE,GAAG,WAAW,CAAC,OAAO;AACvC;AACA,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,MAAM,IAAI,SAAS,CAAC;AAC5B,YAAY,IAAI,EAAE,sBAAsB;AACxC,YAAY,OAAO,EAAE,+BAA+B;AACpD,SAAS,CAAC;AACV,IAAI;AACJ,IAAI,MAAM,UAAU,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;AACxD,IAAI,OAAO;AACX,QAAQ,WAAW;AACnB,QAAQ,OAAO;AACf,QAAQ,UAAU;AAClB,QAAQ,YAAY,EAAE,oBAAoB,EAAE,YAAY,IAAI,MAAM,CAAC,YAAY;AAC/E,QAAQ,QAAQ;AAChB,KAAK;AACL,CAAC;AACW,MAAC,iBAAiB,GAAG,mBAAmB,CAAC,yBAAyB;AAClE,MAAC,8BAA8B,GAAG;;;;"}
@@ -47,6 +47,10 @@ export type AuthPrompt = 'NONE' | 'LOGIN' | 'CONSENT' | 'SELECT_ACCOUNT';
47
47
  export interface AuthSignInWithRedirectInput {
48
48
  provider?: AuthProvider | {
49
49
  custom: string;
50
+ idpIdentifier?: never;
51
+ } | {
52
+ idpIdentifier: string;
53
+ custom?: never;
50
54
  };
51
55
  customState?: string;
52
56
  options?: {
package/package.json CHANGED
@@ -1,113 +1,113 @@
1
1
  {
2
- "name": "@aws-amplify/auth",
3
- "version": "6.16.1-unstable.aae2834.0+aae2834",
4
- "description": "Auth category of aws-amplify",
5
- "main": "./dist/cjs/index.js",
6
- "module": "./dist/esm/index.mjs",
7
- "typings": "./dist/esm/index.d.ts",
8
- "react-native": "./dist/cjs/index.js",
9
- "sideEffects": [
10
- "./dist/cjs/providers/cognito/apis/signInWithRedirect.js",
11
- "./dist/esm/providers/cognito/apis/signInWithRedirect.mjs",
12
- "./dist/cjs/providers/cognito/utils/oauth/enableOAuthListener.js",
13
- "./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.mjs"
14
- ],
15
- "publishConfig": {
16
- "access": "public"
17
- },
18
- "scripts": {
19
- "test": "yarn lint --fix && jest -w 1 --coverage --logHeapUsage",
20
- "build-with-test": "npm test && npm run build",
21
- "build:umd": "webpack && webpack --config ./webpack.config.dev.js",
22
- "build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
23
- "build:watch": "npm run build:esm-cjs -- --watch",
24
- "build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
25
- "clean": "npm run clean:size && rimraf lib-esm lib dist",
26
- "clean:size": "rimraf dual-publish-tmp tmp*",
27
- "format": "echo \"Not implemented\"",
28
- "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
29
- "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
30
- "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 91.18"
31
- },
32
- "typesVersions": {
33
- ">=4.2": {
34
- "cognito": [
35
- "./dist/esm/providers/cognito/index.d.ts"
36
- ],
37
- "cognito/server": [
38
- "./dist/esm/providers/cognito/apis/server/index.d.ts"
39
- ],
40
- "server": [
41
- "./dist/esm/server.d.ts"
42
- ]
43
- }
44
- },
45
- "exports": {
46
- ".": {
47
- "react-native": "./dist/cjs/index.js",
48
- "types": "./dist/esm/index.d.ts",
49
- "import": "./dist/esm/index.mjs",
50
- "require": "./dist/cjs/index.js"
51
- },
52
- "./cognito": {
53
- "react-native": "./dist/cjs/providers/cognito/index.js",
54
- "types": "./dist/esm/providers/cognito/index.d.ts",
55
- "import": "./dist/esm/providers/cognito/index.mjs",
56
- "require": "./dist/cjs/providers/cognito/index.js"
57
- },
58
- "./cognito/server": {
59
- "types": "./dist/esm/providers/cognito/apis/server/index.d.ts",
60
- "import": "./dist/esm/providers/cognito/apis/server/index.mjs",
61
- "require": "./dist/cjs/providers/cognito/apis/server/index.js"
62
- },
63
- "./server": {
64
- "types": "./dist/esm/server.d.ts",
65
- "import": "./dist/esm/server.mjs",
66
- "require": "./dist/cjs/server.js"
67
- },
68
- "./enable-oauth-listener": {
69
- "types": "./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.d.ts",
70
- "import": "./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.mjs",
71
- "require": "./dist/cjs/providers/cognito/utils/oauth/enableOAuthListener.js"
72
- },
73
- "./package.json": "./package.json"
74
- },
75
- "repository": {
76
- "type": "git",
77
- "url": "https://github.com/aws-amplify/amplify-js.git"
78
- },
79
- "author": "Amazon Web Services",
80
- "license": "Apache-2.0",
81
- "bugs": {
82
- "url": "https://github.com/aws/aws-amplify/issues"
83
- },
84
- "homepage": "https://aws-amplify.github.io/",
85
- "files": [
86
- "dist/cjs",
87
- "dist/esm",
88
- "src",
89
- "cognito",
90
- "server",
91
- "enable-oauth-listener"
92
- ],
93
- "dependencies": {
94
- "@aws-crypto/sha256-js": "5.2.0",
95
- "@smithy/types": "^3.3.0",
96
- "tslib": "^2.5.0"
97
- },
98
- "peerDependencies": {
99
- "@aws-amplify/core": "6.13.4-unstable.aae2834.0+aae2834",
100
- "@aws-amplify/react-native": "^1.1.10"
101
- },
102
- "peerDependenciesMeta": {
103
- "@aws-amplify/react-native": {
104
- "optional": true
105
- }
106
- },
107
- "devDependencies": {
108
- "@aws-amplify/core": "6.13.4-unstable.aae2834.0+aae2834",
109
- "@aws-amplify/react-native": "1.2.1-unstable.aae2834.0+aae2834",
110
- "@jest/test-sequencer": "^29.7.0"
111
- },
112
- "gitHead": "aae28343658394c3ee339e8947524feac977c8de"
2
+ "name": "@aws-amplify/auth",
3
+ "version": "6.17.0",
4
+ "description": "Auth category of aws-amplify",
5
+ "main": "./dist/cjs/index.js",
6
+ "module": "./dist/esm/index.mjs",
7
+ "typings": "./dist/esm/index.d.ts",
8
+ "react-native": "./dist/cjs/index.js",
9
+ "sideEffects": [
10
+ "./dist/cjs/providers/cognito/apis/signInWithRedirect.js",
11
+ "./dist/esm/providers/cognito/apis/signInWithRedirect.mjs",
12
+ "./dist/cjs/providers/cognito/utils/oauth/enableOAuthListener.js",
13
+ "./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.mjs"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "scripts": {
19
+ "test": "yarn lint --fix && jest -w 1 --coverage --logHeapUsage",
20
+ "build-with-test": "npm test && npm run build",
21
+ "build:umd": "webpack && webpack --config ./webpack.config.dev.js",
22
+ "build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
23
+ "build:watch": "npm run build:esm-cjs -- --watch",
24
+ "build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
25
+ "clean": "npm run clean:size && rimraf lib-esm lib dist",
26
+ "clean:size": "rimraf dual-publish-tmp tmp*",
27
+ "format": "echo \"Not implemented\"",
28
+ "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
29
+ "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
30
+ "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 91.18"
31
+ },
32
+ "typesVersions": {
33
+ ">=4.2": {
34
+ "cognito": [
35
+ "./dist/esm/providers/cognito/index.d.ts"
36
+ ],
37
+ "cognito/server": [
38
+ "./dist/esm/providers/cognito/apis/server/index.d.ts"
39
+ ],
40
+ "server": [
41
+ "./dist/esm/server.d.ts"
42
+ ]
43
+ }
44
+ },
45
+ "exports": {
46
+ ".": {
47
+ "react-native": "./dist/cjs/index.js",
48
+ "types": "./dist/esm/index.d.ts",
49
+ "import": "./dist/esm/index.mjs",
50
+ "require": "./dist/cjs/index.js"
51
+ },
52
+ "./cognito": {
53
+ "react-native": "./dist/cjs/providers/cognito/index.js",
54
+ "types": "./dist/esm/providers/cognito/index.d.ts",
55
+ "import": "./dist/esm/providers/cognito/index.mjs",
56
+ "require": "./dist/cjs/providers/cognito/index.js"
57
+ },
58
+ "./cognito/server": {
59
+ "types": "./dist/esm/providers/cognito/apis/server/index.d.ts",
60
+ "import": "./dist/esm/providers/cognito/apis/server/index.mjs",
61
+ "require": "./dist/cjs/providers/cognito/apis/server/index.js"
62
+ },
63
+ "./server": {
64
+ "types": "./dist/esm/server.d.ts",
65
+ "import": "./dist/esm/server.mjs",
66
+ "require": "./dist/cjs/server.js"
67
+ },
68
+ "./enable-oauth-listener": {
69
+ "types": "./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.d.ts",
70
+ "import": "./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.mjs",
71
+ "require": "./dist/cjs/providers/cognito/utils/oauth/enableOAuthListener.js"
72
+ },
73
+ "./package.json": "./package.json"
74
+ },
75
+ "repository": {
76
+ "type": "git",
77
+ "url": "https://github.com/aws-amplify/amplify-js.git"
78
+ },
79
+ "author": "Amazon Web Services",
80
+ "license": "Apache-2.0",
81
+ "bugs": {
82
+ "url": "https://github.com/aws/aws-amplify/issues"
83
+ },
84
+ "homepage": "https://aws-amplify.github.io/",
85
+ "files": [
86
+ "dist/cjs",
87
+ "dist/esm",
88
+ "src",
89
+ "cognito",
90
+ "server",
91
+ "enable-oauth-listener"
92
+ ],
93
+ "dependencies": {
94
+ "@aws-crypto/sha256-js": "5.2.0",
95
+ "@smithy/types": "^3.3.0",
96
+ "tslib": "^2.5.0"
97
+ },
98
+ "peerDependencies": {
99
+ "@aws-amplify/core": "^6.1.0",
100
+ "@aws-amplify/react-native": "^1.1.10"
101
+ },
102
+ "peerDependenciesMeta": {
103
+ "@aws-amplify/react-native": {
104
+ "optional": true
105
+ }
106
+ },
107
+ "devDependencies": {
108
+ "@aws-amplify/core": "6.14.0",
109
+ "@aws-amplify/react-native": "1.3.0",
110
+ "@jest/test-sequencer": "^29.7.0"
111
+ },
112
+ "gitHead": "bcb7c416052db16e7e329b2ac44fadc564274e2b"
113
113
  }
@@ -51,17 +51,21 @@ export async function signInWithRedirect(
51
51
  }
52
52
 
53
53
  let provider = 'COGNITO'; // Default
54
+ let idpIdentifier: string | undefined;
54
55
 
55
56
  if (typeof input?.provider === 'string') {
56
57
  provider = cognitoHostedUIIdentityProviderMap[input.provider];
57
58
  } else if (input?.provider?.custom) {
58
59
  provider = input.provider.custom;
60
+ } else if (input?.provider?.idpIdentifier) {
61
+ ({ idpIdentifier } = input.provider);
59
62
  }
60
63
 
61
64
  return oauthSignIn({
62
65
  oauthConfig: authConfig.loginWith.oauth,
63
66
  clientId: authConfig.userPoolClientId,
64
67
  provider,
68
+ idpIdentifier,
65
69
  customState: input?.customState,
66
70
  preferPrivateSession: input?.options?.preferPrivateSession,
67
71
  options: {
@@ -77,6 +81,7 @@ export async function signInWithRedirect(
77
81
  const oauthSignIn = async ({
78
82
  oauthConfig,
79
83
  provider,
84
+ idpIdentifier,
80
85
  clientId,
81
86
  customState,
82
87
  preferPrivateSession,
@@ -85,6 +90,7 @@ const oauthSignIn = async ({
85
90
  }: {
86
91
  oauthConfig: OAuthConfig;
87
92
  provider: string;
93
+ idpIdentifier?: string;
88
94
  clientId: string;
89
95
  customState?: string;
90
96
  preferPrivateSession?: boolean;
@@ -117,10 +123,17 @@ const oauthSignIn = async ({
117
123
  ['redirect_uri', redirectUri],
118
124
  ['response_type', responseType],
119
125
  ['client_id', clientId],
120
- ['identity_provider', provider],
121
- ['scope', scopes.join(' ')],
122
126
  ]);
123
127
 
128
+ // Add either identity_provider or idp_identifier, but not both
129
+ if (idpIdentifier) {
130
+ params.append('idp_identifier', idpIdentifier);
131
+ } else {
132
+ params.append('identity_provider', provider);
133
+ }
134
+
135
+ params.append('scope', scopes.join(' '));
136
+
124
137
  loginHint && params.append('login_hint', loginHint);
125
138
  lang && params.append('lang', lang);
126
139
  nonce && params.append('nonce', nonce);
@@ -4,6 +4,7 @@
4
4
  import {
5
5
  AuthConfig,
6
6
  AuthTokens,
7
+ ClientMetadataProvider,
7
8
  FetchAuthSessionOptions,
8
9
  KeyValueStorageInterface,
9
10
  defaultStorage,
@@ -28,16 +29,20 @@ export class CognitoUserPoolsTokenProvider
28
29
  this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens);
29
30
  }
30
31
 
31
- getTokens(
32
- { forceRefresh }: FetchAuthSessionOptions = { forceRefresh: false },
33
- ): Promise<AuthTokens | null> {
34
- return this.tokenOrchestrator.getTokens({ forceRefresh });
32
+ getTokens(options: FetchAuthSessionOptions = {}): Promise<AuthTokens | null> {
33
+ return this.tokenOrchestrator.getTokens(options);
35
34
  }
36
35
 
37
36
  setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void {
38
37
  this.authTokenStore.setKeyValueStorage(keyValueStorage);
39
38
  }
40
39
 
40
+ setClientMetadataProvider(
41
+ clientMetadataProvider: ClientMetadataProvider,
42
+ ): void {
43
+ this.tokenOrchestrator.setClientMetadataProvider(clientMetadataProvider);
44
+ }
45
+
41
46
  setAuthConfig(authConfig: AuthConfig) {
42
47
  this.authTokenStore.setAuthConfig(authConfig);
43
48
  this.tokenOrchestrator.setAuthConfig(authConfig);
@@ -3,13 +3,13 @@
3
3
  import {
4
4
  AuthConfig,
5
5
  AuthTokens,
6
+ ClientMetadataProvider,
6
7
  CognitoUserPoolConfig,
7
8
  FetchAuthSessionOptions,
8
9
  Hub,
9
10
  } from '@aws-amplify/core';
10
11
  import {
11
12
  AMPLIFY_SYMBOL,
12
- AmplifyErrorCode,
13
13
  assertTokenProviderConfig,
14
14
  isBrowser,
15
15
  isTokenExpired,
@@ -19,7 +19,7 @@ import { assertServiceError } from '../../../errors/utils/assertServiceError';
19
19
  import { AuthError } from '../../../errors/AuthError';
20
20
  import { oAuthStore } from '../utils/oauth/oAuthStore';
21
21
  import { addInflightPromise } from '../utils/oauth/inflightPromise';
22
- import { CognitoAuthSignInDetails } from '../types';
22
+ import { ClientMetadata, CognitoAuthSignInDetails } from '../types';
23
23
 
24
24
  import {
25
25
  AuthTokenOrchestrator,
@@ -32,6 +32,7 @@ import {
32
32
 
33
33
  export class TokenOrchestrator implements AuthTokenOrchestrator {
34
34
  private authConfig?: AuthConfig;
35
+ clientMetadataProvider?: ClientMetadataProvider;
35
36
  tokenStore?: AuthTokenStore;
36
37
  tokenRefresher?: TokenRefresher;
37
38
  inflightPromise: Promise<void> | undefined;
@@ -94,6 +95,12 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
94
95
  return this.tokenRefresher;
95
96
  }
96
97
 
98
+ setClientMetadataProvider(
99
+ clientMetadataProvider: ClientMetadataProvider,
100
+ ): void {
101
+ this.clientMetadataProvider = clientMetadataProvider;
102
+ }
103
+
97
104
  async getTokens(
98
105
  options?: FetchAuthSessionOptions,
99
106
  ): Promise<
@@ -130,6 +137,8 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
130
137
  tokens = await this.refreshTokens({
131
138
  tokens,
132
139
  username,
140
+ clientMetadata:
141
+ options?.clientMetadata ?? (await this.clientMetadataProvider?.()),
133
142
  });
134
143
 
135
144
  if (tokens === null) {
@@ -147,9 +156,11 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
147
156
  private async refreshTokens({
148
157
  tokens,
149
158
  username,
159
+ clientMetadata,
150
160
  }: {
151
161
  tokens: CognitoAuthTokens;
152
162
  username: string;
163
+ clientMetadata?: ClientMetadata;
153
164
  }): Promise<CognitoAuthTokens | null> {
154
165
  try {
155
166
  const { signInDetails } = tokens;
@@ -157,6 +168,7 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
157
168
  tokens,
158
169
  authConfig: this.authConfig,
159
170
  username,
171
+ clientMetadata,
160
172
  });
161
173
  newTokens.signInDetails = signInDetails;
162
174
  await this.setTokens({ tokens: newTokens });
@@ -170,10 +182,15 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
170
182
 
171
183
  private handleErrors(err: unknown) {
172
184
  assertServiceError(err);
173
- if (err.name !== AmplifyErrorCode.NetworkError) {
174
- // TODO(v6): Check errors on client
185
+
186
+ // Only clear tokens for definitive authentication failures
187
+ // Do NOT clear tokens for transient errors like service issues, rate limits, etc.
188
+ const shouldClearTokens = this.isAuthenticationError(err);
189
+
190
+ if (shouldClearTokens) {
175
191
  this.clearTokens();
176
192
  }
193
+
177
194
  Hub.dispatch(
178
195
  'auth',
179
196
  {
@@ -190,6 +207,23 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
190
207
  throw err;
191
208
  }
192
209
 
210
+ private isAuthenticationError(err: any): boolean {
211
+ // Only clear tokens for errors that definitively indicate the tokens are invalid
212
+ // and re-authentication is required. All other errors (service errors, rate limits, etc.)
213
+ // should preserve the tokens to allow for retry.
214
+ // See: https://github.com/aws-amplify/amplify-js/issues/14534
215
+ const authErrorNames = [
216
+ 'NotAuthorizedException', // Refresh token is expired or invalid
217
+ 'TokenRevokedException', // Token was revoked by admin
218
+ 'UserNotFoundException', // User no longer exists
219
+ 'PasswordResetRequiredException', // User must reset password
220
+ 'UserNotConfirmedException', // User account is not confirmed
221
+ 'RefreshTokenReuseException', // Refresh token invalidated by rotation
222
+ ];
223
+
224
+ return authErrorNames.some(errorName => err?.name?.startsWith?.(errorName));
225
+ }
226
+
193
227
  async setTokens({ tokens }: { tokens: CognitoAuthTokens }) {
194
228
  return this.getTokenStore().storeTokens(tokens);
195
229
  }
@@ -3,21 +3,24 @@
3
3
  import {
4
4
  AuthConfig,
5
5
  AuthTokens,
6
+ ClientMetadataProvider,
6
7
  FetchAuthSessionOptions,
7
8
  KeyValueStorageInterface,
8
9
  TokenProvider,
9
10
  } from '@aws-amplify/core';
10
11
 
11
- import { CognitoAuthSignInDetails } from '../types';
12
+ import { ClientMetadata, CognitoAuthSignInDetails } from '../types';
12
13
 
13
14
  export type TokenRefresher = ({
14
15
  tokens,
15
16
  authConfig,
16
17
  username,
18
+ clientMetadata,
17
19
  }: {
18
20
  tokens: CognitoAuthTokens;
19
21
  authConfig?: AuthConfig;
20
22
  username: string;
23
+ clientMetadata?: ClientMetadata;
21
24
  }) => Promise<CognitoAuthTokens>;
22
25
 
23
26
  export type AuthKeys<AuthKey extends string> = Record<AuthKey, string>;
@@ -66,6 +69,9 @@ export interface AuthTokenOrchestrator {
66
69
  export interface CognitoUserPoolTokenProviderType extends TokenProvider {
67
70
  setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void;
68
71
  setAuthConfig(authConfig: AuthConfig): void;
72
+ setClientMetadataProvider(
73
+ clientMetadataProvider: ClientMetadataProvider,
74
+ ): void;
69
75
  }
70
76
 
71
77
  export type CognitoAuthTokens = AuthTokens & {
@@ -38,7 +38,7 @@ export const cognitoHostedUIIdentityProviderMap: Record<AuthProvider, string> =
38
38
  /**
39
39
  * Arbitrary key/value pairs that may be passed as part of certain Cognito requests
40
40
  */
41
- export type ClientMetadata = Record<string, string>;
41
+ export type { ClientMetadata } from '@aws-amplify/core';
42
42
 
43
43
  /**
44
44
  * Allowed values for preferredChallenge
@@ -14,15 +14,18 @@ import { assertAuthTokensWithRefreshToken } from '../utils/types';
14
14
  import { AuthError } from '../../../errors/AuthError';
15
15
  import { createCognitoUserPoolEndpointResolver } from '../factories';
16
16
  import { createGetTokensFromRefreshTokenClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';
17
+ import { ClientMetadata } from '../types';
17
18
 
18
19
  const refreshAuthTokensFunction: TokenRefresher = async ({
19
20
  tokens,
20
21
  authConfig,
21
22
  username,
23
+ clientMetadata,
22
24
  }: {
23
25
  tokens: CognitoAuthTokens;
24
26
  authConfig?: AuthConfig;
25
27
  username: string;
28
+ clientMetadata?: ClientMetadata;
26
29
  }): Promise<CognitoAuthTokens> => {
27
30
  assertTokenProviderConfig(authConfig?.Cognito);
28
31
  const { userPoolId, userPoolClientId, userPoolEndpoint } = authConfig.Cognito;
@@ -41,6 +44,7 @@ const refreshAuthTokensFunction: TokenRefresher = async ({
41
44
  ClientId: userPoolClientId,
42
45
  RefreshToken: tokens.refreshToken,
43
46
  DeviceKey: tokens.deviceMetadata?.deviceKey,
47
+ ClientMetadata: clientMetadata,
44
48
  },
45
49
  );
46
50
 
@@ -69,7 +69,10 @@ export type AuthProvider = 'Amazon' | 'Apple' | 'Facebook' | 'Google';
69
69
  export type AuthPrompt = 'NONE' | 'LOGIN' | 'CONSENT' | 'SELECT_ACCOUNT';
70
70
 
71
71
  export interface AuthSignInWithRedirectInput {
72
- provider?: AuthProvider | { custom: string };
72
+ provider?:
73
+ | AuthProvider
74
+ | { custom: string; idpIdentifier?: never }
75
+ | { idpIdentifier: string; custom?: never };
73
76
  customState?: string;
74
77
  options?: {
75
78
  /**