@aws-sdk/credential-provider-cognito-identity 3.186.0 → 3.188.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.
- package/CHANGELOG.md +8 -0
- package/dist-es/InMemoryStorage.js +9 -12
- package/dist-es/IndexedDbStorage.js +44 -47
- package/dist-es/fromCognitoIdentity.js +14 -36
- package/dist-es/fromCognitoIdentityPool.js +26 -61
- package/dist-es/localStorage.js +1 -1
- package/dist-es/resolveLogins.js +7 -11
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.188.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.187.0...v3.188.0) (2022-10-13)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aws-sdk/credential-provider-cognito-identity
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @aws-sdk/credential-provider-cognito-identity
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (store === void 0) { store = {}; }
|
|
1
|
+
export class InMemoryStorage {
|
|
2
|
+
constructor(store = {}) {
|
|
4
3
|
this.store = store;
|
|
5
4
|
}
|
|
6
|
-
|
|
5
|
+
getItem(key) {
|
|
7
6
|
if (key in this.store) {
|
|
8
7
|
return this.store[key];
|
|
9
8
|
}
|
|
10
9
|
return null;
|
|
11
|
-
}
|
|
12
|
-
|
|
10
|
+
}
|
|
11
|
+
removeItem(key) {
|
|
13
12
|
delete this.store[key];
|
|
14
|
-
}
|
|
15
|
-
|
|
13
|
+
}
|
|
14
|
+
setItem(key, value) {
|
|
16
15
|
this.store[key] = value;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
}());
|
|
20
|
-
export { InMemoryStorage };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,70 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (dbName === void 0) { dbName = "aws:cognito-identity-ids"; }
|
|
1
|
+
const STORE_NAME = "IdentityIds";
|
|
2
|
+
export class IndexedDbStorage {
|
|
3
|
+
constructor(dbName = "aws:cognito-identity-ids") {
|
|
5
4
|
this.dbName = dbName;
|
|
6
5
|
}
|
|
7
|
-
|
|
8
|
-
return this.withObjectStore("readonly",
|
|
9
|
-
|
|
10
|
-
return new Promise(
|
|
11
|
-
req.onerror =
|
|
12
|
-
req.onsuccess =
|
|
6
|
+
getItem(key) {
|
|
7
|
+
return this.withObjectStore("readonly", (store) => {
|
|
8
|
+
const req = store.get(key);
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
req.onerror = () => resolve(null);
|
|
11
|
+
req.onsuccess = () => resolve(req.result ? req.result.value : null);
|
|
13
12
|
});
|
|
14
|
-
}).catch(
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return this.withObjectStore("readwrite",
|
|
18
|
-
|
|
19
|
-
return new Promise(
|
|
20
|
-
req.onerror =
|
|
21
|
-
req.onsuccess =
|
|
13
|
+
}).catch(() => null);
|
|
14
|
+
}
|
|
15
|
+
removeItem(key) {
|
|
16
|
+
return this.withObjectStore("readwrite", (store) => {
|
|
17
|
+
const req = store.delete(key);
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
req.onerror = () => reject(req.error);
|
|
20
|
+
req.onsuccess = () => resolve();
|
|
22
21
|
});
|
|
23
22
|
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return this.withObjectStore("readwrite",
|
|
27
|
-
|
|
28
|
-
return new Promise(
|
|
29
|
-
req.onerror =
|
|
30
|
-
req.onsuccess =
|
|
23
|
+
}
|
|
24
|
+
setItem(id, value) {
|
|
25
|
+
return this.withObjectStore("readwrite", (store) => {
|
|
26
|
+
const req = store.put({ id, value });
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
req.onerror = () => reject(req.error);
|
|
29
|
+
req.onsuccess = () => resolve();
|
|
31
30
|
});
|
|
32
31
|
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return new Promise(
|
|
37
|
-
openDbRequest.onsuccess =
|
|
32
|
+
}
|
|
33
|
+
getDb() {
|
|
34
|
+
const openDbRequest = self.indexedDB.open(this.dbName, 1);
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
openDbRequest.onsuccess = () => {
|
|
38
37
|
resolve(openDbRequest.result);
|
|
39
38
|
};
|
|
40
|
-
openDbRequest.onerror =
|
|
39
|
+
openDbRequest.onerror = () => {
|
|
41
40
|
reject(openDbRequest.error);
|
|
42
41
|
};
|
|
43
|
-
openDbRequest.onblocked =
|
|
42
|
+
openDbRequest.onblocked = () => {
|
|
44
43
|
reject(new Error("Unable to access DB"));
|
|
45
44
|
};
|
|
46
|
-
openDbRequest.onupgradeneeded =
|
|
47
|
-
|
|
48
|
-
db.onerror =
|
|
45
|
+
openDbRequest.onupgradeneeded = () => {
|
|
46
|
+
const db = openDbRequest.result;
|
|
47
|
+
db.onerror = () => {
|
|
49
48
|
reject(new Error("Failed to create object store"));
|
|
50
49
|
};
|
|
51
50
|
db.createObjectStore(STORE_NAME, { keyPath: "id" });
|
|
52
51
|
};
|
|
53
52
|
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return this.getDb().then(
|
|
57
|
-
|
|
58
|
-
tx.oncomplete =
|
|
59
|
-
return new Promise(
|
|
60
|
-
tx.onerror =
|
|
53
|
+
}
|
|
54
|
+
withObjectStore(mode, action) {
|
|
55
|
+
return this.getDb().then((db) => {
|
|
56
|
+
const tx = db.transaction(STORE_NAME, mode);
|
|
57
|
+
tx.oncomplete = () => db.close();
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
tx.onerror = () => reject(tx.error);
|
|
61
60
|
resolve(action(tx.objectStore(STORE_NAME)));
|
|
62
|
-
}).catch(
|
|
61
|
+
}).catch((err) => {
|
|
63
62
|
db.close();
|
|
64
63
|
throw err;
|
|
65
64
|
});
|
|
66
65
|
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}());
|
|
70
|
-
export { IndexedDbStorage };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1,43 +1,21 @@
|
|
|
1
|
-
import { __awaiter, __generator } from "tslib";
|
|
2
1
|
import { GetCredentialsForIdentityCommand } from "@aws-sdk/client-cognito-identity";
|
|
3
2
|
import { CredentialsProviderError } from "@aws-sdk/property-provider";
|
|
4
3
|
import { resolveLogins } from "./resolveLogins";
|
|
5
4
|
export function fromCognitoIdentity(parameters) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return [4, resolveLogins(parameters.logins)];
|
|
21
|
-
case 1:
|
|
22
|
-
_h = _k.sent();
|
|
23
|
-
return [3, 3];
|
|
24
|
-
case 2:
|
|
25
|
-
_h = undefined;
|
|
26
|
-
_k.label = 3;
|
|
27
|
-
case 3: return [4, _f.apply(_e, [new (_g.apply(GetCredentialsForIdentityCommand, [void 0, (_j.Logins = _h,
|
|
28
|
-
_j)]))()])];
|
|
29
|
-
case 4:
|
|
30
|
-
_a = (_k.sent()).Credentials, _b = _a === void 0 ? throwOnMissingCredentials() : _a, _c = _b.AccessKeyId, AccessKeyId = _c === void 0 ? throwOnMissingAccessKeyId() : _c, Expiration = _b.Expiration, _d = _b.SecretKey, SecretKey = _d === void 0 ? throwOnMissingSecretKey() : _d, SessionToken = _b.SessionToken;
|
|
31
|
-
return [2, {
|
|
32
|
-
identityId: parameters.identityId,
|
|
33
|
-
accessKeyId: AccessKeyId,
|
|
34
|
-
secretAccessKey: SecretKey,
|
|
35
|
-
sessionToken: SessionToken,
|
|
36
|
-
expiration: Expiration,
|
|
37
|
-
}];
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}); };
|
|
5
|
+
return async () => {
|
|
6
|
+
const { Credentials: { AccessKeyId = throwOnMissingAccessKeyId(), Expiration, SecretKey = throwOnMissingSecretKey(), SessionToken, } = throwOnMissingCredentials(), } = await parameters.client.send(new GetCredentialsForIdentityCommand({
|
|
7
|
+
CustomRoleArn: parameters.customRoleArn,
|
|
8
|
+
IdentityId: parameters.identityId,
|
|
9
|
+
Logins: parameters.logins ? await resolveLogins(parameters.logins) : undefined,
|
|
10
|
+
}));
|
|
11
|
+
return {
|
|
12
|
+
identityId: parameters.identityId,
|
|
13
|
+
accessKeyId: AccessKeyId,
|
|
14
|
+
secretAccessKey: SecretKey,
|
|
15
|
+
sessionToken: SessionToken,
|
|
16
|
+
expiration: Expiration,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
41
19
|
}
|
|
42
20
|
function throwOnMissingAccessKeyId() {
|
|
43
21
|
throw new CredentialsProviderError("Response from Amazon Cognito contained no access key ID");
|
|
@@ -1,72 +1,37 @@
|
|
|
1
|
-
import { __awaiter, __generator } from "tslib";
|
|
2
1
|
import { GetIdCommand } from "@aws-sdk/client-cognito-identity";
|
|
3
2
|
import { CredentialsProviderError } from "@aws-sdk/property-provider";
|
|
4
3
|
import { fromCognitoIdentity } from "./fromCognitoIdentity";
|
|
5
4
|
import { localStorage } from "./localStorage";
|
|
6
5
|
import { resolveLogins } from "./resolveLogins";
|
|
7
|
-
export function fromCognitoIdentityPool(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
case 1:
|
|
21
|
-
_a = (_h.sent());
|
|
22
|
-
_h.label = 2;
|
|
23
|
-
case 2:
|
|
24
|
-
identityId = _a;
|
|
25
|
-
if (!!identityId) return [3, 7];
|
|
26
|
-
_d = (_c = client).send;
|
|
27
|
-
_e = GetIdCommand.bind;
|
|
28
|
-
_g = {
|
|
29
|
-
AccountId: accountId,
|
|
30
|
-
IdentityPoolId: identityPoolId
|
|
31
|
-
};
|
|
32
|
-
if (!logins) return [3, 4];
|
|
33
|
-
return [4, resolveLogins(logins)];
|
|
34
|
-
case 3:
|
|
35
|
-
_f = _h.sent();
|
|
36
|
-
return [3, 5];
|
|
37
|
-
case 4:
|
|
38
|
-
_f = undefined;
|
|
39
|
-
_h.label = 5;
|
|
40
|
-
case 5: return [4, _d.apply(_c, [new (_e.apply(GetIdCommand, [void 0, (_g.Logins = _f,
|
|
41
|
-
_g)]))()])];
|
|
42
|
-
case 6:
|
|
43
|
-
_b = (_h.sent()).IdentityId, IdentityId = _b === void 0 ? throwOnMissingId() : _b;
|
|
44
|
-
identityId = IdentityId;
|
|
45
|
-
if (cacheKey) {
|
|
46
|
-
Promise.resolve(cache.setItem(cacheKey, identityId)).catch(function () { });
|
|
47
|
-
}
|
|
48
|
-
_h.label = 7;
|
|
49
|
-
case 7:
|
|
50
|
-
provider = fromCognitoIdentity({
|
|
51
|
-
client: client,
|
|
52
|
-
customRoleArn: customRoleArn,
|
|
53
|
-
logins: logins,
|
|
54
|
-
identityId: identityId,
|
|
55
|
-
});
|
|
56
|
-
return [2, provider()];
|
|
6
|
+
export function fromCognitoIdentityPool({ accountId, cache = localStorage(), client, customRoleArn, identityPoolId, logins, userIdentifier = !logins || Object.keys(logins).length === 0 ? "ANONYMOUS" : undefined, }) {
|
|
7
|
+
const cacheKey = userIdentifier ? `aws:cognito-identity-credentials:${identityPoolId}:${userIdentifier}` : undefined;
|
|
8
|
+
let provider = async () => {
|
|
9
|
+
let identityId = cacheKey && (await cache.getItem(cacheKey));
|
|
10
|
+
if (!identityId) {
|
|
11
|
+
const { IdentityId = throwOnMissingId() } = await client.send(new GetIdCommand({
|
|
12
|
+
AccountId: accountId,
|
|
13
|
+
IdentityPoolId: identityPoolId,
|
|
14
|
+
Logins: logins ? await resolveLogins(logins) : undefined,
|
|
15
|
+
}));
|
|
16
|
+
identityId = IdentityId;
|
|
17
|
+
if (cacheKey) {
|
|
18
|
+
Promise.resolve(cache.setItem(cacheKey, identityId)).catch(() => { });
|
|
57
19
|
}
|
|
20
|
+
}
|
|
21
|
+
provider = fromCognitoIdentity({
|
|
22
|
+
client,
|
|
23
|
+
customRoleArn,
|
|
24
|
+
logins,
|
|
25
|
+
identityId,
|
|
58
26
|
});
|
|
59
|
-
|
|
60
|
-
return function () {
|
|
61
|
-
return provider().catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
62
|
-
return __generator(this, function (_a) {
|
|
63
|
-
if (cacheKey) {
|
|
64
|
-
Promise.resolve(cache.removeItem(cacheKey)).catch(function () { });
|
|
65
|
-
}
|
|
66
|
-
throw err;
|
|
67
|
-
});
|
|
68
|
-
}); });
|
|
27
|
+
return provider();
|
|
69
28
|
};
|
|
29
|
+
return () => provider().catch(async (err) => {
|
|
30
|
+
if (cacheKey) {
|
|
31
|
+
Promise.resolve(cache.removeItem(cacheKey)).catch(() => { });
|
|
32
|
+
}
|
|
33
|
+
throw err;
|
|
34
|
+
});
|
|
70
35
|
}
|
|
71
36
|
function throwOnMissingId() {
|
|
72
37
|
throw new CredentialsProviderError("Response from Amazon Cognito contained no identity ID");
|
package/dist-es/localStorage.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IndexedDbStorage } from "./IndexedDbStorage";
|
|
2
2
|
import { InMemoryStorage } from "./InMemoryStorage";
|
|
3
|
-
|
|
3
|
+
const inMemoryStorage = new InMemoryStorage();
|
|
4
4
|
export function localStorage() {
|
|
5
5
|
if (typeof self === "object" && self.indexedDB) {
|
|
6
6
|
return new IndexedDbStorage();
|
package/dist-es/resolveLogins.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { __read } from "tslib";
|
|
2
1
|
export function resolveLogins(logins) {
|
|
3
|
-
return Promise.all(Object.keys(logins).reduce(
|
|
4
|
-
|
|
2
|
+
return Promise.all(Object.keys(logins).reduce((arr, name) => {
|
|
3
|
+
const tokenOrProvider = logins[name];
|
|
5
4
|
if (typeof tokenOrProvider === "string") {
|
|
6
5
|
arr.push([name, tokenOrProvider]);
|
|
7
6
|
}
|
|
8
7
|
else {
|
|
9
|
-
arr.push(tokenOrProvider().then(
|
|
8
|
+
arr.push(tokenOrProvider().then((token) => [name, token]));
|
|
10
9
|
}
|
|
11
10
|
return arr;
|
|
12
|
-
}, [])).then(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return logins;
|
|
17
|
-
}, {});
|
|
18
|
-
});
|
|
11
|
+
}, [])).then((resolvedPairs) => resolvedPairs.reduce((logins, [key, value]) => {
|
|
12
|
+
logins[key] = value;
|
|
13
|
+
return logins;
|
|
14
|
+
}, {}));
|
|
19
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/credential-provider-cognito-identity",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.188.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
6
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
},
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@aws-sdk/client-cognito-identity": "3.
|
|
25
|
-
"@aws-sdk/property-provider": "3.
|
|
26
|
-
"@aws-sdk/types": "3.
|
|
24
|
+
"@aws-sdk/client-cognito-identity": "3.188.0",
|
|
25
|
+
"@aws-sdk/property-provider": "3.188.0",
|
|
26
|
+
"@aws-sdk/types": "3.188.0",
|
|
27
27
|
"tslib": "^2.3.1"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|