@aws-amplify/auth 6.5.4-local-stack.0aa9031.0 → 6.5.4-next-15.7992a88.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 (27) hide show
  1. package/dist/cjs/providers/cognito/credentialsProvider/IdentityIdProvider.js +2 -8
  2. package/dist/cjs/providers/cognito/credentialsProvider/IdentityIdProvider.js.map +1 -1
  3. package/dist/cjs/providers/cognito/credentialsProvider/credentialsProvider.js +2 -13
  4. package/dist/cjs/providers/cognito/credentialsProvider/credentialsProvider.js.map +1 -1
  5. package/dist/cjs/providers/cognito/factories/index.js +1 -3
  6. package/dist/cjs/providers/cognito/factories/index.js.map +1 -1
  7. package/dist/esm/providers/cognito/apis/internal/fetchUserAttributes.mjs +0 -1
  8. package/dist/esm/providers/cognito/apis/internal/fetchUserAttributes.mjs.map +1 -1
  9. package/dist/esm/providers/cognito/credentialsProvider/IdentityIdProvider.mjs +2 -10
  10. package/dist/esm/providers/cognito/credentialsProvider/IdentityIdProvider.mjs.map +1 -1
  11. package/dist/esm/providers/cognito/credentialsProvider/credentialsProvider.mjs +1 -13
  12. package/dist/esm/providers/cognito/credentialsProvider/credentialsProvider.mjs.map +1 -1
  13. package/dist/esm/providers/cognito/factories/index.d.ts +0 -1
  14. package/dist/esm/providers/cognito/factories/index.mjs +0 -1
  15. package/dist/esm/providers/cognito/factories/index.mjs.map +1 -1
  16. package/dist/esm/providers/cognito/utils/refreshAuthTokens.mjs +0 -1
  17. package/dist/esm/providers/cognito/utils/refreshAuthTokens.mjs.map +1 -1
  18. package/package.json +5 -5
  19. package/src/providers/cognito/credentialsProvider/IdentityIdProvider.ts +2 -14
  20. package/src/providers/cognito/credentialsProvider/credentialsProvider.ts +1 -14
  21. package/src/providers/cognito/factories/index.ts +0 -1
  22. package/dist/cjs/providers/cognito/factories/createCognitoIdentityPoolEndpointResolver.js +0 -16
  23. package/dist/cjs/providers/cognito/factories/createCognitoIdentityPoolEndpointResolver.js.map +0 -1
  24. package/dist/esm/providers/cognito/factories/createCognitoIdentityPoolEndpointResolver.d.ts +0 -6
  25. package/dist/esm/providers/cognito/factories/createCognitoIdentityPoolEndpointResolver.mjs +0 -14
  26. package/dist/esm/providers/cognito/factories/createCognitoIdentityPoolEndpointResolver.mjs.map +0 -1
  27. package/src/providers/cognito/factories/createCognitoIdentityPoolEndpointResolver.ts +0 -15
@@ -7,7 +7,6 @@ exports.cognitoIdentityIdProvider = void 0;
7
7
  const core_1 = require("@aws-amplify/core");
8
8
  const AuthError_1 = require("../../../errors/AuthError");
9
9
  const parsers_1 = require("../../../foundation/parsers");
10
- const factories_1 = require("../factories");
11
10
  const utils_1 = require("./utils");
12
11
  const logger = new core_1.ConsoleLogger('CognitoIdentityIdProvider');
