@vardario/cognito-client 0.1.3 → 0.1.5
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/lib/cognito-client.d.ts +1 -1
- package/lib/cognito-client.js +256 -470
- package/lib/cognito-client.test.d.ts +1 -1
- package/lib/cognito-client.test.js +90 -201
- package/lib/error.js +13 -36
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -19
- package/lib/session-storage/cookie-session-storage/cookie-session-storage.d.ts +2 -2
- package/lib/session-storage/cookie-session-storage/cookie-session-storage.js +24 -48
- package/lib/session-storage/cookie-session-storage/index.d.ts +1 -1
- package/lib/session-storage/cookie-session-storage/index.js +1 -17
- package/lib/session-storage/index.d.ts +4 -4
- package/lib/session-storage/index.js +4 -20
- package/lib/session-storage/local-storage-session-storage.d.ts +2 -2
- package/lib/session-storage/local-storage-session-storage.js +17 -39
- package/lib/session-storage/memory-session-storage.d.ts +2 -2
- package/lib/session-storage/memory-session-storage.js +11 -35
- package/lib/session-storage/session-storage.d.ts +1 -1
- package/lib/session-storage/session-storage.js +2 -9
- package/lib/session-storage/session-storage.test.js +22 -23
- package/lib/test-utils.js +73 -130
- package/lib/utils.d.ts +2 -2
- package/lib/utils.js +47 -64
- package/package.json +16 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "isomorphic-fetch";
|
|
@@ -1,210 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
require("isomorphic-fetch");
|
|
51
|
-
var testcontainers_1 = require("testcontainers");
|
|
52
|
-
var cognito_client_1 = require("./cognito-client");
|
|
53
|
-
var session_storage_1 = require("./session-storage");
|
|
54
|
-
var test_utils_1 = require("./test-utils");
|
|
55
|
-
describe('Cognito Client', function () {
|
|
56
|
-
var cognitoClient;
|
|
57
|
-
var container;
|
|
58
|
-
var sessionStorage = new session_storage_1.MemorySessionStorage();
|
|
59
|
-
var oAuth2 = {
|
|
60
|
-
cognitoDomain: 'http://localhost',
|
|
61
|
-
redirectUrl: 'http://localhost',
|
|
62
|
-
responseType: 'code',
|
|
63
|
-
scopes: ['email openid'],
|
|
1
|
+
import "isomorphic-fetch";
|
|
2
|
+
import { GenericContainer } from "testcontainers";
|
|
3
|
+
import { CognitoClient, CognitoIdentityProvider, } from "./cognito-client.js";
|
|
4
|
+
import { MemorySessionStorage } from "./session-storage/index.js";
|
|
5
|
+
import { newUser, setupCognito, user } from "./test-utils.js";
|
|
6
|
+
import { expect, test, describe, beforeAll, beforeEach, afterAll, } from "vitest";
|
|
7
|
+
describe("Cognito Client", () => {
|
|
8
|
+
let cognitoClient;
|
|
9
|
+
let container;
|
|
10
|
+
let sessionStorage = new MemorySessionStorage();
|
|
11
|
+
const oAuth2 = {
|
|
12
|
+
cognitoDomain: "http://localhost",
|
|
13
|
+
redirectUrl: "http://localhost",
|
|
14
|
+
responseType: "code",
|
|
15
|
+
scopes: ["email openid"],
|
|
64
16
|
};
|
|
65
|
-
|
|
66
|
-
userPoolClientId:
|
|
67
|
-
userPoolId:
|
|
17
|
+
let userPoolConfig = {
|
|
18
|
+
userPoolClientId: "",
|
|
19
|
+
userPoolId: "",
|
|
68
20
|
};
|
|
69
|
-
beforeAll(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
cognitoClient = new cognito_client_1.CognitoClient({
|
|
83
|
-
userPoolId: userPoolConfig.userPoolId,
|
|
84
|
-
userPoolClientId: userPoolConfig.userPoolClientId,
|
|
85
|
-
sessionStorage: sessionStorage,
|
|
86
|
-
endpoint: cognitoEndpoint,
|
|
87
|
-
oAuth2: oAuth2,
|
|
88
|
-
});
|
|
89
|
-
return [2 /*return*/];
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}); });
|
|
93
|
-
beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
94
|
-
var error_1;
|
|
95
|
-
return __generator(this, function (_a) {
|
|
96
|
-
switch (_a.label) {
|
|
97
|
-
case 0:
|
|
98
|
-
_a.trys.push([0, 2, , 3]);
|
|
99
|
-
return [4 /*yield*/, cognitoClient.signOut()];
|
|
100
|
-
case 1:
|
|
101
|
-
_a.sent();
|
|
102
|
-
return [3 /*break*/, 3];
|
|
103
|
-
case 2:
|
|
104
|
-
error_1 = _a.sent();
|
|
105
|
-
return [3 /*break*/, 3];
|
|
106
|
-
case 3: return [2 /*return*/];
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}); });
|
|
110
|
-
afterAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
111
|
-
return __generator(this, function (_a) {
|
|
112
|
-
switch (_a.label) {
|
|
113
|
-
case 0: return [4 /*yield*/, container.stop()];
|
|
114
|
-
case 1:
|
|
115
|
-
_a.sent();
|
|
116
|
-
return [2 /*return*/];
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}); });
|
|
120
|
-
test('authenticateUser', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
121
|
-
var session, _a, _b, newSession;
|
|
122
|
-
return __generator(this, function (_c) {
|
|
123
|
-
switch (_c.label) {
|
|
124
|
-
case 0: return [4 /*yield*/, cognitoClient.authenticateUser(test_utils_1.user.email, test_utils_1.user.password)];
|
|
125
|
-
case 1:
|
|
126
|
-
session = _c.sent();
|
|
127
|
-
_b = (_a = expect(session)).toEqual;
|
|
128
|
-
return [4 /*yield*/, cognitoClient.getSession()];
|
|
129
|
-
case 2:
|
|
130
|
-
_b.apply(_a, [_c.sent()]);
|
|
131
|
-
//Simulate session expiring
|
|
132
|
-
sessionStorage.setSession(__assign(__assign({}, session), { expiresIn: 0 }));
|
|
133
|
-
return [4 /*yield*/, cognitoClient.getSession()];
|
|
134
|
-
case 3:
|
|
135
|
-
newSession = _c.sent();
|
|
136
|
-
expect(newSession).not.toEqual(session);
|
|
137
|
-
return [2 /*return*/];
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}); });
|
|
141
|
-
test('authenticateUserSrp: TODO', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
142
|
-
return __generator(this, function (_a) {
|
|
143
|
-
// TODO: Currently SRP auth is not supported through cognito-local
|
|
144
|
-
// const session = await cognitoClient.authenticateUserSrp(user.name, user.password);
|
|
145
|
-
// expect(session).toEqual(await cognitoClient.getSession());
|
|
146
|
-
expect(true).toBe(true);
|
|
147
|
-
return [2 /*return*/];
|
|
148
|
-
});
|
|
149
|
-
}); });
|
|
150
|
-
test('signUp', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
151
|
-
var _a, id, confirmed;
|
|
152
|
-
return __generator(this, function (_b) {
|
|
153
|
-
switch (_b.label) {
|
|
154
|
-
case 0: return [4 /*yield*/, cognitoClient.signUp(test_utils_1.newUser.email, test_utils_1.newUser.password, [
|
|
155
|
-
{ Name: 'givenName', Value: test_utils_1.newUser.givenName },
|
|
156
|
-
{ Name: 'familyName', Value: test_utils_1.newUser.familyName },
|
|
157
|
-
])];
|
|
158
|
-
case 1:
|
|
159
|
-
_a = _b.sent(), id = _a.id, confirmed = _a.confirmed;
|
|
160
|
-
expect(id).toBeDefined();
|
|
161
|
-
expect(confirmed).toBe(false);
|
|
162
|
-
return [2 /*return*/];
|
|
163
|
-
}
|
|
21
|
+
beforeAll(async () => {
|
|
22
|
+
const cognitoPort = 9229;
|
|
23
|
+
container = await new GenericContainer("jagregory/cognito-local")
|
|
24
|
+
.withExposedPorts(cognitoPort)
|
|
25
|
+
.start();
|
|
26
|
+
const cognitoEndpoint = `http://localhost:${container.getMappedPort(cognitoPort)}`;
|
|
27
|
+
userPoolConfig = await setupCognito(cognitoEndpoint);
|
|
28
|
+
cognitoClient = new CognitoClient({
|
|
29
|
+
userPoolId: userPoolConfig.userPoolId,
|
|
30
|
+
userPoolClientId: userPoolConfig.userPoolClientId,
|
|
31
|
+
sessionStorage: sessionStorage,
|
|
32
|
+
endpoint: cognitoEndpoint,
|
|
33
|
+
oAuth2: oAuth2,
|
|
164
34
|
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
expect(cognitoClient.authenticateUser(test_utils_1.user.email, test_utils_1.user.password)).rejects.toThrow();
|
|
183
|
-
return [4 /*yield*/, cognitoClient.authenticateUser(test_utils_1.user.email, 'newPassword')];
|
|
184
|
-
case 4:
|
|
185
|
-
_a.sent();
|
|
186
|
-
return [2 /*return*/];
|
|
187
|
-
}
|
|
35
|
+
});
|
|
36
|
+
beforeEach(async () => {
|
|
37
|
+
try {
|
|
38
|
+
await cognitoClient.signOut();
|
|
39
|
+
}
|
|
40
|
+
catch (error) { }
|
|
41
|
+
});
|
|
42
|
+
afterAll(async () => {
|
|
43
|
+
await container.stop();
|
|
44
|
+
});
|
|
45
|
+
test("authenticateUser", async () => {
|
|
46
|
+
const session = await cognitoClient.authenticateUser(user.email, user.password);
|
|
47
|
+
expect(session).toEqual(await cognitoClient.getSession());
|
|
48
|
+
//Simulate session expiring
|
|
49
|
+
sessionStorage.setSession({
|
|
50
|
+
...session,
|
|
51
|
+
expiresIn: 0,
|
|
188
52
|
});
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
53
|
+
const newSession = await cognitoClient.getSession();
|
|
54
|
+
expect(newSession).not.toEqual(session);
|
|
55
|
+
});
|
|
56
|
+
test("authenticateUserSrp: TODO", async () => {
|
|
57
|
+
// TODO: Currently SRP auth is not supported through cognito-local
|
|
58
|
+
// const session = await cognitoClient.authenticateUserSrp(user.name, user.password);
|
|
59
|
+
// expect(session).toEqual(await cognitoClient.getSession());
|
|
60
|
+
expect(true).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
test("signUp", async () => {
|
|
63
|
+
const { id, confirmed } = await cognitoClient.signUp(newUser.email, newUser.password, [
|
|
64
|
+
{ Name: "givenName", Value: newUser.givenName },
|
|
65
|
+
{ Name: "familyName", Value: newUser.familyName },
|
|
66
|
+
]);
|
|
67
|
+
expect(id).toBeDefined();
|
|
68
|
+
expect(confirmed).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
test("changePassword", async () => {
|
|
71
|
+
const newPassword = "newPassword";
|
|
72
|
+
expect(cognitoClient.changePassword(user.password, newPassword)).rejects.toThrow();
|
|
73
|
+
await cognitoClient.authenticateUser(user.email, user.password);
|
|
74
|
+
await cognitoClient.changePassword(user.password, newPassword);
|
|
75
|
+
await cognitoClient.signOut();
|
|
76
|
+
expect(cognitoClient.authenticateUser(user.email, user.password)).rejects.toThrow();
|
|
77
|
+
await cognitoClient.authenticateUser(user.email, "newPassword");
|
|
78
|
+
});
|
|
79
|
+
test("generateOAuthSignInUrl", () => {
|
|
80
|
+
const _test = (cb, identityProvider) => {
|
|
81
|
+
const hostedUIUrl = cognitoClient.generateOAuthSignInUrl(identityProvider);
|
|
82
|
+
const { searchParams } = new URL(hostedUIUrl);
|
|
83
|
+
expect(searchParams.get("redirect_uri")).toBe(oAuth2.redirectUrl);
|
|
84
|
+
expect(searchParams.get("response_type")).toBe(oAuth2.responseType);
|
|
85
|
+
expect(searchParams.get("client_id")).toBe(userPoolConfig.userPoolClientId);
|
|
86
|
+
expect(searchParams.get("scope")).toBe(oAuth2.scopes.join(" "));
|
|
87
|
+
expect(searchParams.get("state")).toBeDefined();
|
|
88
|
+
expect(searchParams.get("code_challenge")).toBeDefined();
|
|
89
|
+
expect(searchParams.get("code_challenge_method")).toBe("S256");
|
|
201
90
|
cb(searchParams);
|
|
202
91
|
};
|
|
203
|
-
_test(
|
|
204
|
-
expect(searchParams.get(
|
|
92
|
+
_test((searchParams) => {
|
|
93
|
+
expect(searchParams.get("identity_provider")).toBeNull();
|
|
205
94
|
});
|
|
206
|
-
_test(
|
|
207
|
-
expect(searchParams.get(
|
|
208
|
-
},
|
|
95
|
+
_test((searchParams) => {
|
|
96
|
+
expect(searchParams.get("identity_provider")).toBe(CognitoIdentityProvider.Apple);
|
|
97
|
+
}, CognitoIdentityProvider.Apple);
|
|
209
98
|
});
|
|
210
99
|
});
|
package/lib/error.js
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getAuthError = exports.ErrorCode = exports.AuthException = exports.AuthError = void 0;
|
|
19
1
|
/**
|
|
20
2
|
* Possible Authentications errors
|
|
21
3
|
*/
|
|
22
|
-
var AuthError;
|
|
4
|
+
export var AuthError;
|
|
23
5
|
(function (AuthError) {
|
|
24
6
|
/**
|
|
25
7
|
* User already confirmed
|
|
@@ -57,25 +39,21 @@ var AuthError;
|
|
|
57
39
|
* Unknown auth error happened.
|
|
58
40
|
*/
|
|
59
41
|
AuthError["Unknown"] = "unknown";
|
|
60
|
-
})(AuthError
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_this.authError = authError;
|
|
66
|
-
return _this;
|
|
42
|
+
})(AuthError || (AuthError = {}));
|
|
43
|
+
export class AuthException extends Error {
|
|
44
|
+
constructor(message, authError) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.authError = authError;
|
|
67
47
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
exports.AuthException = AuthException;
|
|
71
|
-
var ErrorCode;
|
|
48
|
+
}
|
|
49
|
+
export var ErrorCode;
|
|
72
50
|
(function (ErrorCode) {
|
|
73
51
|
ErrorCode["UserNotFoundException"] = "UserNotFoundException";
|
|
74
52
|
ErrorCode["NotAuthorizedException"] = "NotAuthorizedException";
|
|
75
53
|
ErrorCode["LimitExceededException"] = "LimitExceededException";
|
|
76
|
-
})(ErrorCode
|
|
77
|
-
function getAuthError(errorResponse) {
|
|
78
|
-
|
|
54
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
55
|
+
export function getAuthError(errorResponse) {
|
|
56
|
+
const mapping = {
|
|
79
57
|
'UserNotFoundException:User cannot be confirmed. Current status is CONFIRMED': AuthError.UserConfirmedAlready,
|
|
80
58
|
'NotAuthorizedException:Incorrect username or password.': AuthError.EmailOrPasswordWrong,
|
|
81
59
|
'LimitExceededException:Attempt limit exceeded, please try after some time.': AuthError.LimitExceededException,
|
|
@@ -86,8 +64,7 @@ function getAuthError(errorResponse) {
|
|
|
86
64
|
'InvalidParameterException:Cannot reset password for the user as there is no registered/verified email or phone_number': AuthError.UserEmailNotVerified,
|
|
87
65
|
'UserNotConfirmedException:User is not confirmed.': AuthError.UserEmailNotVerified,
|
|
88
66
|
};
|
|
89
|
-
|
|
90
|
-
|
|
67
|
+
const message = `${errorResponse.__type}:${errorResponse.message}`;
|
|
68
|
+
const authError = mapping[message] || AuthError.Unknown;
|
|
91
69
|
return new AuthException(message, authError);
|
|
92
70
|
}
|
|
93
|
-
exports.getAuthError = getAuthError;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './cognito-client';
|
|
2
|
-
export * from './error';
|
|
3
|
-
export * from './session-storage';
|
|
1
|
+
export * from './cognito-client.js';
|
|
2
|
+
export * from './error.js';
|
|
3
|
+
export * from './session-storage/index.js';
|
package/lib/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./cognito-client"), exports);
|
|
18
|
-
__exportStar(require("./error"), exports);
|
|
19
|
-
__exportStar(require("./session-storage"), exports);
|
|
1
|
+
export * from './cognito-client.js';
|
|
2
|
+
export * from './error.js';
|
|
3
|
+
export * from './session-storage/index.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CookieProps } from '@vardario/cookies';
|
|
2
|
-
import { Session } from '../../cognito-client';
|
|
3
|
-
import { OAuthVerificationParams, SessionStorage } from '../session-storage';
|
|
2
|
+
import { Session } from '../../cognito-client.js';
|
|
3
|
+
import { OAuthVerificationParams, SessionStorage } from '../session-storage.js';
|
|
4
4
|
export interface CookieSessionStorageProps extends CookieProps {
|
|
5
5
|
cookieName: string;
|
|
6
6
|
}
|
|
@@ -1,66 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.CookieSessionStorage = void 0;
|
|
19
|
-
var cookies_1 = require("@vardario/cookies");
|
|
20
|
-
var session_storage_1 = require("../session-storage");
|
|
1
|
+
import { Cookies } from '@vardario/cookies';
|
|
2
|
+
import { SessionStorage } from '../session-storage.js';
|
|
21
3
|
/**
|
|
22
4
|
* Cookies based session storage.
|
|
23
5
|
* This session storage works also across sub domains.
|
|
24
6
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var _a, _b, _c, _d;
|
|
30
|
-
_this = _super.call(this) || this;
|
|
31
|
-
_this.props = {
|
|
7
|
+
export class CookieSessionStorage extends SessionStorage {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super();
|
|
10
|
+
this.props = {
|
|
32
11
|
domain: props.domain,
|
|
33
|
-
path:
|
|
34
|
-
expires:
|
|
35
|
-
secure:
|
|
36
|
-
sameSite:
|
|
12
|
+
path: props.path ?? '/',
|
|
13
|
+
expires: props.expires ?? 365,
|
|
14
|
+
secure: props.secure ?? true,
|
|
15
|
+
sameSite: props.sameSite ?? 'None',
|
|
37
16
|
cookieName: props.cookieName,
|
|
38
17
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return _this;
|
|
18
|
+
this.cookies = new Cookies(this.props);
|
|
19
|
+
this.sessionCookieName = `${props.cookieName}`;
|
|
20
|
+
this.oAuthParamCookieName = `${props.cookieName}_oauth`;
|
|
43
21
|
}
|
|
44
|
-
|
|
45
|
-
|
|
22
|
+
getSession() {
|
|
23
|
+
const session = this.cookies.getCookie(this.sessionCookieName);
|
|
46
24
|
if (session === undefined) {
|
|
47
25
|
return undefined;
|
|
48
26
|
}
|
|
49
27
|
return JSON.parse(session);
|
|
50
|
-
}
|
|
51
|
-
|
|
28
|
+
}
|
|
29
|
+
setSession(session) {
|
|
52
30
|
this.cookies.setCookie(this.sessionCookieName, JSON.stringify(session));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
31
|
+
}
|
|
32
|
+
getOauthVerificationParams() {
|
|
33
|
+
const oAuthParams = this.cookies.getCookie(this.oAuthParamCookieName);
|
|
56
34
|
if (oAuthParams === undefined) {
|
|
57
35
|
return undefined;
|
|
58
36
|
}
|
|
59
37
|
return JSON.parse(oAuthParams);
|
|
60
|
-
}
|
|
61
|
-
|
|
38
|
+
}
|
|
39
|
+
setOauthVerificationParams(oAuthParams) {
|
|
62
40
|
this.cookies.setCookie(this.oAuthParamCookieName, JSON.stringify(oAuthParams));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
}(session_storage_1.SessionStorage));
|
|
66
|
-
exports.CookieSessionStorage = CookieSessionStorage;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './cookie-session-storage';
|
|
1
|
+
export * from './cookie-session-storage.js';
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./cookie-session-storage"), exports);
|
|
1
|
+
export * from './cookie-session-storage.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './cookie-session-storage';
|
|
2
|
-
export * from './local-storage-session-storage';
|
|
3
|
-
export * from './memory-session-storage';
|
|
4
|
-
export * from './session-storage';
|
|
1
|
+
export * from './cookie-session-storage/index.js';
|
|
2
|
+
export * from './local-storage-session-storage.js';
|
|
3
|
+
export * from './memory-session-storage.js';
|
|
4
|
+
export * from './session-storage.js';
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./cookie-session-storage"), exports);
|
|
18
|
-
__exportStar(require("./local-storage-session-storage"), exports);
|
|
19
|
-
__exportStar(require("./memory-session-storage"), exports);
|
|
20
|
-
__exportStar(require("./session-storage"), exports);
|
|
1
|
+
export * from './cookie-session-storage/index.js';
|
|
2
|
+
export * from './local-storage-session-storage.js';
|
|
3
|
+
export * from './memory-session-storage.js';
|
|
4
|
+
export * from './session-storage.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Session } from '../cognito-client';
|
|
2
|
-
import { OAuthVerificationParams, SessionStorage } from './session-storage';
|
|
1
|
+
import { Session } from '../cognito-client.js';
|
|
2
|
+
import { OAuthVerificationParams, SessionStorage } from './session-storage.js';
|
|
3
3
|
export interface LocalStorageSessionStorageProps {
|
|
4
4
|
storageName: string;
|
|
5
5
|
}
|