@iyio/aws-credential-providers 0.0.29 → 0.1.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/esm/package.json +4 -0
- package/esm/src/index.d.ts +4 -0
- package/esm/src/index.js +5 -0
- package/esm/src/index.js.map +1 -0
- package/esm/src/lib/CognitoAuthProvider.d.ts +32 -0
- package/esm/src/lib/CognitoAuthProvider.js +265 -0
- package/esm/src/lib/CognitoAuthProvider.js.map +1 -0
- package/esm/src/lib/_modules.aws-credential-providers.d.ts +2 -0
- package/esm/src/lib/_modules.aws-credential-providers.js +8 -0
- package/esm/src/lib/_modules.aws-credential-providers.js.map +1 -0
- package/esm/src/lib/_types.aws-credential-providers.d.ts +3 -0
- package/esm/src/lib/_types.aws-credential-providers.js +5 -0
- package/esm/src/lib/_types.aws-credential-providers.js.map +1 -0
- package/esm/src/lib/cognito-test-helper.d.ts +3 -0
- package/esm/src/lib/cognito-test-helper.js +41 -0
- package/esm/src/lib/cognito-test-helper.js.map +1 -0
- package/package.json +7 -4
- package/src/package.json +4 -0
package/esm/package.json
ADDED
package/esm/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/aws-credential-providers/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yCAAyC,CAAC;AACxD,cAAc,uCAAuC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Credentials, Provider } from "@aws-sdk/types";
|
|
2
|
+
import { AwsAuthProvider } from '@iyio/aws';
|
|
3
|
+
import { AuthDeleteResult, AuthProvider, AuthRegisterResult, AuthSignInResult, BaseUser, FactoryTypeDef, ReadonlySubject, Scope, UserAuthProviderData, UserFactoryCallback } 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 declare const CognitoAuthProviderType = "CognitoAuthProvider";
|
|
10
|
+
export interface CognitoAuthProviderConfig extends ICognitoUserPoolData {
|
|
11
|
+
region: string;
|
|
12
|
+
identityPoolId: string;
|
|
13
|
+
currentUser: ReadonlySubject<BaseUser | null>;
|
|
14
|
+
userFactory: FactoryTypeDef<UserFactoryCallback>;
|
|
15
|
+
}
|
|
16
|
+
export declare class CognitoAuthProvider implements AuthProvider, AwsAuthProvider {
|
|
17
|
+
static fromScope(scope: Scope): CognitoAuthProvider;
|
|
18
|
+
readonly type = "CognitoAuthProvider";
|
|
19
|
+
readonly config: Readonly<CognitoAuthProviderConfig>;
|
|
20
|
+
private readonly userPool;
|
|
21
|
+
private readonly currentUser;
|
|
22
|
+
constructor(config: CognitoAuthProviderConfig);
|
|
23
|
+
private readonly providerMap;
|
|
24
|
+
getAuthProvider(): Provider<Credentials> | undefined;
|
|
25
|
+
getCurrentUser(): Promise<BaseUser | null>;
|
|
26
|
+
private convertCognitoUserAsync;
|
|
27
|
+
getUserAsync(data: UserAuthProviderData): Promise<BaseUser | null>;
|
|
28
|
+
deleteAsync(user: BaseUser): Promise<AuthDeleteResult | undefined>;
|
|
29
|
+
signOutAsync(user: BaseUser): Promise<void>;
|
|
30
|
+
signInEmailPasswordAsync(email: string, password: string, newPassword?: string): Promise<AuthSignInResult>;
|
|
31
|
+
registerEmailPasswordAsync?(email: string, password: string): Promise<AuthRegisterResult | undefined>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { fromCognitoIdentityPool } from "@aws-sdk/credential-providers";
|
|
3
|
+
import { awsRegionParam } from '@iyio/aws';
|
|
4
|
+
import { currentBaseUser, parseConfigBool, UserFactory } from '@iyio/common';
|
|
5
|
+
import { AuthenticationDetails, CognitoUser, CognitoUserAttribute, CognitoUserPool } from 'amazon-cognito-identity-js';
|
|
6
|
+
import { cognitoIdentityPoolIdParam, cognitoUserPoolClientIdParam, cognitoUserPoolIdParam } from './_types.aws-credential-providers';
|
|
7
|
+
const trackIssuedCreds = parseConfigBool(process.env['NX_TRACK_COGNITO_ISSUED_CREDS']);
|
|
8
|
+
/**
|
|
9
|
+
* Used for testing
|
|
10
|
+
*/
|
|
11
|
+
export const _allIssuedCognitoCreds = [];
|
|
12
|
+
const sessionKey = Symbol('cognitoSession');
|
|
13
|
+
const userKey = Symbol('cognitoUser');
|
|
14
|
+
export const CognitoAuthProviderType = 'CognitoAuthProvider';
|
|
15
|
+
export class CognitoAuthProvider {
|
|
16
|
+
constructor(config) {
|
|
17
|
+
this.type = CognitoAuthProviderType;
|
|
18
|
+
this.providerMap = {};
|
|
19
|
+
this.userPool = new CognitoUserPool(config);
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.currentUser = config.currentUser;
|
|
22
|
+
}
|
|
23
|
+
static fromScope(scope) {
|
|
24
|
+
return new CognitoAuthProvider({
|
|
25
|
+
UserPoolId: cognitoUserPoolIdParam(scope),
|
|
26
|
+
ClientId: cognitoUserPoolClientIdParam(scope),
|
|
27
|
+
identityPoolId: cognitoIdentityPoolIdParam(scope),
|
|
28
|
+
region: awsRegionParam(scope),
|
|
29
|
+
currentUser: scope.subject(currentBaseUser),
|
|
30
|
+
userFactory: scope.to(UserFactory)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getAuthProvider() {
|
|
34
|
+
var _a;
|
|
35
|
+
const user = this.currentUser.value;
|
|
36
|
+
if (!user) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const session = (_a = user.providerData.providerData) === null || _a === void 0 ? void 0 : _a[sessionKey];
|
|
40
|
+
if (!session) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const token = session.getIdToken().getJwtToken();
|
|
44
|
+
let provider = this.providerMap[token];
|
|
45
|
+
if (provider) {
|
|
46
|
+
return provider;
|
|
47
|
+
}
|
|
48
|
+
provider = fromCognitoIdentityPool({
|
|
49
|
+
identityPoolId: this.config.identityPoolId,
|
|
50
|
+
logins: {
|
|
51
|
+
[`cognito-idp.${this.config.region}.amazonaws.com/${this.config.UserPoolId}`]: token
|
|
52
|
+
},
|
|
53
|
+
clientConfig: {
|
|
54
|
+
region: this.config.region,
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const cached = cacheCreds(provider);
|
|
58
|
+
if (trackIssuedCreds) {
|
|
59
|
+
_allIssuedCognitoCreds.push(cached);
|
|
60
|
+
}
|
|
61
|
+
return this.providerMap[token] = cached;
|
|
62
|
+
}
|
|
63
|
+
getCurrentUser() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
try {
|
|
66
|
+
const cognitoUser = this.userPool.getCurrentUser();
|
|
67
|
+
if (cognitoUser) {
|
|
68
|
+
const user = yield this.convertCognitoUserAsync(cognitoUser);
|
|
69
|
+
return user !== null && user !== void 0 ? user : null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (ex) {
|
|
73
|
+
console.error('User initialization failed', ex);
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
convertCognitoUserAsync(user) {
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
user.getSession((error, session) => {
|
|
81
|
+
if (session) {
|
|
82
|
+
const id = user.getUsername();
|
|
83
|
+
const options = {
|
|
84
|
+
id,
|
|
85
|
+
name: id,
|
|
86
|
+
providerData: {
|
|
87
|
+
type: this.type,
|
|
88
|
+
userId: id,
|
|
89
|
+
providerData: {
|
|
90
|
+
[sessionKey]: session,
|
|
91
|
+
[userKey]: user
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const baseUser = this.config.userFactory.generate(options);
|
|
96
|
+
if (!baseUser) {
|
|
97
|
+
reject('No user factory provided a user');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
resolve(baseUser);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
reject(error !== null && error !== void 0 ? error : new Error('Unable to get user session'));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
getUserAsync(data) {
|
|
109
|
+
var _a;
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const user = (_a = data.providerData) === null || _a === void 0 ? void 0 : _a[userKey];
|
|
112
|
+
if (!user) {
|
|
113
|
+
if (!data.userId) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const currentUser = yield this.getCurrentUser();
|
|
117
|
+
return (currentUser === null || currentUser === void 0 ? void 0 : currentUser.id) === data.userId ? currentUser : null;
|
|
118
|
+
}
|
|
119
|
+
return yield this.convertCognitoUserAsync(user);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
deleteAsync(user) {
|
|
123
|
+
var _a;
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const cUser = (_a = user.providerData.providerData) === null || _a === void 0 ? void 0 : _a[userKey];
|
|
126
|
+
if (!cUser) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
return yield new Promise((resolve) => {
|
|
130
|
+
cUser.deleteUser((err) => {
|
|
131
|
+
if (err) {
|
|
132
|
+
resolve({
|
|
133
|
+
status: 'error',
|
|
134
|
+
message: 'Delete user failed',
|
|
135
|
+
error: err
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
resolve({
|
|
140
|
+
status: 'success'
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
signOutAsync(user) {
|
|
148
|
+
var _a;
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const cUser = (_a = user.providerData.providerData) === null || _a === void 0 ? void 0 : _a[userKey];
|
|
151
|
+
if (!cUser) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
yield new Promise((resolve) => {
|
|
155
|
+
cUser.signOut(() => resolve());
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
signInEmailPasswordAsync(email, password, newPassword) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
return new Promise((resolve) => {
|
|
162
|
+
const details = new AuthenticationDetails({
|
|
163
|
+
Username: email,
|
|
164
|
+
Password: password
|
|
165
|
+
});
|
|
166
|
+
const userData = {
|
|
167
|
+
Username: email,
|
|
168
|
+
Pool: this.userPool,
|
|
169
|
+
};
|
|
170
|
+
const cognitoUser = new CognitoUser(userData);
|
|
171
|
+
const callbacks = {
|
|
172
|
+
onSuccess: (session, confirmationNeeded) => __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
if (confirmationNeeded) {
|
|
174
|
+
resolve({
|
|
175
|
+
success: false,
|
|
176
|
+
message: 'Confirmation required'
|
|
177
|
+
});
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const user = yield this.convertCognitoUserAsync(cognitoUser);
|
|
181
|
+
resolve({
|
|
182
|
+
success: true,
|
|
183
|
+
user
|
|
184
|
+
});
|
|
185
|
+
}),
|
|
186
|
+
onFailure: (err) => {
|
|
187
|
+
resolve({
|
|
188
|
+
success: false,
|
|
189
|
+
message: 'Sign-in failed',
|
|
190
|
+
error: err
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
newPasswordRequired: () => {
|
|
194
|
+
if (newPassword) {
|
|
195
|
+
cognitoUser.completeNewPasswordChallenge(newPassword, {}, callbacks);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
resolve({
|
|
199
|
+
success: false,
|
|
200
|
+
message: 'New password required'
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
cognitoUser.authenticateUser(details, callbacks);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
registerEmailPasswordAsync(email, password) {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
return new Promise((resolve) => {
|
|
212
|
+
const atts = [
|
|
213
|
+
new CognitoUserAttribute({
|
|
214
|
+
Name: 'email',
|
|
215
|
+
Value: email
|
|
216
|
+
})
|
|
217
|
+
];
|
|
218
|
+
this.userPool.signUp(email, password, atts, [], (err, result) => __awaiter(this, void 0, void 0, function* () {
|
|
219
|
+
if (err || !(result === null || result === void 0 ? void 0 : result.user)) {
|
|
220
|
+
resolve({
|
|
221
|
+
status: 'error',
|
|
222
|
+
message: 'Register failed',
|
|
223
|
+
error: err
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
else if (result.userConfirmed) {
|
|
227
|
+
const result = yield this.signInEmailPasswordAsync(email, password);
|
|
228
|
+
if (result.success) {
|
|
229
|
+
resolve({
|
|
230
|
+
status: 'success',
|
|
231
|
+
user: result.user
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
resolve({
|
|
236
|
+
status: 'error',
|
|
237
|
+
message: result.message,
|
|
238
|
+
error: result.error
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
resolve({
|
|
244
|
+
status: 'verificationRequired',
|
|
245
|
+
message: `A verification code has been sent to ${email}`,
|
|
246
|
+
verificationDestination: email
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}));
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const cacheCreds = (provider) => {
|
|
255
|
+
let credsPromise = null;
|
|
256
|
+
let t = Date.now();
|
|
257
|
+
return () => __awaiter(void 0, void 0, void 0, function* () {
|
|
258
|
+
if (!credsPromise || (Date.now() - t) > 1000 * 60 * 3) {
|
|
259
|
+
t = Date.now();
|
|
260
|
+
credsPromise = provider();
|
|
261
|
+
}
|
|
262
|
+
return yield credsPromise;
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
//# 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,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAExE,OAAO,EAAmB,cAAc,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAmG,eAAe,EAA2B,eAAe,EAAgD,WAAW,EAAuB,MAAM,cAAc,CAAC;AAC1Q,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,oBAAoB,EAAE,eAAe,EAAqE,MAAM,4BAA4B,CAAC;AAC1L,OAAO,EACH,0BAA0B,EAC1B,4BAA4B,EAC5B,sBAAsB,EACzB,MAAM,mCAAmC,CAAC;AAE3C,MAAM,gBAAgB,GAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC,CAAC;AAErF;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAyB,EAAE,CAAC;AAG/D,MAAM,UAAU,GAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,OAAO,GAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AAEpC,MAAM,CAAC,MAAM,uBAAuB,GAAC,qBAAqB,CAAC;AAU3D,MAAM,OAAO,mBAAmB;IAsB5B,YAAY,MAAgC;QAR5B,SAAI,GAAC,uBAAuB,CAAC;QAe5B,gBAAW,GAAgC,EAAE,CAAC;QAL3D,IAAI,CAAC,QAAQ,GAAC,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAC,MAAM,CAAC;QACnB,IAAI,CAAC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AC;4BACd,OAAO,CAAC;gCACJ,MAAM,EAAC,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;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,8 @@
|
|
|
1
|
+
import { AwsAuthProviders } from "@iyio/aws";
|
|
2
|
+
import { AuthProviders } from "@iyio/common";
|
|
3
|
+
import { CognitoAuthProvider, CognitoAuthProviderType } from "./CognitoAuthProvider";
|
|
4
|
+
export const cognitoAuthProviderModule = (reg) => {
|
|
5
|
+
reg.addProvider(AuthProviders, scope => CognitoAuthProvider.fromScope(scope), CognitoAuthProviderType)
|
|
6
|
+
.and(AwsAuthProviders);
|
|
7
|
+
};
|
|
8
|
+
//# 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,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAqB,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAErF,MAAM,CAAC,MAAM,yBAAyB,GAAC,CAAC,GAAqB,EAAC,EAAE;IAC5D,GAAG,CAAC,WAAW,CAAC,aAAa,EAAC,KAAK,CAAA,EAAE,CAAA,mBAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,EAAC,uBAAuB,CAAC;SAC7F,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAC/B,CAAC,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const cognitoIdentityPoolIdParam: import("@iyio/common").ParamTypeDef<string>;
|
|
2
|
+
export declare const cognitoUserPoolClientIdParam: import("@iyio/common").ParamTypeDef<string>;
|
|
3
|
+
export declare const cognitoUserPoolIdParam: import("@iyio/common").ParamTypeDef<string>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { defineStringParam } from "@iyio/common";
|
|
2
|
+
export const cognitoIdentityPoolIdParam = defineStringParam('cognitoIdentityPoolId');
|
|
3
|
+
export const cognitoUserPoolClientIdParam = defineStringParam('cognitoUserPoolClientId');
|
|
4
|
+
export const cognitoUserPoolIdParam = defineStringParam('cognitoUserPoolId');
|
|
5
|
+
//# 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,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,CAAC,MAAM,0BAA0B,GAAC,iBAAiB,CAAC,uBAAuB,CAAC,CAAC;AACnF,MAAM,CAAC,MAAM,4BAA4B,GAAC,iBAAiB,CAAC,yBAAyB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,sBAAsB,GAAC,iBAAiB,CAAC,mBAAmB,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,41 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { AwsAuthProviders } from "@iyio/aws";
|
|
3
|
+
import { AuthProviders, authService, createScope, MemoryStore, shortUuid, storeRoot, uuid } from "@iyio/common";
|
|
4
|
+
import { fail } from "assert";
|
|
5
|
+
import { CognitoAuthProvider } from "./CognitoAuthProvider";
|
|
6
|
+
export const useTempCognitoUser = (module, work) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7
|
+
let provider = undefined;
|
|
8
|
+
const scope = createScope(reg => {
|
|
9
|
+
reg.use(module);
|
|
10
|
+
provider = reg
|
|
11
|
+
.addProvider(AuthProviders, scope => CognitoAuthProvider.fromScope(scope))
|
|
12
|
+
.and(AwsAuthProviders)
|
|
13
|
+
.getValue();
|
|
14
|
+
});
|
|
15
|
+
storeRoot(scope).mount('/', new MemoryStore());
|
|
16
|
+
const email = `unit-test.${uuid()}@iyio.io`;
|
|
17
|
+
const password = 'P1!p-' + shortUuid();
|
|
18
|
+
console.log(`Registering ${email}, ${password}`);
|
|
19
|
+
const result = yield authService(scope).registerEmailPasswordAsync(email, password);
|
|
20
|
+
if (result.status !== 'success') {
|
|
21
|
+
console.log(result);
|
|
22
|
+
fail('Result not success');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
yield work(scope, result.user, provider.config);
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
const deleteResult = yield authService(scope).deleteAsync(result.user);
|
|
30
|
+
if (deleteResult.status === 'error') {
|
|
31
|
+
fail('Failed to delete user');
|
|
32
|
+
}
|
|
33
|
+
else if (deleteResult.status === 'pending') {
|
|
34
|
+
console.warn('Delete user pending');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.log(`${email} deleted`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
//# 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,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAY,WAAW,EAAE,WAAW,EAAsB,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC9I,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAA6B,MAAM,uBAAuB,CAAC;AAEvF,MAAM,CAAC,MAAM,kBAAkB,GAAC,CAAO,MAAkB,EAAC,IAAgF,EAAC,EAAE;IAEzI,IAAI,QAAQ,GAA+B,SAAS,CAAC;IAErD,MAAM,KAAK,GAAC,WAAW,CAAC,GAAG,CAAA,EAAE;QACzB,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAChB,QAAQ,GAAC,GAAG;aACP,WAAW,CAAC,aAAa,EAAC,KAAK,CAAA,EAAE,CAAA,mBAAmB,CAAC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2
|
"name": "@iyio/aws-credential-providers",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@iyio/aws": "0.0
|
|
10
|
-
"@iyio/common": "0.0
|
|
9
|
+
"@iyio/aws": "0.1.0",
|
|
10
|
+
"@iyio/common": "0.1.0",
|
|
11
11
|
"rxjs": "^7.5.7",
|
|
12
|
+
"date-fns": "^2.29.3",
|
|
12
13
|
"uuid": "^9.0.0",
|
|
13
14
|
"@aws-sdk/credential-providers": "^3.199.0",
|
|
14
15
|
"amazon-cognito-identity-js": "^5.2.12",
|
|
15
16
|
"tslib": "^2.3.0"
|
|
16
|
-
}
|
|
17
|
+
},
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"module": "./esm/src/index.js"
|
|
17
20
|
}
|
package/src/package.json
ADDED