13
12
  /**
@@ -63,16 +62,11 @@ exports.cognitoIdentityIdProvider = cognitoIdentityIdProvider;
63
62
  async function generateIdentityId(logins, authConfig) {
64
63
  const identityPoolId = authConfig?.identityPoolId;
65
64
  const region = (0, parsers_1.getRegionFromIdentityPoolId)(identityPoolId);
66
- const getId = (0, core_1.createGetIdClient)({
67
- endpointResolver: (0, factories_1.createCognitoIdentityPoolEndpointResolver)({
68
- endpointOverride: authConfig.identityPoolEndpoint,
69
- }),
70
- });
71
65
  // IdentityId is absent so get it using IdentityPoolId with Cognito's GetId API
72
66
  const idResult =
73
67
  // for a first-time user, this will return a brand new identity
74
- // for a returning user, this will retrieve the previous identity associated with the logins
75
- (await getId({
68
+ // for a returning user, this will retrieve the previous identity assocaited with the logins
69
+ (await (0, core_1.getId)({
76
70
  region,
77
71
  }, {
78
72
  IdentityPoolId: identityPoolId,
@@ -1 +1 @@
1
- {"version":3,"file":"IdentityIdProvider.js","sources":["../../../../../src/providers/cognito/credentialsProvider/IdentityIdProvider.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.cognitoIdentityIdProvider = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst AuthError_1 = require(\"../../../errors/AuthError\");\nconst parsers_1 = require(\"../../../foundation/parsers\");\nconst factories_1 = require(\"../factories\");\nconst utils_1 = require(\"./utils\");\nconst logger = new core_1.ConsoleLogger('CognitoIdentityIdProvider');\n/**\n * Provides a Cognito identityId\n *\n * @param tokens - The AuthTokens received after SignIn\n * @returns string\n * @throws configuration exceptions: `InvalidIdentityPoolIdException`\n * - Auth errors that may arise from misconfiguration.\n * @throws service exceptions: {@link GetIdException }\n */\nasync function cognitoIdentityIdProvider({ tokens, authConfig, identityIdStore, }) {\n identityIdStore.setAuthConfig({ Cognito: authConfig });\n // will return null only if there is no identityId cached or if there is an error retrieving it\n let identityId = await identityIdStore.loadIdentityId();\n // Tokens are available so return primary identityId\n if (tokens) {\n // If there is existing primary identityId in-memory return that\n if (identityId && identityId.type === 'primary') {\n return identityId.id;\n }\n else {\n const logins = tokens.idToken\n ? (0, utils_1.formLoginsMap)(tokens.idToken.toString())\n : {};\n const generatedIdentityId = await generateIdentityId(logins, authConfig);\n if (identityId && identityId.id === generatedIdentityId) {\n logger.debug(`The guest identity ${identityId.id} has become the primary identity.`);\n }\n identityId = {\n id: generatedIdentityId,\n type: 'primary',\n };\n }\n }\n else {\n // If there is existing guest identityId cached return that\n if (identityId && identityId.type === 'guest') {\n return identityId.id;\n }\n else {\n identityId = {\n id: await generateIdentityId({}, authConfig),\n type: 'guest',\n };\n }\n }\n // Store in-memory or local storage depending on guest or primary identityId\n identityIdStore.storeIdentityId(identityId);\n return identityId.id;\n}\nexports.cognitoIdentityIdProvider = cognitoIdentityIdProvider;\nasync function generateIdentityId(logins, authConfig) {\n const identityPoolId = authConfig?.identityPoolId;\n const region = (0, parsers_1.getRegionFromIdentityPoolId)(identityPoolId);\n const getId = (0, core_1.createGetIdClient)({\n endpointResolver: (0, factories_1.createCognitoIdentityPoolEndpointResolver)({\n endpointOverride: authConfig.identityPoolEndpoint,\n }),\n });\n // IdentityId is absent so get it using IdentityPoolId with Cognito's GetId API\n const idResult = \n // for a first-time user, this will return a brand new identity\n // for a returning user, this will retrieve the previous identity associated with the logins\n (await getId({\n region,\n }, {\n IdentityPoolId: identityPoolId,\n Logins: logins,\n })).IdentityId;\n if (!idResult) {\n throw new AuthError_1.AuthError({\n name: 'GetIdResponseException',\n message: 'Received undefined response from getId operation',\n recoverySuggestion: 'Make sure to pass a valid identityPoolId in the configuration.',\n });\n }\n return idResult;\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,yBAAyB,GAAG,KAAK,CAAC,CAAC;AAC3C,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACzD,MAAM,SAAS,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AACzD,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,2BAA2B,CAAC,CAAC;AACrE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,yBAAyB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,GAAG,EAAE;AACnF,IAAI,eAAe,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;AAC3D;AACA,IAAI,IAAI,UAAU,GAAG,MAAM,eAAe,CAAC,cAAc,EAAE,CAAC;AAC5D;AACA,IAAI,IAAI,MAAM,EAAE;AAChB;AACA,QAAQ,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE;AACz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AG,IAAI,SAAS,CAAC,2BAA2B,EAAE,cAAc,CAAC,CAAC;AAC9E,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,iBAAiB,EAAE;AAChD,QAAQ,gBAAgB,EAAE,IAAI,WAAW,CAAC,yCAAyC,EAAE;AACrF,YAAY,gBAAgB,EAAE,UAAU,CAAC,oBAAoB;AAC7D,SAAS,CAAC;AACV,KAAK,CAAC,CAAC;AACP;AACA,IAAI,MAAM,QAAQ;AAClB;AACA;AACA,IAAI,CAAC,MAAM,KAAK,CAAC;AACjB,QAAQ,MAAM;AACd,KAAK,EAAE;AACP,QAAQ,cAAc,EAAE,cAAc;AACtC,QAAQ,MAAM,EAAE,MAAM;AACtB,KAAK,CAAC,EAAE,UAAU,CAAC;AACnB,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB,QAAQ,MAAM,IAAI,WAAW,CAAC,SAAS,CAAC;AACxC,YAAY,IAAI,EAAE,wBAAwB;AAC1C,YAAY,OAAO,EAAE,kDAAkD;AACvE,YAAY,kBAAkB,EAAE,gEAAgE;AAChG,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,QAAQ,CAAC;AACpB;;"}
1
+ {"version":3,"file":"IdentityIdProvider.js","sources":["../../../../../src/providers/cognito/credentialsProvider/IdentityIdProvider.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.cognitoIdentityIdProvider = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst AuthError_1 = require(\"../../../errors/AuthError\");\nconst parsers_1 = require(\"../../../foundation/parsers\");\nconst utils_1 = require(\"./utils\");\nconst logger = new core_1.ConsoleLogger('CognitoIdentityIdProvider');\n/**\n * Provides a Cognito identityId\n *\n * @param tokens - The AuthTokens received after SignIn\n * @returns string\n * @throws configuration exceptions: `InvalidIdentityPoolIdException`\n * - Auth errors that may arise from misconfiguration.\n * @throws service exceptions: {@link GetIdException }\n */\nasync function cognitoIdentityIdProvider({ tokens, authConfig, identityIdStore, }) {\n identityIdStore.setAuthConfig({ Cognito: authConfig });\n // will return null only if there is no identityId cached or if there is an error retrieving it\n let identityId = await identityIdStore.loadIdentityId();\n // Tokens are available so return primary identityId\n if (tokens) {\n // If there is existing primary identityId in-memory return that\n if (identityId && identityId.type === 'primary') {\n return identityId.id;\n }\n else {\n const logins = tokens.idToken\n ? (0, utils_1.formLoginsMap)(tokens.idToken.toString())\n : {};\n const generatedIdentityId = await generateIdentityId(logins, authConfig);\n if (identityId && identityId.id === generatedIdentityId) {\n logger.debug(`The guest identity ${identityId.id} has become the primary identity.`);\n }\n identityId = {\n id: generatedIdentityId,\n type: 'primary',\n };\n }\n }\n else {\n // If there is existing guest identityId cached return that\n if (identityId && identityId.type === 'guest') {\n return identityId.id;\n }\n else {\n identityId = {\n id: await generateIdentityId({}, authConfig),\n type: 'guest',\n };\n }\n }\n // Store in-memory or local storage depending on guest or primary identityId\n identityIdStore.storeIdentityId(identityId);\n return identityId.id;\n}\nexports.cognitoIdentityIdProvider = cognitoIdentityIdProvider;\nasync function generateIdentityId(logins, authConfig) {\n const identityPoolId = authConfig?.identityPoolId;\n const region = (0, parsers_1.getRegionFromIdentityPoolId)(identityPoolId);\n // IdentityId is absent so get it using IdentityPoolId with Cognito's GetId API\n const idResult = \n // for a first-time user, this will return a brand new identity\n // for a returning user, this will retrieve the previous identity assocaited with the logins\n (await (0, core_1.getId)({\n region,\n }, {\n IdentityPoolId: identityPoolId,\n Logins: logins,\n })).IdentityId;\n if (!idResult) {\n throw new AuthError_1.AuthError({\n name: 'GetIdResponseException',\n message: 'Received undefined response from getId operation',\n recoverySuggestion: 'Make sure to pass a valid identityPoolId in the configuration.',\n });\n }\n return idResult;\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAA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AChG,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,QAAQ,CAAC;AACpB;;"}
@@ -9,7 +9,6 @@ const utils_1 = require("@aws-amplify/core/internals/utils");
9
9
  const AuthError_1 = require("../../../errors/AuthError");
10
10
  const parsers_1 = require("../../../foundation/parsers");
11
11
  const types_1 = require("../utils/types");
12
- const factories_1 = require("../factories");
13
12
  const IdentityIdProvider_1 = require("./IdentityIdProvider");
14
13
  const utils_2 = require("./utils");
15
14
  const logger = new core_1.ConsoleLogger('CognitoCredentialsProvider');
@@ -73,16 +72,11 @@ class CognitoAWSCredentialsAndIdentityIdProvider {
73
72
  // Clear to discard if any authenticated credentials are set and start with a clean slate
74
73
  this.clearCredentials();
75
74
  const region = (0, parsers_1.getRegionFromIdentityPoolId)(authConfig.identityPoolId);
76
- const getCredentialsForIdentity = (0, core_1.createGetCredentialsForIdentityClient)({
77
- endpointResolver: (0, factories_1.createCognitoIdentityPoolEndpointResolver)({
78
- endpointOverride: authConfig.identityPoolEndpoint,
79
- }),
80
- });
81
75
  // use identityId to obtain guest credentials
82
76
  // save credentials in-memory
83
77
  // No logins params should be passed for guest creds:
84
78
  // https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html
85
- const clientResult = await getCredentialsForIdentity({ region }, {
79
+ const clientResult = await (0, core_1.getCredentialsForIdentity)({ region }, {
86
80
  IdentityId: identityId,
87
81
  });
88
82
  if (clientResult.Credentials &&
@@ -132,12 +126,7 @@ class CognitoAWSCredentialsAndIdentityIdProvider {
132
126
  ? (0, utils_2.formLoginsMap)(authTokens.idToken.toString())
133
127
  : {};
134
128
  const region = (0, parsers_1.getRegionFromIdentityPoolId)(authConfig.identityPoolId);
135
- const getCredentialsForIdentity = (0, core_1.createGetCredentialsForIdentityClient)({
136
- endpointResolver: (0, factories_1.createCognitoIdentityPoolEndpointResolver)({
137
- endpointOverride: authConfig.identityPoolEndpoint,
138
- }),
139
- });
140
- const clientResult = await getCredentialsForIdentity({ region }, {
129
+ const clientResult = await (0, core_1.getCredentialsForIdentity)({ region }, {
141
130
  IdentityId: identityId,
142
131
  Logins: logins,
143
132
  });
@@ -1 +1 @@
1
- {"version":3,"file":"credentialsProvider.js","sources":["../../../../../src/providers/cognito/credentialsProvider/credentialsProvider.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.CognitoAWSCredentialsAndIdentityIdProvider = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst AuthError_1 = require(\"../../../errors/AuthError\");\nconst parsers_1 = require(\"../../../foundation/parsers\");\nconst types_1 = require(\"../utils/types\");\nconst factories_1 = require(\"../factories\");\nconst IdentityIdProvider_1 = require(\"./IdentityIdProvider\");\nconst utils_2 = require(\"./utils\");\nconst logger = new core_1.ConsoleLogger('CognitoCredentialsProvider');\nconst CREDENTIALS_TTL = 50 * 60 * 1000; // 50 min, can be modified on config if required in the future\nclass CognitoAWSCredentialsAndIdentityIdProvider {\n constructor(identityIdStore) {\n this._nextCredentialsRefresh = 0;\n this._identityIdStore = identityIdStore;\n }\n async clearCredentialsAndIdentityId() {\n logger.debug('Clearing out credentials and identityId');\n this._credentialsAndIdentityId = undefined;\n await this._identityIdStore.clearIdentityId();\n }\n async clearCredentials() {\n logger.debug('Clearing out in-memory credentials');\n this._credentialsAndIdentityId = undefined;\n }\n async getCredentialsAndIdentityId(getCredentialsOptions) {\n const isAuthenticated = getCredentialsOptions.authenticated;\n const { tokens } = getCredentialsOptions;\n const { authConfig } = getCredentialsOptions;\n try {\n (0, utils_1.assertIdentityPoolIdConfig)(authConfig?.Cognito);\n }\n catch {\n // No identity pool configured, skipping\n return;\n }\n if (!isAuthenticated && !authConfig.Cognito.allowGuestAccess) {\n // TODO(V6): return partial result like Native platforms\n return;\n }\n const { forceRefresh } = getCredentialsOptions;\n const tokenHasChanged = this.hasTokenChanged(tokens);\n const identityId = await (0, IdentityIdProvider_1.cognitoIdentityIdProvider)({\n tokens,\n authConfig: authConfig.Cognito,\n identityIdStore: this._identityIdStore,\n });\n // Clear cached credentials when forceRefresh is true OR the cache token has changed\n if (forceRefresh || tokenHasChanged) {\n this.clearCredentials();\n }\n if (!isAuthenticated) {\n return this.getGuestCredentials(identityId, authConfig.Cognito);\n }\n else {\n (0, types_1.assertIdTokenInAuthTokens)(tokens);\n return this.credsForOIDCTokens(authConfig.Cognito, tokens, identityId);\n }\n }\n async getGuestCredentials(identityId, authConfig) {\n // Return existing in-memory cached credentials only if it exists, is not past it's lifetime and is unauthenticated credentials\n if (this._credentialsAndIdentityId &&\n !this.isPastTTL() &&\n this._credentialsAndIdentityId.isAuthenticatedCreds === false) {\n logger.info('returning stored credentials as they neither past TTL nor expired.');\n return this._credentialsAndIdentityId;\n }\n // Clear to discard if any authenticated credentials are set and start with a clean slate\n this.clearCredentials();\n const region = (0, parsers_1.getRegionFromIdentityPoolId)(authConfig.identityPoolId);\n const getCredentialsForIdentity = (0, core_1.createGetCredentialsForIdentityClient)({\n endpointResolver: (0, factories_1.createCognitoIdentityPoolEndpointResolver)({\n endpointOverride: authConfig.identityPoolEndpoint,\n }),\n });\n // use identityId to obtain guest credentials\n // save credentials in-memory\n // No logins params should be passed for guest creds:\n // https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html\n const clientResult = await getCredentialsForIdentity({ region }, {\n IdentityId: identityId,\n });\n if (clientResult.Credentials &&\n clientResult.Credentials.AccessKeyId &&\n clientResult.Credentials.SecretKey) {\n this._nextCredentialsRefresh = new Date().getTime() + CREDENTIALS_TTL;\n const res = {\n credentials: {\n accessKeyId: clientResult.Credentials.AccessKeyId,\n secretAccessKey: clientResult.Credentials.SecretKey,\n sessionToken: clientResult.Credentials.SessionToken,\n expiration: clientResult.Credentials.Expiration,\n },\n identityId,\n };\n const identityIdRes = clientResult.IdentityId;\n if (identityIdRes) {\n res.identityId = identityIdRes;\n this._identityIdStore.storeIdentityId({\n id: identityIdRes,\n type: 'guest',\n });\n }\n this._credentialsAndIdentityId = {\n ...res,\n isAuthenticatedCreds: false,\n };\n return res;\n }\n else {\n throw new AuthError_1.AuthError({\n name: 'CredentialsNotFoundException',\n message: `Cognito did not respond with either Credentials, AccessKeyId or SecretKey.`,\n });\n }\n }\n async credsForOIDCTokens(authConfig, authTokens, identityId) {\n if (this._credentialsAndIdentityId &&\n !this.isPastTTL() &&\n this._credentialsAndIdentityId.isAuthenticatedCreds === true) {\n logger.debug('returning stored credentials as they neither past TTL nor expired.');\n return this._credentialsAndIdentityId;\n }\n // Clear to discard if any unauthenticated credentials are set and start with a clean slate\n this.clearCredentials();\n const logins = authTokens.idToken\n ? (0, utils_2.formLoginsMap)(authTokens.idToken.toString())\n : {};\n const region = (0, parsers_1.getRegionFromIdentityPoolId)(authConfig.identityPoolId);\n const getCredentialsForIdentity = (0, core_1.createGetCredentialsForIdentityClient)({\n endpointResolver: (0, factories_1.createCognitoIdentityPoolEndpointResolver)({\n endpointOverride: authConfig.identityPoolEndpoint,\n }),\n });\n const clientResult = await getCredentialsForIdentity({ region }, {\n IdentityId: identityId,\n Logins: logins,\n });\n if (clientResult.Credentials &&\n clientResult.Credentials.AccessKeyId &&\n clientResult.Credentials.SecretKey) {\n const res = {\n credentials: {\n accessKeyId: clientResult.Credentials.AccessKeyId,\n secretAccessKey: clientResult.Credentials.SecretKey,\n sessionToken: clientResult.Credentials.SessionToken,\n expiration: clientResult.Credentials.Expiration,\n },\n identityId,\n };\n // Store the credentials in-memory along with the expiration\n this._credentialsAndIdentityId = {\n ...res,\n isAuthenticatedCreds: true,\n associatedIdToken: authTokens.idToken?.toString(),\n };\n this._nextCredentialsRefresh = new Date().getTime() + CREDENTIALS_TTL;\n const identityIdRes = clientResult.IdentityId;\n if (identityIdRes) {\n res.identityId = identityIdRes;\n this._identityIdStore.storeIdentityId({\n id: identityIdRes,\n type: 'primary',\n });\n }\n return res;\n }\n else {\n throw new AuthError_1.AuthError({\n name: 'CredentialsException',\n message: `Cognito did not respond with either Credentials, AccessKeyId or SecretKey.`,\n });\n }\n }\n isPastTTL() {\n return this._nextCredentialsRefresh === undefined\n ? true\n : this._nextCredentialsRefresh <= Date.now();\n }\n hasTokenChanged(tokens) {\n return (!!tokens &&\n !!this._credentialsAndIdentityId?.associatedIdToken &&\n tokens.idToken?.toString() !==\n this._credentialsAndIdentityId.associatedIdToken);\n }\n}\nexports.CognitoAWSCredentialsAndIdentityIdProvider = CognitoAWSCredentialsAndIdentityIdProvider;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,0CAA0C,GAAG,KAAK,CAAC,CAAC;AAC5D,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACzD,MAAM,SAAS,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AACzD,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,oBAAoB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,4BAA4B,CAAC,CAAC;AACtE,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACvC,MAAM,0CAA0C,CAAC;AACjD,IAAI,WAAW,CAAC,eAAe,EAAE;AACj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AAI;AAClB,cAAc,IAAI,CAAC,uBAAuB,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;AACzD,KAAK;AACL,IAAI,eAAe,CAAC,MAAM,EAAE;AAC5B,QAAQ,QAAQ,CAAC,CAAC,MAAM;AACxB,YAAY,CAAC,CAAC,IAAI,CAAC,yBAAyB,EAAE,iBAAiB;AAC/D,YAAY,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE;AACtC,gBAAgB,IAAI,CAAC,yBAAyB,CAAC,iBAAiB,EAAE;AAClE,KAAK;AACL,CAAC;AACD,OAAO,CAAC,0CAA0C,GAAG,0CAA0C;;"}
1
+ {"version":3,"file":"credentialsProvider.js","sources":["../../../../../src/providers/cognito/credentialsProvider/credentialsProvider.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.CognitoAWSCredentialsAndIdentityIdProvider = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst AuthError_1 = require(\"../../../errors/AuthError\");\nconst parsers_1 = require(\"../../../foundation/parsers\");\nconst types_1 = require(\"../utils/types\");\nconst IdentityIdProvider_1 = require(\"./IdentityIdProvider\");\nconst utils_2 = require(\"./utils\");\nconst logger = new core_1.ConsoleLogger('CognitoCredentialsProvider');\nconst CREDENTIALS_TTL = 50 * 60 * 1000; // 50 min, can be modified on config if required in the future\nclass CognitoAWSCredentialsAndIdentityIdProvider {\n constructor(identityIdStore) {\n this._nextCredentialsRefresh = 0;\n this._identityIdStore = identityIdStore;\n }\n async clearCredentialsAndIdentityId() {\n logger.debug('Clearing out credentials and identityId');\n this._credentialsAndIdentityId = undefined;\n await this._identityIdStore.clearIdentityId();\n }\n async clearCredentials() {\n logger.debug('Clearing out in-memory credentials');\n this._credentialsAndIdentityId = undefined;\n }\n async getCredentialsAndIdentityId(getCredentialsOptions) {\n const isAuthenticated = getCredentialsOptions.authenticated;\n const { tokens } = getCredentialsOptions;\n const { authConfig } = getCredentialsOptions;\n try {\n (0, utils_1.assertIdentityPoolIdConfig)(authConfig?.Cognito);\n }\n catch {\n // No identity pool configured, skipping\n return;\n }\n if (!isAuthenticated && !authConfig.Cognito.allowGuestAccess) {\n // TODO(V6): return partial result like Native platforms\n return;\n }\n const { forceRefresh } = getCredentialsOptions;\n const tokenHasChanged = this.hasTokenChanged(tokens);\n const identityId = await (0, IdentityIdProvider_1.cognitoIdentityIdProvider)({\n tokens,\n authConfig: authConfig.Cognito,\n identityIdStore: this._identityIdStore,\n });\n // Clear cached credentials when forceRefresh is true OR the cache token has changed\n if (forceRefresh || tokenHasChanged) {\n this.clearCredentials();\n }\n if (!isAuthenticated) {\n return this.getGuestCredentials(identityId, authConfig.Cognito);\n }\n else {\n (0, types_1.assertIdTokenInAuthTokens)(tokens);\n return this.credsForOIDCTokens(authConfig.Cognito, tokens, identityId);\n }\n }\n async getGuestCredentials(identityId, authConfig) {\n // Return existing in-memory cached credentials only if it exists, is not past it's lifetime and is unauthenticated credentials\n if (this._credentialsAndIdentityId &&\n !this.isPastTTL() &&\n this._credentialsAndIdentityId.isAuthenticatedCreds === false) {\n logger.info('returning stored credentials as they neither past TTL nor expired.');\n return this._credentialsAndIdentityId;\n }\n // Clear to discard if any authenticated credentials are set and start with a clean slate\n this.clearCredentials();\n const region = (0, parsers_1.getRegionFromIdentityPoolId)(authConfig.identityPoolId);\n // use identityId to obtain guest credentials\n // save credentials in-memory\n // No logins params should be passed for guest creds:\n // https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html\n const clientResult = await (0, core_1.getCredentialsForIdentity)({ region }, {\n IdentityId: identityId,\n });\n if (clientResult.Credentials &&\n clientResult.Credentials.AccessKeyId &&\n clientResult.Credentials.SecretKey) {\n this._nextCredentialsRefresh = new Date().getTime() + CREDENTIALS_TTL;\n const res = {\n credentials: {\n accessKeyId: clientResult.Credentials.AccessKeyId,\n secretAccessKey: clientResult.Credentials.SecretKey,\n sessionToken: clientResult.Credentials.SessionToken,\n expiration: clientResult.Credentials.Expiration,\n },\n identityId,\n };\n const identityIdRes = clientResult.IdentityId;\n if (identityIdRes) {\n res.identityId = identityIdRes;\n this._identityIdStore.storeIdentityId({\n id: identityIdRes,\n type: 'guest',\n });\n }\n this._credentialsAndIdentityId = {\n ...res,\n isAuthenticatedCreds: false,\n };\n return res;\n }\n else {\n throw new AuthError_1.AuthError({\n name: 'CredentialsNotFoundException',\n message: `Cognito did not respond with either Credentials, AccessKeyId or SecretKey.`,\n });\n }\n }\n async credsForOIDCTokens(authConfig, authTokens, identityId) {\n if (this._credentialsAndIdentityId &&\n !this.isPastTTL() &&\n this._credentialsAndIdentityId.isAuthenticatedCreds === true) {\n logger.debug('returning stored credentials as they neither past TTL nor expired.');\n return this._credentialsAndIdentityId;\n }\n // Clear to discard if any unauthenticated credentials are set and start with a clean slate\n this.clearCredentials();\n const logins = authTokens.idToken\n ? (0, utils_2.formLoginsMap)(authTokens.idToken.toString())\n : {};\n const region = (0, parsers_1.getRegionFromIdentityPoolId)(authConfig.identityPoolId);\n const clientResult = await (0, core_1.getCredentialsForIdentity)({ region }, {\n IdentityId: identityId,\n Logins: logins,\n });\n if (clientResult.Credentials &&\n clientResult.Credentials.AccessKeyId &&\n clientResult.Credentials.SecretKey) {\n const res = {\n credentials: {\n accessKeyId: clientResult.Credentials.AccessKeyId,\n secretAccessKey: clientResult.Credentials.SecretKey,\n sessionToken: clientResult.Credentials.SessionToken,\n expiration: clientResult.Credentials.Expiration,\n },\n identityId,\n };\n // Store the credentials in-memory along with the expiration\n this._credentialsAndIdentityId = {\n ...res,\n isAuthenticatedCreds: true,\n associatedIdToken: authTokens.idToken?.toString(),\n };\n this._nextCredentialsRefresh = new Date().getTime() + CREDENTIALS_TTL;\n const identityIdRes = clientResult.IdentityId;\n if (identityIdRes) {\n res.identityId = identityIdRes;\n this._identityIdStore.storeIdentityId({\n id: identityIdRes,\n type: 'primary',\n });\n }\n return res;\n }\n else {\n throw new AuthError_1.AuthError({\n name: 'CredentialsException',\n message: `Cognito did not respond with either Credentials, AccessKeyId or SecretKey.`,\n });\n }\n }\n isPastTTL() {\n return this._nextCredentialsRefresh === undefined\n ? true\n : this._nextCredentialsRefresh <= Date.now();\n }\n hasTokenChanged(tokens) {\n return (!!tokens &&\n !!this._credentialsAndIdentityId?.associatedIdToken &&\n tokens.idToken?.toString() !==\n this._credentialsAndIdentityId.associatedIdToken);\n }\n}\nexports.CognitoAWSCredentialsAndIdentityIdProvider = CognitoAWSCredentialsAndIdentityIdProvider;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,0CAA0C,GAAG,KAAK,CAAC,CAAC;AAC5D,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACzD,MAAM,SAAS,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AACzD,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,oBAAoB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,4BAA4B,CAAC,CAAC;AACtE,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACvC,MAAM,0CAA0C,CAAC;AACjD,IAAI,WAAW,CAAC,eAAe,EAAE;AACjC,QAAQ,IAAI,CAAC,uBAAuB,GAAG,CAAC,CA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object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createCognitoIdentityPoolEndpointResolver = exports.createCognitoUserPoolEndpointResolver = void 0;
4
+ exports.createCognitoUserPoolEndpointResolver = void 0;
5
5
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
6
  // SPDX-License-Identifier: Apache-2.0
7
7
  var createCognitoUserPoolEndpointResolver_1 = require("./createCognitoUserPoolEndpointResolver");
8
8
  Object.defineProperty(exports, "createCognitoUserPoolEndpointResolver", { enumerable: true, get: function () { return createCognitoUserPoolEndpointResolver_1.createCognitoUserPoolEndpointResolver; } });
9
- var createCognitoIdentityPoolEndpointResolver_1 = require("./createCognitoIdentityPoolEndpointResolver");
10
- Object.defineProperty(exports, "createCognitoIdentityPoolEndpointResolver", { enumerable: true, get: function () { return createCognitoIdentityPoolEndpointResolver_1.createCognitoIdentityPoolEndpointResolver; } });
11
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../src/providers/cognito/factories/index.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createCognitoIdentityPoolEndpointResolver = exports.createCognitoUserPoolEndpointResolver = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nvar createCognitoUserPoolEndpointResolver_1 = require(\"./createCognitoUserPoolEndpointResolver\");\nObject.defineProperty(exports, \"createCognitoUserPoolEndpointResolver\", { enumerable: true, get: function () { return createCognitoUserPoolEndpointResolver_1.createCognitoUserPoolEndpointResolver; } });\nvar createCognitoIdentityPoolEndpointResolver_1 = require(\"./createCognitoIdentityPoolEndpointResolver\");\nObject.defineProperty(exports, \"createCognitoIdentityPoolEndpointResolver\", { enumerable: true, get: function () { return createCognitoIdentityPoolEndpointResolver_1.createCognitoIdentityPoolEndpointResolver; } });\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,yCAAyC,GAAG,OAAO,CAAC,qCAAqC,GAAG,KAAK,CAAC,CAAC;AAC3G;AACA;AACA,IAAI,uCAAuC,GAAG,OAAO,CAAC,yCAAyC,CAAC,CAAC;AACjG,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,uCAAuC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,uCAAuC,CAAC,qCAAqC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC1M,IAAI,2CAA2C,GAAG,OAAO,CAAC,6CAA6C,CAAC,CAAC;AACzG,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,2CAA2C,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,2CAA2C,CAAC,yCAAyC,CAAC,EAAE,EAAE,CAAC;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/providers/cognito/factories/index.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createCognitoUserPoolEndpointResolver = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nvar createCognitoUserPoolEndpointResolver_1 = require(\"./createCognitoUserPoolEndpointResolver\");\nObject.defineProperty(exports, \"createCognitoUserPoolEndpointResolver\", { enumerable: true, get: function () { return createCognitoUserPoolEndpointResolver_1.createCognitoUserPoolEndpointResolver; } });\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,qCAAqC,GAAG,KAAK,CAAC,CAAC;AACvD;AACA;AACA,IAAI,uCAAuC,GAAG,OAAO,CAAC,yCAAyC,CAAC,CAAC;AACjG,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,uCAAuC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,uCAAuC,CAAC,qCAAqC,CAAC,EAAE,EAAE,CAAC;;"}
@@ -9,7 +9,6 @@ import '../../../../foundation/factories/serviceClients/cognitoIdentityProvider/
9
9
  import '../../../../foundation/factories/serviceClients/cognitoIdentityProvider/constants.mjs';
10
10
  import { createGetUserClient } from '../../../../foundation/factories/serviceClients/cognitoIdentityProvider/createGetUserClient.mjs';
11
11
  import { createCognitoUserPoolEndpointResolver } from '../../factories/createCognitoUserPoolEndpointResolver.mjs';
12
- import '@aws-amplify/core';
13
12
 
14
13
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
15
14
  // SPDX-License-Identifier: Apache-2.0
@@ -1 +1 @@
1
- {"version":3,"file":"fetchUserAttributes.mjs","sources":["../../../../../../src/providers/cognito/apis/internal/fetchUserAttributes.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AuthAction, assertTokenProviderConfig, fetchAuthSession, } from '@aws-amplify/core/internals/utils';\nimport { getRegionFromUserPoolId } from '../../../../foundation/parsers';\nimport { assertAuthTokens } from '../../utils/types';\nimport { toAuthUserAttribute } from '../../utils/apiHelpers';\nimport { getAuthUserAgentValue } from '../../../../utils';\nimport { createGetUserClient } from '../../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nimport { createCognitoUserPoolEndpointResolver } from '../../factories';\nexport const fetchUserAttributes = async (amplify) => {\n const authConfig = amplify.getConfig().Auth?.Cognito;\n assertTokenProviderConfig(authConfig);\n const { userPoolEndpoint, userPoolId } = authConfig;\n const { tokens } = await fetchAuthSession(amplify, {\n forceRefresh: false,\n });\n assertAuthTokens(tokens);\n const getUser = createGetUserClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { UserAttributes } = await getUser({\n region: getRegionFromUserPoolId(userPoolId),\n userAgentValue: getAuthUserAgentValue(AuthAction.FetchUserAttributes),\n }, {\n AccessToken: tokens.accessToken.toString(),\n });\n return toAuthUserAttribute(UserAttributes);\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;AACA;AAQY,MAAC,mBAAmB,GAAG,OAAO,OAAO,KAAK;AACtD,IAAI,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC;AACzD,IAAI,yBAAyB,CAAC,UAAU,CAAC,CAAC;AAC1C,IAAI,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,GAAG,UAAU,CAAC;AACxD,IAAI,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE;AACvD,QAAQ,YAAY,EAAE,KAAK;AAC3B,KAAK,CAAC,CAAC;AACP,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAC7B,IAAI,MAAM,OAAO,GAAG,mBAAmB,CAAC;AACxC,QAAQ,gBAAgB,EAAE,qCAAqC,CAAC;AAChE,YAAY,gBAAgB,EAAE,gBAAgB;AAC9C,SAAS,CAAC;AACV,KAAK,CAAC,CAAC;AACP,IAAI,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,OAAO,CAAC;AAC7C,QAAQ,MAAM,EAAE,uBAAuB,CAAC,UAAU,CAAC;AACnD,QAAQ,cAAc,EAAE,qBAAqB,CAAC,UAAU,CAAC,mBAAmB,CAAC;AAC7E,KAAK,EAAE;AACP,QAAQ,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE;AAClD,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,mBAAmB,CAAC,cAAc,CAAC,CAAC;AAC/C;;;;"}
1
+ {"version":3,"file":"fetchUserAttributes.mjs","sources":["../../../../../../src/providers/cognito/apis/internal/fetchUserAttributes.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AuthAction, assertTokenProviderConfig, fetchAuthSession, } from '@aws-amplify/core/internals/utils';\nimport { getRegionFromUserPoolId } from '../../../../foundation/parsers';\nimport { assertAuthTokens } from '../../utils/types';\nimport { toAuthUserAttribute } from '../../utils/apiHelpers';\nimport { getAuthUserAgentValue } from '../../../../utils';\nimport { createGetUserClient } from '../../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nimport { createCognitoUserPoolEndpointResolver } from '../../factories';\nexport const fetchUserAttributes = async (amplify) => {\n const authConfig = amplify.getConfig().Auth?.Cognito;\n assertTokenProviderConfig(authConfig);\n const { userPoolEndpoint, userPoolId } = authConfig;\n const { tokens } = await fetchAuthSession(amplify, {\n forceRefresh: false,\n });\n assertAuthTokens(tokens);\n const getUser = createGetUserClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { UserAttributes } = await getUser({\n region: getRegionFromUserPoolId(userPoolId),\n userAgentValue: getAuthUserAgentValue(AuthAction.FetchUserAttributes),\n }, {\n AccessToken: tokens.accessToken.toString(),\n });\n return toAuthUserAttribute(UserAttributes);\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;AACA;AAQY,MAAC,mBAAmB,GAAG,OAAO,OAAO,KAAK;AACtD,IAAI,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC;AACzD,IAAI,yBAAyB,CAAC,UAAU,CAAC,CAAC;AAC1C,IAAI,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,GAAG,UAAU,CAAC;AACxD,IAAI,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE;AACvD,QAAQ,YAAY,EAAE,KAAK;AAC3B,KAAK,CAAC,CAAC;AACP,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAC7B,IAAI,MAAM,OAAO,GAAG,mBAAmB,CAAC;AACxC,QAAQ,gBAAgB,EAAE,qCAAqC,CAAC;AAChE,YAAY,gBAAgB,EAAE,gBAAgB;AAC9C,SAAS,CAAC;AACV,KAAK,CAAC,CAAC;AACP,IAAI,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,OAAO,CAAC;AAC7C,QAAQ,MAAM,EAAE,uBAAuB,CAAC,UAAU,CAAC;AACnD,QAAQ,cAAc,EAAE,qBAAqB,CAAC,UAAU,CAAC,mBAAmB,CAAC;AAC7E,KAAK,EAAE;AACP,QAAQ,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE;AAClD,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,mBAAmB,CAAC,cAAc,CAAC,CAAC;AAC/C;;;;"}
@@ -1,9 +1,6 @@
1
- import { ConsoleLogger, createGetIdClient } from '@aws-amplify/core';
1
+ import { ConsoleLogger, getId } from '@aws-amplify/core';
2
2
  import { AuthError } from '../../../errors/AuthError.mjs';
3
3
  import { getRegionFromIdentityPoolId } from '../../../foundation/parsers/regionParsers.mjs';
4
- import '@aws-amplify/core/internals/utils';
5
- import '@aws-amplify/core/internals/aws-client-utils';
6
- import { createCognitoIdentityPoolEndpointResolver } from '../factories/createCognitoIdentityPoolEndpointResolver.mjs';
7
4
  import { formLoginsMap } from './utils.mjs';
8
5
 
9
6
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -61,15 +58,10 @@ async function cognitoIdentityIdProvider({ tokens, authConfig, identityIdStore,
61
58
  async function generateIdentityId(logins, authConfig) {
62
59
  const identityPoolId = authConfig?.identityPoolId;
63
60
  const region = getRegionFromIdentityPoolId(identityPoolId);
64
- const getId = createGetIdClient({
65
- endpointResolver: createCognitoIdentityPoolEndpointResolver({
66
- endpointOverride: authConfig.identityPoolEndpoint,
67
- }),
68
- });
69
61
  // IdentityId is absent so get it using IdentityPoolId with Cognito's GetId API
70
62
  const idResult =
71
63
  // for a first-time user, this will return a brand new identity
72
- // for a returning user, this will retrieve the previous identity associated with the logins
64
+ // for a returning user, this will retrieve the previous identity assocaited with the logins
73
65
  (await getId({
74
66
  region,
75
67
  }, {
@@ -1 +1 @@
1
- {"version":3,"file":"IdentityIdProvider.mjs","sources":["../../../../../src/providers/cognito/credentialsProvider/IdentityIdProvider.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger, createGetIdClient, } from '@aws-amplify/core';\nimport { AuthError } from '../../../errors/AuthError';\nimport { getRegionFromIdentityPoolId } from '../../../foundation/parsers';\nimport { createCognitoIdentityPoolEndpointResolver } from '../factories';\nimport { formLoginsMap } from './utils';\nconst logger = new ConsoleLogger('CognitoIdentityIdProvider');\n/**\n * Provides a Cognito identityId\n *\n * @param tokens - The AuthTokens received after SignIn\n * @returns string\n * @throws configuration exceptions: `InvalidIdentityPoolIdException`\n * - Auth errors that may arise from misconfiguration.\n * @throws service exceptions: {@link GetIdException }\n */\nexport async function cognitoIdentityIdProvider({ tokens, authConfig, identityIdStore, }) {\n identityIdStore.setAuthConfig({ Cognito: authConfig });\n // will return null only if there is no identityId cached or if there is an error retrieving it\n let identityId = await identityIdStore.loadIdentityId();\n // Tokens are available so return primary identityId\n if (tokens) {\n // If there is existing primary identityId in-memory return that\n if (identityId && identityId.type === 'primary') {\n return identityId.id;\n }\n else {\n const logins = tokens.idToken\n ? formLoginsMap(tokens.idToken.toString())\n : {};\n const generatedIdentityId = await generateIdentityId(logins, authConfig);\n if (identityId && identityId.id === generatedIdentityId) {\n logger.debug(`The guest identity ${identityId.id} has become the primary identity.`);\n }\n identityId = {\n id: generatedIdentityId,\n type: 'primary',\n };\n }\n }\n else {\n // If there is existing guest identityId cached return that\n if (identityId && identityId.type === 'guest') {\n return identityId.id;\n }\n else {\n identityId = {\n id: await generateIdentityId({}, authConfig),\n type: 'guest',\n };\n }\n }\n // Store in-memory or local storage depending on guest or primary identityId\n identityIdStore.storeIdentityId(identityId);\n return identityId.id;\n}\nasync function generateIdentityId(logins, authConfig) {\n const identityPoolId = authConfig?.identityPoolId;\n const region = getRegionFromIdentityPoolId(identityPoolId);\n const getId = createGetIdClient({\n endpointResolver: createCognitoIdentityPoolEndpointResolver({\n endpointOverride: authConfig.identityPoolEndpoint,\n }),\n });\n // IdentityId is absent so get it using IdentityPoolId with Cognito's GetId API\n const idResult = \n // for a first-time user, this will return a brand new identity\n // for a returning user, this will retrieve the previous identity associated with the logins\n (await getId({\n region,\n }, {\n IdentityPoolId: identityPoolId,\n Logins: logins,\n })).IdentityId;\n if (!idResult) {\n throw new AuthError({\n name: 'GetIdResponseException',\n message: 'Received undefined response from getId operation',\n recoverySuggestion: 'Make sure to pass a valid identityPoolId in the configuration.',\n });\n }\n return idResult;\n}\n"],"names":[],"mappings":";;;;;;;;AAAA;AACA;AAMA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,2BAA2B,CAAC,CAAC;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,yBAAyB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,GAAG,EAAE;AAC1F,IAAI,eAAe,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;AAC3D;AACA,IAAI,IAAI,UAAU,GAAG,MAAM,eAAe,CAAC,cAAc,EAAE,CAAC;AAC5D;AACA,IAAI,IAAI,MAAM,EAAE;AAChB;AACA,QAAQ,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE;AACzD,YAAY,OAAO,UAAU,CAAC,EAAE,CAAC;AACjC,SAAS;AACT,aAAa;AACb,YAAY,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO;AACzC,kBAAkB,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC1D,kBAAkB,EAAE,CAAC;AACrB,YAAY,MAAM,mBAAmB,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE,UAA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c,EAAE,cAAc;AACtC,QAAQ,MAAM,EAAE,MAAM;AACtB,KAAK,CAAC,EAAE,UAAU,CAAC;AACnB,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB,QAAQ,MAAM,IAAI,SAAS,CAAC;AAC5B,YAAY,IAAI,EAAE,wBAAwB;AAC1C,YAAY,OAAO,EAAE,kDAAkD;AACvE,YAAY,kBAAkB,EAAE,gEAAgE;AAChG,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,QAAQ,CAAC;AACpB;;;;"}
1
+ {"version":3,"file":"IdentityIdProvider.mjs","sources":["../../../../../src/providers/cognito/credentialsProvider/IdentityIdProvider.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger, getId } from '@aws-amplify/core';\nimport { AuthError } from '../../../errors/AuthError';\nimport { getRegionFromIdentityPoolId } from '../../../foundation/parsers';\nimport { formLoginsMap } from './utils';\nconst logger = new ConsoleLogger('CognitoIdentityIdProvider');\n/**\n * Provides a Cognito identityId\n *\n * @param tokens - The AuthTokens received after SignIn\n * @returns string\n * @throws configuration exceptions: `InvalidIdentityPoolIdException`\n * - Auth errors that may arise from misconfiguration.\n * @throws service exceptions: {@link GetIdException }\n */\nexport async function cognitoIdentityIdProvider({ tokens, authConfig, identityIdStore, }) {\n identityIdStore.setAuthConfig({ Cognito: authConfig });\n // will return null only if there is no identityId cached or if there is an error retrieving it\n let identityId = await identityIdStore.loadIdentityId();\n // Tokens are available so return primary identityId\n if (tokens) {\n // If there is existing primary identityId in-memory return that\n if (identityId && identityId.type === 'primary') {\n return identityId.id;\n }\n else {\n const logins = tokens.idToken\n ? formLoginsMap(tokens.idToken.toString())\n : {};\n const generatedIdentityId = await generateIdentityId(logins, authConfig);\n if (identityId && identityId.id === generatedIdentityId) {\n logger.debug(`The guest identity ${identityId.id} has become the primary identity.`);\n }\n identityId = {\n id: generatedIdentityId,\n type: 'primary',\n };\n }\n }\n else {\n // If there is existing guest identityId cached return that\n if (identityId && identityId.type === 'guest') {\n return identityId.id;\n }\n else {\n identityId = {\n id: await generateIdentityId({}, authConfig),\n type: 'guest',\n };\n }\n }\n // Store in-memory or local storage depending on guest or primary identityId\n identityIdStore.storeIdentityId(identityId);\n return identityId.id;\n}\nasync function generateIdentityId(logins, authConfig) {\n const identityPoolId = authConfig?.identityPoolId;\n const region = getRegionFromIdentityPoolId(identityPoolId);\n // IdentityId is absent so get it using IdentityPoolId with Cognito's GetId API\n const idResult = \n // for a first-time user, this will return a brand new identity\n // for a returning user, this will retrieve the previous identity assocaited with the logins\n (await getId({\n region,\n }, {\n IdentityPoolId: identityPoolId,\n Logins: logins,\n })).IdentityId;\n if (!idResult) {\n throw new AuthError({\n name: 'GetIdResponseException',\n message: 'Received undefined response from getId operation',\n recoverySuggestion: 'Make sure to pass a valid identityPoolId in the configuration.',\n });\n }\n return idResult;\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAKA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,2BAA2B,CAAC,CAAC;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,yBAAyB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,GAAG,EAAE;AAC1F,IAAI,eAAe,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;AAC3D;AACA,IAAI,IAAI,UAAU,GAAG,MAAM,eAAe,CAAC,cAAc,EAAE,CAAC;AAC5D;AACA,IAAI,IAAI,MAAM,EAAE;AAChB;AACA,QAAQ,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE;AACzD,YAAY,OAAO,UAAU,CAAC,EAAE,CAAC;AACjC,SAAS;AACT,aAAa;AACb,YAAY,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO;AACzC,kBAAkB,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,E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E,UAAU,CAAC;AACnB,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB,QAAQ,MAAM,IAAI,SAAS,CAAC;AAC5B,YAAY,IAAI,EAAE,wBAAwB;AAC1C,YAAY,OAAO,EAAE,kDAAkD;AACvE,YAAY,kBAAkB,EAAE,gEAAgE;AAChG,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,QAAQ,CAAC;AACpB;;;;"}
@@ -1,10 +1,8 @@
1
- import { ConsoleLogger, createGetCredentialsForIdentityClient } from '@aws-amplify/core';
1
+ import { ConsoleLogger, getCredentialsForIdentity } from '@aws-amplify/core';
2
2
  import { assertIdentityPoolIdConfig } from '@aws-amplify/core/internals/utils';
3
3
  import { AuthError } from '../../../errors/AuthError.mjs';
4
4
  import { getRegionFromIdentityPoolId } from '../../../foundation/parsers/regionParsers.mjs';
5
5
  import { assertIdTokenInAuthTokens } from '../utils/types.mjs';
6
- import '@aws-amplify/core/internals/aws-client-utils';
7
- import { createCognitoIdentityPoolEndpointResolver } from '../factories/createCognitoIdentityPoolEndpointResolver.mjs';
8
6
  import { cognitoIdentityIdProvider } from './IdentityIdProvider.mjs';
9
7
  import { formLoginsMap } from './utils.mjs';
10
8
 
@@ -71,11 +69,6 @@ class CognitoAWSCredentialsAndIdentityIdProvider {
71
69
  // Clear to discard if any authenticated credentials are set and start with a clean slate
72
70
  this.clearCredentials();
73
71
  const region = getRegionFromIdentityPoolId(authConfig.identityPoolId);
74
- const getCredentialsForIdentity = createGetCredentialsForIdentityClient({
75
- endpointResolver: createCognitoIdentityPoolEndpointResolver({
76
- endpointOverride: authConfig.identityPoolEndpoint,
77
- }),
78
- });
79
72
  // use identityId to obtain guest credentials
80
73
  // save credentials in-memory
81
74
  // No logins params should be passed for guest creds:
@@ -130,11 +123,6 @@ class CognitoAWSCredentialsAndIdentityIdProvider {
130
123
  ? formLoginsMap(authTokens.idToken.toString())
131
124
  : {};
132
125
  const region = getRegionFromIdentityPoolId(authConfig.identityPoolId);
133
- const getCredentialsForIdentity = createGetCredentialsForIdentityClient({
134
- endpointResolver: createCognitoIdentityPoolEndpointResolver({
135
- endpointOverride: authConfig.identityPoolEndpoint,
136
- }),
137
- });
138
126
  const clientResult = await getCredentialsForIdentity({ region }, {
139
127
  IdentityId: identityId,
140
128
  Logins: logins,
@@ -1 +1 @@
1
- {"version":3,"file":"credentialsProvider.mjs","sources":["../../../../../src/providers/cognito/credentialsProvider/credentialsProvider.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger, createGetCredentialsForIdentityClient, } from '@aws-amplify/core';\nimport { assertIdentityPoolIdConfig, } from '@aws-amplify/core/internals/utils';\nimport { AuthError } from '../../../errors/AuthError';\nimport { getRegionFromIdentityPoolId } from '../../../foundation/parsers';\nimport { assertIdTokenInAuthTokens } from '../utils/types';\nimport { createCognitoIdentityPoolEndpointResolver } from '../factories';\nimport { cognitoIdentityIdProvider } from './IdentityIdProvider';\nimport { formLoginsMap } from './utils';\nconst logger = new ConsoleLogger('CognitoCredentialsProvider');\nconst CREDENTIALS_TTL = 50 * 60 * 1000; // 50 min, can be modified on config if required in the future\nexport class CognitoAWSCredentialsAndIdentityIdProvider {\n constructor(identityIdStore) {\n this._nextCredentialsRefresh = 0;\n this._identityIdStore = identityIdStore;\n }\n async clearCredentialsAndIdentityId() {\n logger.debug('Clearing out credentials and identityId');\n this._credentialsAndIdentityId = undefined;\n await this._identityIdStore.clearIdentityId();\n }\n async clearCredentials() {\n logger.debug('Clearing out in-memory credentials');\n this._credentialsAndIdentityId = undefined;\n }\n async getCredentialsAndIdentityId(getCredentialsOptions) {\n const isAuthenticated = getCredentialsOptions.authenticated;\n const { tokens } = getCredentialsOptions;\n const { authConfig } = getCredentialsOptions;\n try {\n assertIdentityPoolIdConfig(authConfig?.Cognito);\n }\n catch {\n // No identity pool configured, skipping\n return;\n }\n if (!isAuthenticated && !authConfig.Cognito.allowGuestAccess) {\n // TODO(V6): return partial result like Native platforms\n return;\n }\n const { forceRefresh } = getCredentialsOptions;\n const tokenHasChanged = this.hasTokenChanged(tokens);\n const identityId = await cognitoIdentityIdProvider({\n tokens,\n authConfig: authConfig.Cognito,\n identityIdStore: this._identityIdStore,\n });\n // Clear cached credentials when forceRefresh is true OR the cache token has changed\n if (forceRefresh || tokenHasChanged) {\n this.clearCredentials();\n }\n if (!isAuthenticated) {\n return this.getGuestCredentials(identityId, authConfig.Cognito);\n }\n else {\n assertIdTokenInAuthTokens(tokens);\n return this.credsForOIDCTokens(authConfig.Cognito, tokens, identityId);\n }\n }\n async getGuestCredentials(identityId, authConfig) {\n // Return existing in-memory cached credentials only if it exists, is not past it's lifetime and is unauthenticated credentials\n if (this._credentialsAndIdentityId &&\n !this.isPastTTL() &&\n this._credentialsAndIdentityId.isAuthenticatedCreds === false) {\n logger.info('returning stored credentials as they neither past TTL nor expired.');\n return this._credentialsAndIdentityId;\n }\n // Clear to discard if any authenticated credentials are set and start with a clean slate\n this.clearCredentials();\n const region = getRegionFromIdentityPoolId(authConfig.identityPoolId);\n const getCredentialsForIdentity = createGetCredentialsForIdentityClient({\n endpointResolver: createCognitoIdentityPoolEndpointResolver({\n endpointOverride: authConfig.identityPoolEndpoint,\n }),\n });\n // use identityId to obtain guest credentials\n // save credentials in-memory\n // No logins params should be passed for guest creds:\n // https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html\n const clientResult = await getCredentialsForIdentity({ region }, {\n IdentityId: identityId,\n });\n if (clientResult.Credentials &&\n clientResult.Credentials.AccessKeyId &&\n clientResult.Credentials.SecretKey) {\n this._nextCredentialsRefresh = new Date().getTime() + CREDENTIALS_TTL;\n const res = {\n credentials: {\n accessKeyId: clientResult.Credentials.AccessKeyId,\n secretAccessKey: clientResult.Credentials.SecretKey,\n sessionToken: clientResult.Credentials.SessionToken,\n expiration: clientResult.Credentials.Expiration,\n },\n identityId,\n };\n const identityIdRes = clientResult.IdentityId;\n if (identityIdRes) {\n res.identityId = identityIdRes;\n this._identityIdStore.storeIdentityId({\n id: identityIdRes,\n type: 'guest',\n });\n }\n this._credentialsAndIdentityId = {\n ...res,\n isAuthenticatedCreds: false,\n };\n return res;\n }\n else {\n throw new AuthError({\n name: 'CredentialsNotFoundException',\n message: `Cognito did not respond with either Credentials, AccessKeyId or SecretKey.`,\n });\n }\n }\n async credsForOIDCTokens(authConfig, authTokens, identityId) {\n if (this._credentialsAndIdentityId &&\n !this.isPastTTL() &&\n this._credentialsAndIdentityId.isAuthenticatedCreds === true) {\n logger.debug('returning stored credentials as they neither past TTL nor expired.');\n return this._credentialsAndIdentityId;\n }\n // Clear to discard if any unauthenticated credentials are set and start with a clean slate\n this.clearCredentials();\n const logins = authTokens.idToken\n ? formLoginsMap(authTokens.idToken.toString())\n : {};\n const region = getRegionFromIdentityPoolId(authConfig.identityPoolId);\n const getCredentialsForIdentity = createGetCredentialsForIdentityClient({\n endpointResolver: createCognitoIdentityPoolEndpointResolver({\n endpointOverride: authConfig.identityPoolEndpoint,\n }),\n });\n const clientResult = await getCredentialsForIdentity({ region }, {\n IdentityId: identityId,\n Logins: logins,\n });\n if (clientResult.Credentials &&\n clientResult.Credentials.AccessKeyId &&\n clientResult.Credentials.SecretKey) {\n const res = {\n credentials: {\n accessKeyId: clientResult.Credentials.AccessKeyId,\n secretAccessKey: clientResult.Credentials.SecretKey,\n sessionToken: clientResult.Credentials.SessionToken,\n expiration: clientResult.Credentials.Expiration,\n },\n identityId,\n };\n // Store the credentials in-memory along with the expiration\n this._credentialsAndIdentityId = {\n ...res,\n isAuthenticatedCreds: true,\n associatedIdToken: authTokens.idToken?.toString(),\n };\n this._nextCredentialsRefresh = new Date().getTime() + CREDENTIALS_TTL;\n const identityIdRes = clientResult.IdentityId;\n if (identityIdRes) {\n res.identityId = identityIdRes;\n this._identityIdStore.storeIdentityId({\n id: identityIdRes,\n type: 'primary',\n });\n }\n return res;\n }\n else {\n throw new AuthError({\n name: 'CredentialsException',\n message: `Cognito did not respond with either Credentials, AccessKeyId or SecretKey.`,\n });\n }\n }\n isPastTTL() {\n return this._nextCredentialsRefresh === undefined\n ? true\n : this._nextCredentialsRefresh <= Date.now();\n }\n hasTokenChanged(tokens) {\n return (!!tokens &&\n !!this._credentialsAndIdentityId?.associatedIdToken &&\n tokens.idToken?.toString() !==\n this._credentialsAndIdentityId.associatedIdToken);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AASA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,4BAA4B,CAAC,CAAC;AAC/D,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAChC,MAAM,0CAA0C,CAAC;AACxD,IAAI,WAAW,CAAC,eAAe,EAAE;AACjC,QAAQ,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;AACzC,QAAQ,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;AAChD,KAAK;AACL,IAAI,MAAM,6BAA6B,GAAG;AAC1C,QAAQ,MAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;AAChE,QAAQ,IAAI,CAAC,yBAAyB,GAAG,SAAS,CAAC;AACnD,QAAQ,MAAM,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,CAAC;AACtD,KAAK;AACL,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;AAC3D,QAAQ,IAAI,CAAC,yBAAyB,GAAG,SAAS,CAAC;AACnD,KAAK;AACL,IAAI,MAAM,2BAA2B,CAAC,qBAAqB,EAAE;AAC7D,QAAQ,MAAM,eAAe,GAAG,qBAAqB,CAAC,aAAa,CAAC;AACpE,QAAQ,MAAM,EAAE,MAAM,EAAE,GAAG,qBAAqB,CAAC;AACjD,QAAQ,MAAM,EAAE,UAAU,EAAE,GAAG,qBAAqB,CAAC;AACrD,QAAQ,IAAI;AACZ,YAAY,0B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ACvB,SAAS;AACT,aAAa;AACb,YAAY,MAAM,IAAI,SAAS,CAAC;AAChC,gBAAgB,IAAI,EAAE,sBAAsB;AAC5C,gBAAgB,OAAO,EAAE,CAAC,0EAA0E,CAAC;AACrG,aAAa,CAAC,CAAC;AACf,SAAS;AACT,KAAK;AACL,IAAI,SAAS,GAAG;AAChB,QAAQ,OAAO,IAAI,CAAC,uBAAuB,KAAK,SAAS;AACzD,cAAc,IAAI;AAClB,cAAc,IAAI,CAAC,uBAAuB,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;AACzD,KAAK;AACL,IAAI,eAAe,CAAC,MAAM,EAAE;AAC5B,QAAQ,QAAQ,CAAC,CAAC,MAAM;AACxB,YAAY,CAAC,CAAC,IAAI,CAAC,yBAAyB,EAAE,iBAAiB;AAC/D,YAAY,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE;AACtC,gBAAgB,IAAI,CAAC,yBAAyB,CAAC,iBAAiB,EAAE;AAClE,KAAK;AACL;;;;"}
1
+ {"version":3,"file":"credentialsProvider.mjs","sources":["../../../../../src/providers/cognito/credentialsProvider/credentialsProvider.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger, getCredentialsForIdentity, } from '@aws-amplify/core';\nimport { assertIdentityPoolIdConfig, } from '@aws-amplify/core/internals/utils';\nimport { AuthError } from '../../../errors/AuthError';\nimport { getRegionFromIdentityPoolId } from '../../../foundation/parsers';\nimport { assertIdTokenInAuthTokens } from '../utils/types';\nimport { cognitoIdentityIdProvider } from './IdentityIdProvider';\nimport { formLoginsMap } from './utils';\nconst logger = new ConsoleLogger('CognitoCredentialsProvider');\nconst CREDENTIALS_TTL = 50 * 60 * 1000; // 50 min, can be modified on config if required in the future\nexport class CognitoAWSCredentialsAndIdentityIdProvider {\n constructor(identityIdStore) {\n this._nextCredentialsRefresh = 0;\n this._identityIdStore = identityIdStore;\n }\n async clearCredentialsAndIdentityId() {\n logger.debug('Clearing out credentials and identityId');\n this._credentialsAndIdentityId = undefined;\n await this._identityIdStore.clearIdentityId();\n }\n async clearCredentials() {\n logger.debug('Clearing out in-memory credentials');\n this._credentialsAndIdentityId = undefined;\n }\n async getCredentialsAndIdentityId(getCredentialsOptions) {\n const isAuthenticated = getCredentialsOptions.authenticated;\n const { tokens } = getCredentialsOptions;\n const { authConfig } = getCredentialsOptions;\n try {\n assertIdentityPoolIdConfig(authConfig?.Cognito);\n }\n catch {\n // No identity pool configured, skipping\n return;\n }\n if (!isAuthenticated && !authConfig.Cognito.allowGuestAccess) {\n // TODO(V6): return partial result like Native platforms\n return;\n }\n const { forceRefresh } = getCredentialsOptions;\n const tokenHasChanged = this.hasTokenChanged(tokens);\n const identityId = await cognitoIdentityIdProvider({\n tokens,\n authConfig: authConfig.Cognito,\n identityIdStore: this._identityIdStore,\n });\n // Clear cached credentials when forceRefresh is true OR the cache token has changed\n if (forceRefresh || tokenHasChanged) {\n this.clearCredentials();\n }\n if (!isAuthenticated) {\n return this.getGuestCredentials(identityId, authConfig.Cognito);\n }\n else {\n assertIdTokenInAuthTokens(tokens);\n return this.credsForOIDCTokens(authConfig.Cognito, tokens, identityId);\n }\n }\n async getGuestCredentials(identityId, authConfig) {\n // Return existing in-memory cached credentials only if it exists, is not past it's lifetime and is unauthenticated credentials\n if (this._credentialsAndIdentityId &&\n !this.isPastTTL() &&\n this._credentialsAndIdentityId.isAuthenticatedCreds === false) {\n logger.info('returning stored credentials as they neither past TTL nor expired.');\n return this._credentialsAndIdentityId;\n }\n // Clear to discard if any authenticated credentials are set and start with a clean slate\n this.clearCredentials();\n const region = getRegionFromIdentityPoolId(authConfig.identityPoolId);\n // use identityId to obtain guest credentials\n // save credentials in-memory\n // No logins params should be passed for guest creds:\n // https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html\n const clientResult = await getCredentialsForIdentity({ region }, {\n IdentityId: identityId,\n });\n if (clientResult.Credentials &&\n clientResult.Credentials.AccessKeyId &&\n clientResult.Credentials.SecretKey) {\n this._nextCredentialsRefresh = new Date().getTime() + CREDENTIALS_TTL;\n const res = {\n credentials: {\n accessKeyId: clientResult.Credentials.AccessKeyId,\n secretAccessKey: clientResult.Credentials.SecretKey,\n sessionToken: clientResult.Credentials.SessionToken,\n expiration: clientResult.Credentials.Expiration,\n },\n identityId,\n };\n const identityIdRes = clientResult.IdentityId;\n if (identityIdRes) {\n res.identityId = identityIdRes;\n this._identityIdStore.storeIdentityId({\n id: identityIdRes,\n type: 'guest',\n });\n }\n this._credentialsAndIdentityId = {\n ...res,\n isAuthenticatedCreds: false,\n };\n return res;\n }\n else {\n throw new AuthError({\n name: 'CredentialsNotFoundException',\n message: `Cognito did not respond with either Credentials, AccessKeyId or SecretKey.`,\n });\n }\n }\n async credsForOIDCTokens(authConfig, authTokens, identityId) {\n if (this._credentialsAndIdentityId &&\n !this.isPastTTL() &&\n this._credentialsAndIdentityId.isAuthenticatedCreds === true) {\n logger.debug('returning stored credentials as they neither past TTL nor expired.');\n return this._credentialsAndIdentityId;\n }\n // Clear to discard if any unauthenticated credentials are set and start with a clean slate\n this.clearCredentials();\n const logins = authTokens.idToken\n ? formLoginsMap(authTokens.idToken.toString())\n : {};\n const region = getRegionFromIdentityPoolId(authConfig.identityPoolId);\n const clientResult = await getCredentialsForIdentity({ region }, {\n IdentityId: identityId,\n Logins: logins,\n });\n if (clientResult.Credentials &&\n clientResult.Credentials.AccessKeyId &&\n clientResult.Credentials.SecretKey) {\n const res = {\n credentials: {\n accessKeyId: clientResult.Credentials.AccessKeyId,\n secretAccessKey: clientResult.Credentials.SecretKey,\n sessionToken: clientResult.Credentials.SessionToken,\n expiration: clientResult.Credentials.Expiration,\n },\n identityId,\n };\n // Store the credentials in-memory along with the expiration\n this._credentialsAndIdentityId = {\n ...res,\n isAuthenticatedCreds: true,\n associatedIdToken: authTokens.idToken?.toString(),\n };\n this._nextCredentialsRefresh = new Date().getTime() + CREDENTIALS_TTL;\n const identityIdRes = clientResult.IdentityId;\n if (identityIdRes) {\n res.identityId = identityIdRes;\n this._identityIdStore.storeIdentityId({\n id: identityIdRes,\n type: 'primary',\n });\n }\n return res;\n }\n else {\n throw new AuthError({\n name: 'CredentialsException',\n message: `Cognito did not respond with either Credentials, AccessKeyId or SecretKey.`,\n });\n }\n }\n isPastTTL() {\n return this._nextCredentialsRefresh === undefined\n ? true\n : this._nextCredentialsRefresh <= Date.now();\n }\n hasTokenChanged(tokens) {\n return (!!tokens &&\n !!this._credentialsAndIdentityId?.associatedIdToken &&\n tokens.idToken?.toString() !==\n this._credentialsAndIdentityId.associatedIdToken);\n }\n}\n"],"names":[],"mappings":";;;;;;;;AAAA;AACA;AAQA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,4BAA4B,CAAC,CAAC;AAC/D,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAChC,MAAM,0CAA0C,CAAC;AACxD,IAAI,WAAW,CAAC,eAAe,EAAE;AACjC,QAAQ,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;AACzC,QAAQ,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;AAChD,KAAK;AACL,IAAI,MAAM,6BAA6B,GAAG;AAC1C,QAAQ,MAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;AAChE,QAAQ,IAAI,CAAC,yBAAyB,GAAG,SAAS,CAAC;AACnD,QAAQ,MAAM,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,CAAC;AACtD,KAAK;AACL,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;AAC3D,QAAQ,IAAI,CAAC,yBAAyB,GAAG,SAAS,CAAC;AACnD,KAAK;AACL,IAAI,MAAM,2BAA2B,CAAC,qBAAqB,EAAE;AAC7D,QAAQ,MAAM,eAAe,GAAG,qBAAqB,CAAC,aAAa,CAAC;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;AAChB,QAAQ,OAAO,IAAI,CAAC,uBAAuB,KAAK,SAAS;AACzD,cAAc,IAAI;AAClB,cAAc,IAAI,CAAC,uBAAuB,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;AACzD,KAAK;AACL,IAAI,eAAe,CAAC,MAAM,EAAE;AAC5B,QAAQ,QAAQ,CAAC,CAAC,MAAM;AACxB,YAAY,CAAC,CAAC,IAAI,CAAC,yBAAyB,EAAE,iBAAiB;AAC/D,YAAY,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE;AACtC,gBAAgB,IAAI,CAAC,yBAAyB,CAAC,iBAAiB,EAAE;AAClE,KAAK;AACL;;;;"}
@@ -1,2 +1 @@
1
1
  export { createCognitoUserPoolEndpointResolver } from './createCognitoUserPoolEndpointResolver';
2
- export { createCognitoIdentityPoolEndpointResolver } from './createCognitoIdentityPoolEndpointResolver';
@@ -1,3 +1,2 @@
1
1
  export { createCognitoUserPoolEndpointResolver } from './createCognitoUserPoolEndpointResolver.mjs';
2
- export { createCognitoIdentityPoolEndpointResolver } from './createCognitoIdentityPoolEndpointResolver.mjs';
3
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -8,7 +8,6 @@ import '../../../foundation/factories/serviceClients/cognitoIdentityProvider/sha
8
8
  import '@aws-amplify/core/internals/aws-client-utils';
9
9
  import '../../../foundation/factories/serviceClients/cognitoIdentityProvider/constants.mjs';
10
10
  import { createCognitoUserPoolEndpointResolver } from '../factories/createCognitoUserPoolEndpointResolver.mjs';
11
- import '@aws-amplify/core';
12
11
  import { getUserContextData } from './userContextData.mjs';
13
12
 
14
13
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -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 { createInitiateAuthClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nimport { createCognitoUserPoolEndpointResolver } from '../factories';\nimport { getUserContextData } from './userContextData';\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 refreshTokenString = tokens.refreshToken;\n const AuthParameters = {\n REFRESH_TOKEN: refreshTokenString,\n };\n if (tokens.deviceMetadata?.deviceKey) {\n AuthParameters.DEVICE_KEY = tokens.deviceMetadata.deviceKey;\n }\n const UserContextData = getUserContextData({\n username,\n userPoolId,\n userPoolClientId,\n });\n const initiateAuth = createInitiateAuthClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { AuthenticationResult } = await initiateAuth({ region }, {\n ClientId: userPoolClientId,\n AuthFlow: 'REFRESH_TOKEN_AUTH',\n AuthParameters,\n UserContextData,\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: refreshTokenString,\n username,\n };\n};\nexport const refreshAuthTokens = deDupeAsyncFunction(refreshAuthTokensFunction);\nexport const refreshAuthTokensWithoutDedupe = refreshAuthTokensFunction;\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;AACA;AAQA,MAAM,yBAAyB,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAG,KAAK;AAC/E,IAAI,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AACnD,IAAI,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC;AAClF,IAAI,MAAM,MAAM,GAAG,uBAAuB,CAAC,UAAU,CAAC,CAAC;AACvD,IAAI,gCAAgC,CAAC,MAAM,CAAC,CAAC;AAC7C,IAAI,MAAM,kBAAkB,GAAG,MAAM,CAAC,YAAY,CAAC;AACnD,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ,aAAa,EAAE,kBAAkB;AACzC,KAAK,CAAC;AACN,IAAI,IAAI,MAAM,CAAC,cAAc,EAAE,SAAS,EAAE;AAC1C,QAAQ,cAAc,CAAC,UAAU,GAAG,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC;AACpE,KAAK;AACL,IAAI,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAC/C,QAAQ,QAAQ;AAChB,QAAQ,UAAU;AAClB,QAAQ,gBAAgB;AACxB,KAAK,CAAC,CAAC;AACP,IAAI,MAAM,YAAY,GAAG,wBAAwB,CAAC;AAClD,QAAQ,gBAAgB,EAAE,qCAAqC,CAAC;AAChE,YAAY,gBAAgB,EAAE,gBAAgB;AAC9C,SAAS,CAAC;AACV,KAAK,CAAC,CAAC;AACP,IAAI,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE;AACpE,QAAQ,QAAQ,EAAE,gBAAgB;AAClC,QAAQ,QAAQ,EAAE,oBAAoB;AACtC,QAAQ,cAAc;AACtB,QAAQ,eAAe;AACvB,KAAK,CAAC,CAAC;AACP,IAAI,MAAM,WAAW,GAAG,SAAS,CAAC,oBAAoB,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC;AAC3E,IAAI,MAAM,OAAO,GAAG,oBAAoB,EAAE,OAAO;AACjD,UAAU,SAAS,CAAC,oBAAoB,CAAC,OAAO,CAAC;AACjD,UAAU,SAAS,CAAC;AACpB,IAAI,MAAM,EAAE,GAAG,EAAE,GAAG,WAAW,CAAC,OAAO,CAAC;AACxC;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,CAAC;AACX,KAAK;AACL,IAAI,MAAM,UAAU,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;AACzD,IAAI,OAAO;AACX,QAAQ,WAAW;AACnB,QAAQ,OAAO;AACf,QAAQ,UAAU;AAClB,QAAQ,YAAY,EAAE,kBAAkB;AACxC,QAAQ,QAAQ;AAChB,KAAK,CAAC;AACN,CAAC,CAAC;AACU,MAAC,iBAAiB,GAAG,mBAAmB,CAAC,yBAAyB,EAAE;AACpE,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 { createInitiateAuthClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nimport { createCognitoUserPoolEndpointResolver } from '../factories';\nimport { getUserContextData } from './userContextData';\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 refreshTokenString = tokens.refreshToken;\n const AuthParameters = {\n REFRESH_TOKEN: refreshTokenString,\n };\n if (tokens.deviceMetadata?.deviceKey) {\n AuthParameters.DEVICE_KEY = tokens.deviceMetadata.deviceKey;\n }\n const UserContextData = getUserContextData({\n username,\n userPoolId,\n userPoolClientId,\n });\n const initiateAuth = createInitiateAuthClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { AuthenticationResult } = await initiateAuth({ region }, {\n ClientId: userPoolClientId,\n AuthFlow: 'REFRESH_TOKEN_AUTH',\n AuthParameters,\n UserContextData,\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: refreshTokenString,\n username,\n };\n};\nexport const refreshAuthTokens = deDupeAsyncFunction(refreshAuthTokensFunction);\nexport const refreshAuthTokensWithoutDedupe = refreshAuthTokensFunction;\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;AACA;AAQA,MAAM,yBAAyB,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAG,KAAK;AAC/E,IAAI,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AACnD,IAAI,MAAM,EAAE,UAA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AAO,CAAC;AACxC;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,CAAC;AACX,KAAK;AACL,IAAI,MAAM,UAAU,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;AACzD,IAAI,OAAO;AACX,QAAQ,WAAW;AACnB,QAAQ,OAAO;AACf,QAAQ,UAAU;AAClB,QAAQ,YAAY,EAAE,kBAAkB;AACxC,QAAQ,QAAQ;AAChB,KAAK,CAAC;AACN,CAAC,CAAC;AACU,MAAC,iBAAiB,GAAG,mBAAmB,CAAC,yBAAyB,EAAE;AACpE,MAAC,8BAA8B,GAAG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/auth",
3
- "version": "6.5.4-local-stack.0aa9031.0+0aa9031",
3
+ "version": "6.5.4-next-15.7992a88.0+7992a88",
4
4
  "description": "Auth category of aws-amplify",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -94,13 +94,13 @@
94
94
  "tslib": "^2.5.0"
95
95
  },
96
96
  "peerDependencies": {
97
- "@aws-amplify/core": "6.4.7-local-stack.0aa9031.0+0aa9031"
97
+ "@aws-amplify/core": "6.4.7-next-15.7992a88.0+7992a88"
98
98
  },
99
99
  "devDependencies": {
100
- "@aws-amplify/core": "6.4.7-local-stack.0aa9031.0+0aa9031",
101
- "@aws-amplify/react-native": "1.1.7-local-stack.0aa9031.0+0aa9031",
100
+ "@aws-amplify/core": "6.4.7-next-15.7992a88.0+7992a88",
101
+ "@aws-amplify/react-native": "1.1.7-next-15.7992a88.0+7992a88",
102
102
  "@jest/test-sequencer": "^29.7.0",
103
103
  "typescript": "5.0.2"
104
104
  },
105
- "gitHead": "0aa903169067c0aa1d47d4a019c66af0174fd123"
105
+ "gitHead": "7992a886d96b76abf37560b7296ea75d4ea9ef29"
106
106
  }
@@ -1,18 +1,12 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import {
5
- AuthTokens,
6
- ConsoleLogger,
7
- Identity,
8
- createGetIdClient,
9
- } from '@aws-amplify/core';
4
+ import { AuthTokens, ConsoleLogger, Identity, getId } from '@aws-amplify/core';
10
5
  import { CognitoIdentityPoolConfig } from '@aws-amplify/core/internals/utils';
11
6
 
12
7
  import { AuthError } from '../../../errors/AuthError';
13
8
  import { getRegionFromIdentityPoolId } from '../../../foundation/parsers';
14
9
  import { GetIdException } from '../types/errors';
15
- import { createCognitoIdentityPoolEndpointResolver } from '../factories';
16
10
 
17
11
  import { IdentityIdStore } from './types';
18
12
  import { formLoginsMap } from './utils';
@@ -88,16 +82,10 @@ async function generateIdentityId(
88
82
  const identityPoolId = authConfig?.identityPoolId;
89
83
  const region = getRegionFromIdentityPoolId(identityPoolId);
90
84
 
91
- const getId = createGetIdClient({
92
- endpointResolver: createCognitoIdentityPoolEndpointResolver({
93
- endpointOverride: authConfig.identityPoolEndpoint,
94
- }),
95
- });
96
-
97
85
  // IdentityId is absent so get it using IdentityPoolId with Cognito's GetId API
98
86
  const idResult =
99
87
  // for a first-time user, this will return a brand new identity
100
- // for a returning user, this will retrieve the previous identity associated with the logins
88
+ // for a returning user, this will retrieve the previous identity assocaited with the logins
101
89
  (
102
90
  await getId(
103
91
  {
@@ -7,7 +7,7 @@ import {
7
7
  CredentialsAndIdentityId,
8
8
  CredentialsAndIdentityIdProvider,
9
9
  GetCredentialsOptions,
10
- createGetCredentialsForIdentityClient,
10
+ getCredentialsForIdentity,
11
11
  } from '@aws-amplify/core';
12
12
  import {
13
13
  CognitoIdentityPoolConfig,
@@ -17,7 +17,6 @@ import {
17
17
  import { AuthError } from '../../../errors/AuthError';
18
18
  import { getRegionFromIdentityPoolId } from '../../../foundation/parsers';
19
19
  import { assertIdTokenInAuthTokens } from '../utils/types';
20
- import { createCognitoIdentityPoolEndpointResolver } from '../factories';
21
20
 
22
21
  import { IdentityIdStore } from './types';
23
22
  import { cognitoIdentityIdProvider } from './IdentityIdProvider';
@@ -113,12 +112,6 @@ export class CognitoAWSCredentialsAndIdentityIdProvider
113
112
 
114
113
  const region = getRegionFromIdentityPoolId(authConfig.identityPoolId);
115
114
 
116
- const getCredentialsForIdentity = createGetCredentialsForIdentityClient({
117
- endpointResolver: createCognitoIdentityPoolEndpointResolver({
118
- endpointOverride: authConfig.identityPoolEndpoint,
119
- }),
120
- });
121
-
122
115
  // use identityId to obtain guest credentials
123
116
  // save credentials in-memory
124
117
  // No logins params should be passed for guest creds:
@@ -193,12 +186,6 @@ export class CognitoAWSCredentialsAndIdentityIdProvider
193
186
 
194
187
  const region = getRegionFromIdentityPoolId(authConfig.identityPoolId);
195
188
 
196
- const getCredentialsForIdentity = createGetCredentialsForIdentityClient({
197
- endpointResolver: createCognitoIdentityPoolEndpointResolver({
198
- endpointOverride: authConfig.identityPoolEndpoint,
199
- }),
200
- });
201
-
202
189
  const clientResult = await getCredentialsForIdentity(
203
190
  { region },
204
191
  {
@@ -1,4 +1,3 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  export { createCognitoUserPoolEndpointResolver } from './createCognitoUserPoolEndpointResolver';
4
- export { createCognitoIdentityPoolEndpointResolver } from './createCognitoIdentityPoolEndpointResolver';
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createCognitoIdentityPoolEndpointResolver = void 0;
5
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
- // SPDX-License-Identifier: Apache-2.0
7
- const core_1 = require("@aws-amplify/core");
8
- const utils_1 = require("@aws-amplify/core/internals/utils");
9
- const createCognitoIdentityPoolEndpointResolver = ({ endpointOverride }) => (input) => {
10
- if (endpointOverride) {
11
- return { url: new utils_1.AmplifyUrl(endpointOverride) };
12
- }
13
- return (0, core_1.cognitoIdentityPoolEndpointResolver)(input);
14
- };
15
- exports.createCognitoIdentityPoolEndpointResolver = createCognitoIdentityPoolEndpointResolver;
16
- //# sourceMappingURL=createCognitoIdentityPoolEndpointResolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createCognitoIdentityPoolEndpointResolver.js","sources":["../../../../../src/providers/cognito/factories/createCognitoIdentityPoolEndpointResolver.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createCognitoIdentityPoolEndpointResolver = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst createCognitoIdentityPoolEndpointResolver = ({ endpointOverride }) => (input) => {\n if (endpointOverride) {\n return { url: new utils_1.AmplifyUrl(endpointOverride) };\n }\n return (0, core_1.cognitoIdentityPoolEndpointResolver)(input);\n};\nexports.createCognitoIdentityPoolEndpointResolver = createCognitoIdentityPoolEndpointResolver;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,yCAAyC,GAAG,KAAK,CAAC,CAAC;AAC3D;AACA;AACA,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,yCAAyC,GAAG,CAAC,EAAE,gBAAgB,EAAE,KAAK,CAAC,KAAK,KAAK;AACvF,IAAI,IAAI,gBAAgB,EAAE;AAC1B,QAAQ,OAAO,EAAE,GAAG,EAAE,IAAI,OAAO,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;AACjE,KAAK;AACL,IAAI,OAAO,IAAI,MAAM,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;AAClE,CAAC,CAAC;AACF,OAAO,CAAC,yCAAyC,GAAG,yCAAyC;;"}
@@ -1,6 +0,0 @@
1
- import { EndpointResolverOptions } from '@aws-amplify/core/internals/aws-client-utils';
2
- export declare const createCognitoIdentityPoolEndpointResolver: ({ endpointOverride }: {
3
- endpointOverride: string | undefined;
4
- }) => (input: EndpointResolverOptions) => {
5
- url: URL;
6
- };
@@ -1,14 +0,0 @@
1
- import { cognitoIdentityPoolEndpointResolver } from '@aws-amplify/core';
2
- import { AmplifyUrl } from '@aws-amplify/core/internals/utils';
3
-
4
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
- // SPDX-License-Identifier: Apache-2.0
6
- const createCognitoIdentityPoolEndpointResolver = ({ endpointOverride }) => (input) => {
7
- if (endpointOverride) {
8
- return { url: new AmplifyUrl(endpointOverride) };
9
- }
10
- return cognitoIdentityPoolEndpointResolver(input);
11
- };
12
-
13
- export { createCognitoIdentityPoolEndpointResolver };
14
- //# sourceMappingURL=createCognitoIdentityPoolEndpointResolver.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createCognitoIdentityPoolEndpointResolver.mjs","sources":["../../../../../src/providers/cognito/factories/createCognitoIdentityPoolEndpointResolver.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { cognitoIdentityPoolEndpointResolver } from '@aws-amplify/core';\nimport { AmplifyUrl } from '@aws-amplify/core/internals/utils';\nexport const createCognitoIdentityPoolEndpointResolver = ({ endpointOverride }) => (input) => {\n if (endpointOverride) {\n return { url: new AmplifyUrl(endpointOverride) };\n }\n return cognitoIdentityPoolEndpointResolver(input);\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGY,MAAC,yCAAyC,GAAG,CAAC,EAAE,gBAAgB,EAAE,KAAK,CAAC,KAAK,KAAK;AAC9F,IAAI,IAAI,gBAAgB,EAAE;AAC1B,QAAQ,OAAO,EAAE,GAAG,EAAE,IAAI,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;AACzD,KAAK;AACL,IAAI,OAAO,mCAAmC,CAAC,KAAK,CAAC,CAAC;AACtD;;;;"}
@@ -1,15 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { cognitoIdentityPoolEndpointResolver } from '@aws-amplify/core';
4
- import { EndpointResolverOptions } from '@aws-amplify/core/internals/aws-client-utils';
5
- import { AmplifyUrl } from '@aws-amplify/core/internals/utils';
6
-
7
- export const createCognitoIdentityPoolEndpointResolver =
8
- ({ endpointOverride }: { endpointOverride: string | undefined }) =>
9
- (input: EndpointResolverOptions): { url: URL } => {
10
- if (endpointOverride) {
11
- return { url: new AmplifyUrl(endpointOverride) };
12
- }
13
-
14
- return cognitoIdentityPoolEndpointResolver(input);
15
- };