@iyio/aws-credential-providers 0.0.10
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/README.md +11 -0
- package/package.json +17 -0
- package/src/index.d.ts +4 -0
- package/src/index.js +8 -0
- package/src/index.js.map +1 -0
- package/src/lib/CognitoAuthProvider.d.ts +30 -0
- package/src/lib/CognitoAuthProvider.js +253 -0
- package/src/lib/CognitoAuthProvider.js.map +1 -0
- package/src/lib/_modules.aws-credential-providers.d.ts +2 -0
- package/src/lib/_modules.aws-credential-providers.js +12 -0
- package/src/lib/_modules.aws-credential-providers.js.map +1 -0
- package/src/lib/_types.aws-credential-providers.d.ts +3 -0
- package/src/lib/_types.aws-credential-providers.js +8 -0
- package/src/lib/_types.aws-credential-providers.js.map +1 -0
- package/src/lib/cognito-test-helper.d.ts +3 -0
- package/src/lib/cognito-test-helper.js +45 -0
- package/src/lib/cognito-test-helper.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# aws-credential-providers
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build aws-credential-providers` to build the library.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `nx test aws-credential-providers` to execute the unit tests via [Jest](https://jestjs.io).
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@iyio/aws-credential-providers",
|
|
3
|
+
"version": "0.0.10",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"dependencies": {},
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"@iyio/aws": "0.0.10",
|
|
10
|
+
"@iyio/common": "0.0.10",
|
|
11
|
+
"rxjs": "^7.5.7",
|
|
12
|
+
"uuid": "^9.0.0",
|
|
13
|
+
"@aws-sdk/credential-providers": "^3.199.0",
|
|
14
|
+
"amazon-cognito-identity-js": "^5.2.12",
|
|
15
|
+
"tslib": "^2.3.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./lib/cognito-test-helper"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/CognitoAuthProvider"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/_modules.aws-credential-providers"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/_types.aws-credential-providers"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/aws-credential-providers/src/index.ts"],"names":[],"mappings":";;;AAAA,oEAA0C;AAC1C,oEAA0C;AAC1C,kFAAwD;AACxD,gFAAsD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Credentials, Provider } from "@aws-sdk/types";
|
|
2
|
+
import { IAwsAuth } from '@iyio/aws';
|
|
3
|
+
import { AuthDeleteResult, AuthRegisterResult, AuthSignInResult, BaseUser, IAuthProvider, ReadonlySubject, Scope, UserAuthProviderData } from '@iyio/common';
|
|
4
|
+
import { ICognitoUserPoolData } from 'amazon-cognito-identity-js';
|
|
5
|
+
/**
|
|
6
|
+
* Used for testing
|
|
7
|
+
*/
|
|
8
|
+
export declare const _allIssuedCognitoCreds: Provider<Credentials>[];
|
|
9
|
+
export interface CognitoAuthProviderConfig extends ICognitoUserPoolData {
|
|
10
|
+
region: string;
|
|
11
|
+
identityPoolId: string;
|
|
12
|
+
currentUser: ReadonlySubject<BaseUser | null>;
|
|
13
|
+
}
|
|
14
|
+
export declare class CognitoAuthProvider implements IAuthProvider, IAwsAuth {
|
|
15
|
+
static fromScope(scope: Scope): CognitoAuthProvider;
|
|
16
|
+
readonly type = "CognitoAuthProvider";
|
|
17
|
+
readonly config: Readonly<CognitoAuthProviderConfig>;
|
|
18
|
+
private readonly userPool;
|
|
19
|
+
private readonly currentUser;
|
|
20
|
+
constructor(config: CognitoAuthProviderConfig);
|
|
21
|
+
private readonly providerMap;
|
|
22
|
+
getAuthProvider(): Provider<Credentials> | undefined;
|
|
23
|
+
getCurrentUser(): Promise<BaseUser | null>;
|
|
24
|
+
private convertCognitoUserAsync;
|
|
25
|
+
getUserAsync(data: UserAuthProviderData): Promise<BaseUser | null>;
|
|
26
|
+
deleteAsync(user: BaseUser): Promise<AuthDeleteResult | undefined>;
|
|
27
|
+
signOutAsync(user: BaseUser): Promise<void>;
|
|
28
|
+
signInEmailPasswordAsync(email: string, password: string, newPassword?: string): Promise<AuthSignInResult>;
|
|
29
|
+
registerEmailPasswordAsync?(email: string, password: string): Promise<AuthRegisterResult | undefined>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CognitoAuthProvider = exports._allIssuedCognitoCreds = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const credential_providers_1 = require("@aws-sdk/credential-providers");
|
|
6
|
+
const aws_1 = require("@iyio/aws");
|
|
7
|
+
const common_1 = require("@iyio/common");
|
|
8
|
+
const amazon_cognito_identity_js_1 = require("amazon-cognito-identity-js");
|
|
9
|
+
const _types_aws_credential_providers_1 = require("./_types.aws-credential-providers");
|
|
10
|
+
const trackIssuedCreds = (0, common_1.parseConfigBool)(process.env['NX_TRACK_COGNITO_ISSUED_CREDS']);
|
|
11
|
+
/**
|
|
12
|
+
* Used for testing
|
|
13
|
+
*/
|
|
14
|
+
exports._allIssuedCognitoCreds = [];
|
|
15
|
+
const sessionKey = Symbol('cognitoSession');
|
|
16
|
+
const userKey = Symbol('cognitoUser');
|
|
17
|
+
class CognitoAuthProvider {
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.type = 'CognitoAuthProvider';
|
|
20
|
+
this.providerMap = {};
|
|
21
|
+
this.userPool = new amazon_cognito_identity_js_1.CognitoUserPool(config);
|
|
22
|
+
this.config = config;
|
|
23
|
+
this.currentUser = config.currentUser;
|
|
24
|
+
}
|
|
25
|
+
static fromScope(scope) {
|
|
26
|
+
return new CognitoAuthProvider({
|
|
27
|
+
UserPoolId: (0, _types_aws_credential_providers_1.cognitoUserPoolIdParam)(scope),
|
|
28
|
+
ClientId: (0, _types_aws_credential_providers_1.cognitoUserPoolClientIdParam)(scope),
|
|
29
|
+
identityPoolId: (0, _types_aws_credential_providers_1.cognitoIdentityPoolIdParam)(scope),
|
|
30
|
+
region: (0, aws_1.awsRegionParam)(scope),
|
|
31
|
+
currentUser: scope.subject(common_1.currentUser)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
getAuthProvider() {
|
|
35
|
+
var _a;
|
|
36
|
+
const user = this.currentUser.value;
|
|
37
|
+
if (!user) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const session = (_a = user.providerData.providerData) === null || _a === void 0 ? void 0 : _a[sessionKey];
|
|
41
|
+
if (!session) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const token = session.getIdToken().getJwtToken();
|
|
45
|
+
let provider = this.providerMap[token];
|
|
46
|
+
if (provider) {
|
|
47
|
+
return provider;
|
|
48
|
+
}
|
|
49
|
+
provider = (0, credential_providers_1.fromCognitoIdentityPool)({
|
|
50
|
+
identityPoolId: this.config.identityPoolId,
|
|
51
|
+
logins: {
|
|
52
|
+
[`cognito-idp.${this.config.region}.amazonaws.com/${this.config.UserPoolId}`]: token
|
|
53
|
+
},
|
|
54
|
+
clientConfig: {
|
|
55
|
+
region: this.config.region,
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const cached = cacheCreds(provider);
|
|
59
|
+
if (trackIssuedCreds) {
|
|
60
|
+
exports._allIssuedCognitoCreds.push(cached);
|
|
61
|
+
}
|
|
62
|
+
return this.providerMap[token] = cached;
|
|
63
|
+
}
|
|
64
|
+
getCurrentUser() {
|
|
65
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
try {
|
|
67
|
+
const cognitoUser = this.userPool.getCurrentUser();
|
|
68
|
+
if (cognitoUser) {
|
|
69
|
+
const user = yield this.convertCognitoUserAsync(cognitoUser);
|
|
70
|
+
return user !== null && user !== void 0 ? user : null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (ex) {
|
|
74
|
+
console.error('User initialization failed', ex);
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
convertCognitoUserAsync(user) {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
user.getSession((error, session) => {
|
|
82
|
+
if (session) {
|
|
83
|
+
const id = user.getUsername();
|
|
84
|
+
resolve(new common_1.BaseUser(id, id, {
|
|
85
|
+
type: this.type,
|
|
86
|
+
userId: id,
|
|
87
|
+
providerData: {
|
|
88
|
+
[sessionKey]: session,
|
|
89
|
+
[userKey]: user
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
reject(error !== null && error !== void 0 ? error : new Error('Unable to get user session'));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
getUserAsync(data) {
|
|
100
|
+
var _a;
|
|
101
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const user = (_a = data.providerData) === null || _a === void 0 ? void 0 : _a[userKey];
|
|
103
|
+
if (!user) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return yield this.convertCognitoUserAsync(user);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
deleteAsync(user) {
|
|
110
|
+
var _a;
|
|
111
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const cUser = (_a = user.providerData.providerData) === null || _a === void 0 ? void 0 : _a[userKey];
|
|
113
|
+
if (!cUser) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
return yield new Promise((resolve) => {
|
|
117
|
+
cUser.deleteUser((err) => {
|
|
118
|
+
if (err) {
|
|
119
|
+
resolve({
|
|
120
|
+
status: 'error',
|
|
121
|
+
message: 'Delete user failed',
|
|
122
|
+
error: err
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
resolve({
|
|
127
|
+
status: 'success'
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
signOutAsync(user) {
|
|
135
|
+
var _a;
|
|
136
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const cUser = (_a = user.providerData.providerData) === null || _a === void 0 ? void 0 : _a[userKey];
|
|
138
|
+
if (!cUser) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
yield new Promise((resolve) => {
|
|
142
|
+
cUser.signOut(() => resolve());
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
signInEmailPasswordAsync(email, password, newPassword) {
|
|
147
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
return new Promise((resolve) => {
|
|
149
|
+
const details = new amazon_cognito_identity_js_1.AuthenticationDetails({
|
|
150
|
+
Username: email,
|
|
151
|
+
Password: password
|
|
152
|
+
});
|
|
153
|
+
const userData = {
|
|
154
|
+
Username: email,
|
|
155
|
+
Pool: this.userPool,
|
|
156
|
+
};
|
|
157
|
+
const cognitoUser = new amazon_cognito_identity_js_1.CognitoUser(userData);
|
|
158
|
+
const callbacks = {
|
|
159
|
+
onSuccess: (session, confirmationNeeded) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
if (confirmationNeeded) {
|
|
161
|
+
resolve({
|
|
162
|
+
success: false,
|
|
163
|
+
message: 'Confirmation required'
|
|
164
|
+
});
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const user = yield this.convertCognitoUserAsync(cognitoUser);
|
|
168
|
+
resolve({
|
|
169
|
+
success: true,
|
|
170
|
+
user
|
|
171
|
+
});
|
|
172
|
+
}),
|
|
173
|
+
onFailure: (err) => {
|
|
174
|
+
resolve({
|
|
175
|
+
success: false,
|
|
176
|
+
message: 'Sign-in failed',
|
|
177
|
+
error: err
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
newPasswordRequired: () => {
|
|
181
|
+
if (newPassword) {
|
|
182
|
+
cognitoUser.completeNewPasswordChallenge(newPassword, {}, callbacks);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
resolve({
|
|
186
|
+
success: false,
|
|
187
|
+
message: 'New password required'
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
cognitoUser.authenticateUser(details, callbacks);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
registerEmailPasswordAsync(email, password) {
|
|
197
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
return new Promise((resolve) => {
|
|
199
|
+
const atts = [
|
|
200
|
+
new amazon_cognito_identity_js_1.CognitoUserAttribute({
|
|
201
|
+
Name: 'email',
|
|
202
|
+
Value: email
|
|
203
|
+
})
|
|
204
|
+
];
|
|
205
|
+
this.userPool.signUp(email, password, atts, [], (err, result) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
if (err || !(result === null || result === void 0 ? void 0 : result.user)) {
|
|
207
|
+
resolve({
|
|
208
|
+
status: 'error',
|
|
209
|
+
message: 'Register failed',
|
|
210
|
+
error: err
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
else if (result.userConfirmed) {
|
|
214
|
+
const result = yield this.signInEmailPasswordAsync(email, password);
|
|
215
|
+
if (result.success) {
|
|
216
|
+
resolve({
|
|
217
|
+
status: 'success',
|
|
218
|
+
user: result.user
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
resolve({
|
|
223
|
+
status: 'error',
|
|
224
|
+
message: result.message,
|
|
225
|
+
error: result.error
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
resolve({
|
|
231
|
+
status: 'verificationRequired',
|
|
232
|
+
message: `A verification code has been sent to ${email}`,
|
|
233
|
+
verificationDestination: email
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}));
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
exports.CognitoAuthProvider = CognitoAuthProvider;
|
|
242
|
+
const cacheCreds = (provider) => {
|
|
243
|
+
let credsPromise = null;
|
|
244
|
+
let t = Date.now();
|
|
245
|
+
return () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
246
|
+
if (!credsPromise || (Date.now() - t) > 1000 * 60 * 3) {
|
|
247
|
+
t = Date.now();
|
|
248
|
+
credsPromise = provider();
|
|
249
|
+
}
|
|
250
|
+
return yield credsPromise;
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
//# sourceMappingURL=CognitoAuthProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CognitoAuthProvider.js","sourceRoot":"","sources":["../../../../../packages/aws-credential-providers/src/lib/CognitoAuthProvider.ts"],"names":[],"mappings":";;;;AAAA,wEAAwE;AAExE,mCAAqD;AACrD,yCAAoM;AACpM,2EAA0L;AAC1L,uFAI2C;AAE3C,MAAM,gBAAgB,GAAC,IAA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,SAAS;gCAChB,IAAI,EAAC,MAAM,CAAC,IAAI;6BACnB,CAAC,CAAA;yBACL;6BAAI;4BACD,OAAO,CAAC;gCACJ,MAAM,EAAC,OAAO;gCACd,OAAO,EAAC,MAAM,CAAC,OAAO;gCACtB,KAAK,EAAC,MAAM,CAAC,KAAK;6BACrB,CAAC,CAAA;yBACL;qBACJ;yBAAI;wBACD,OAAO,CAAC;4BACJ,MAAM,EAAC,sBAAsB;4BAC7B,OAAO,EAAC,wCAAwC,KAAK,EAAE;4BACvD,uBAAuB,EAAC,KAAK;yBAChC,CAAC,CAAA;qBACL;gBACL,CAAC,CAAA,CAAC,CAAA;YACN,CAAC,CAAC,CAAC;QACP,CAAC;KAAA;CAEJ;AA7OD,kDA6OC;AAED,MAAM,UAAU,GAAC,CAAC,QAA8B,EAAuB,EAAE;IACrE,IAAI,YAAY,GAA2B,IAAI,CAAC;IAChD,IAAI,CAAC,GAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IAEjB,OAAO,GAAQ,EAAE;QACb,IAAG,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAC,CAAC,CAAC,GAAC,IAAI,GAAC,EAAE,GAAC,CAAC,EAAC;YACzC,CAAC,GAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,YAAY,GAAC,QAAQ,EAAE,CAAC;SAC3B;QACD,OAAO,MAAM,YAAY,CAAC;IAC9B,CAAC,CAAA,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cognitoAuthProviderModule = void 0;
|
|
4
|
+
const aws_1 = require("@iyio/aws");
|
|
5
|
+
const common_1 = require("@iyio/common");
|
|
6
|
+
const CognitoAuthProvider_1 = require("./CognitoAuthProvider");
|
|
7
|
+
const cognitoAuthProviderModule = (reg) => {
|
|
8
|
+
reg.provideForType(common_1.IAuthProviderType, scope => CognitoAuthProvider_1.CognitoAuthProvider.fromScope(scope))
|
|
9
|
+
.andFor(aws_1.IAwsAuthType);
|
|
10
|
+
};
|
|
11
|
+
exports.cognitoAuthProviderModule = cognitoAuthProviderModule;
|
|
12
|
+
//# sourceMappingURL=_modules.aws-credential-providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_modules.aws-credential-providers.js","sourceRoot":"","sources":["../../../../../packages/aws-credential-providers/src/lib/_modules.aws-credential-providers.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AACzC,yCAAoE;AACpE,+DAA4D;AAErD,MAAM,yBAAyB,GAAC,CAAC,GAAqB,EAAC,EAAE;IAC5D,GAAG,CAAC,cAAc,CAAC,0BAAiB,EAAC,KAAK,CAAA,EAAE,CAAA,yCAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SAC5E,MAAM,CAAC,kBAAY,CAAC,CAAC;AAC9B,CAAC,CAAA;AAHY,QAAA,yBAAyB,6BAGrC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const cognitoIdentityPoolIdParam: import("@iyio/common").CallableTypeDef<string>;
|
|
2
|
+
export declare const cognitoUserPoolClientIdParam: import("@iyio/common").CallableTypeDef<string>;
|
|
3
|
+
export declare const cognitoUserPoolIdParam: import("@iyio/common").CallableTypeDef<string>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cognitoUserPoolIdParam = exports.cognitoUserPoolClientIdParam = exports.cognitoIdentityPoolIdParam = void 0;
|
|
4
|
+
const common_1 = require("@iyio/common");
|
|
5
|
+
exports.cognitoIdentityPoolIdParam = (0, common_1.defineStringParam)('COGNITO_IDENTITY_POOL_ID');
|
|
6
|
+
exports.cognitoUserPoolClientIdParam = (0, common_1.defineStringParam)('COGNITO_USER_POOL_CLIENT_ID');
|
|
7
|
+
exports.cognitoUserPoolIdParam = (0, common_1.defineStringParam)('COGNITO_USER_POOL_ID');
|
|
8
|
+
//# sourceMappingURL=_types.aws-credential-providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_types.aws-credential-providers.js","sourceRoot":"","sources":["../../../../../packages/aws-credential-providers/src/lib/_types.aws-credential-providers.ts"],"names":[],"mappings":";;;AAAA,yCAAiD;AAEpC,QAAA,0BAA0B,GAAC,IAAA,0BAAiB,EAAC,0BAA0B,CAAC,CAAC;AACzE,QAAA,4BAA4B,GAAC,IAAA,0BAAiB,EAAC,6BAA6B,CAAC,CAAC;AAC9E,QAAA,sBAAsB,GAAC,IAAA,0BAAiB,EAAC,sBAAsB,CAAC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BaseUser, Scope, ScopeModule } from "@iyio/common";
|
|
2
|
+
import { CognitoAuthProviderConfig } from "./CognitoAuthProvider";
|
|
3
|
+
export declare const useTempCognitoUser: (module: ScopeModule, work: (scope: Scope, user: BaseUser, config: CognitoAuthProviderConfig) => Promise<void>) => Promise<void>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useTempCognitoUser = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const aws_1 = require("@iyio/aws");
|
|
6
|
+
const common_1 = require("@iyio/common");
|
|
7
|
+
const assert_1 = require("assert");
|
|
8
|
+
const CognitoAuthProvider_1 = require("./CognitoAuthProvider");
|
|
9
|
+
const useTempCognitoUser = (module, work) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
10
|
+
let provider = undefined;
|
|
11
|
+
const scope = (0, common_1.createScope)(reg => {
|
|
12
|
+
reg.use(module);
|
|
13
|
+
provider = reg
|
|
14
|
+
.provideForType(common_1.IAuthProviderType, scope => CognitoAuthProvider_1.CognitoAuthProvider.fromScope(scope))
|
|
15
|
+
.andFor(aws_1.IAwsAuthType)
|
|
16
|
+
.getValue();
|
|
17
|
+
});
|
|
18
|
+
(0, common_1.storeService)(scope).mount('/', new common_1.MemoryStore());
|
|
19
|
+
const email = `unit-test.${(0, common_1.shortUuid)()}@iyio.io`;
|
|
20
|
+
const password = 'P1!p-' + (0, common_1.shortUuid)();
|
|
21
|
+
console.log(`Registering ${email}, ${password}`);
|
|
22
|
+
const result = yield (0, common_1.authService)(scope).registerEmailPasswordAsync(email, password);
|
|
23
|
+
if (result.status !== 'success') {
|
|
24
|
+
console.log(result);
|
|
25
|
+
(0, assert_1.fail)('Result not success');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
yield work(scope, result.user, provider.config);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
const deleteResult = yield (0, common_1.authService)(scope).deleteAsync(result.user);
|
|
33
|
+
if (deleteResult.status === 'error') {
|
|
34
|
+
(0, assert_1.fail)('Failed to delete user');
|
|
35
|
+
}
|
|
36
|
+
else if (deleteResult.status === 'pending') {
|
|
37
|
+
console.warn('Delete user pending');
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.log(`${email} deleted`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
exports.useTempCognitoUser = useTempCognitoUser;
|
|
45
|
+
//# sourceMappingURL=cognito-test-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognito-test-helper.js","sourceRoot":"","sources":["../../../../../packages/aws-credential-providers/src/lib/cognito-test-helper.ts"],"names":[],"mappings":";;;;AAAA,mCAAyC;AACzC,yCAA+I;AAC/I,mCAA8B;AAC9B,+DAAuF;AAEhF,MAAM,kBAAkB,GAAC,CAAO,MAAkB,EAAC,IAAgF,EAAC,EAAE;IAEzI,IAAI,QAAQ,GAA+B,SAAS,CAAC;IAErD,MAAM,KAAK,GAAC,IAAA,oBAAW,EAAC,GAAG,CAAA,EAAE;QACzB,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