@vardario/cognito-client 3.0.0 → 4.0.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/lib/cognito-client.d.ts +16 -16
- package/lib/cognito-client.js +77 -52
- package/lib/error.d.ts +47 -7
- package/lib/error.js +67 -5
- package/package.json +7 -2
package/lib/cognito-client.d.ts
CHANGED
|
@@ -261,7 +261,7 @@ export interface DecodedTokens {
|
|
|
261
261
|
* List of used and supported Cognito API calls.
|
|
262
262
|
* @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_Operations.html for more details
|
|
263
263
|
*/
|
|
264
|
-
export declare enum
|
|
264
|
+
export declare enum ServiceTarget {
|
|
265
265
|
InitiateAuth = "InitiateAuth",
|
|
266
266
|
RespondToAuthChallenge = "RespondToAuthChallenge",
|
|
267
267
|
SignUp = "SignUp",
|
|
@@ -279,7 +279,7 @@ export declare enum CognitoServiceTarget {
|
|
|
279
279
|
* Cognito supported federated identities public providers.
|
|
280
280
|
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-identity.html for more information.
|
|
281
281
|
*/
|
|
282
|
-
export declare enum
|
|
282
|
+
export declare enum IdentityProvider {
|
|
283
283
|
Cognito = "COGNITO",
|
|
284
284
|
Google = "Google",
|
|
285
285
|
Facebook = "Facebook",
|
|
@@ -306,7 +306,7 @@ export interface ChallengeResponse {
|
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
308
|
export declare function authResultToSession(authenticationResult: AuthenticationResult): Session;
|
|
309
|
-
export declare function cognitoRequest(body: object, serviceTarget:
|
|
309
|
+
export declare function cognitoRequest(body: object, serviceTarget: ServiceTarget, cognitoEndpoint: string): Promise<any>;
|
|
310
310
|
/**
|
|
311
311
|
* Lightweight AWS Cogito client without any AWS SDK dependencies.
|
|
312
312
|
*/
|
|
@@ -326,7 +326,7 @@ export declare class CognitoClient {
|
|
|
326
326
|
* @param username Username
|
|
327
327
|
* @param password Password
|
|
328
328
|
*
|
|
329
|
-
* @throws {
|
|
329
|
+
* @throws {InitAuthError, CognitoRespondToAuthChallengeError}
|
|
330
330
|
*/
|
|
331
331
|
authenticateUserSrp(username: string, password: string): Promise<Session>;
|
|
332
332
|
/**
|
|
@@ -336,7 +336,7 @@ export declare class CognitoClient {
|
|
|
336
336
|
*
|
|
337
337
|
* @param username Username
|
|
338
338
|
* @param password Password
|
|
339
|
-
* @throws {
|
|
339
|
+
* @throws {InitAuthError}
|
|
340
340
|
*/
|
|
341
341
|
authenticateUser(username: string, password: string): Promise<Session>;
|
|
342
342
|
/**
|
|
@@ -345,7 +345,7 @@ export declare class CognitoClient {
|
|
|
345
345
|
* @param refreshToken Refresh token from a previous session.
|
|
346
346
|
* @param username Username is required when using a client secret and needs to be the cognito user id.
|
|
347
347
|
* @returns @see Session
|
|
348
|
-
* @throws {
|
|
348
|
+
* @throws {InitAuthError}
|
|
349
349
|
*/
|
|
350
350
|
refreshSession(refreshToken: string, username?: string): Promise<Session>;
|
|
351
351
|
/**
|
|
@@ -353,7 +353,7 @@ export declare class CognitoClient {
|
|
|
353
353
|
* @param username Username
|
|
354
354
|
* @param password Password
|
|
355
355
|
*
|
|
356
|
-
* @throws {
|
|
356
|
+
* @throws {SignUpError}
|
|
357
357
|
*/
|
|
358
358
|
signUp(username: string, password: string, userAttributes?: UserAttribute[]): Promise<{
|
|
359
359
|
id: string;
|
|
@@ -365,7 +365,7 @@ export declare class CognitoClient {
|
|
|
365
365
|
* @param username Username
|
|
366
366
|
* @param code Confirmation code the user gets through the registration E-Mail
|
|
367
367
|
*
|
|
368
|
-
* @throws {
|
|
368
|
+
* @throws {ConfirmSignUpError}
|
|
369
369
|
*/
|
|
370
370
|
confirmSignUp(username: string, code: string): Promise<void>;
|
|
371
371
|
/**
|
|
@@ -373,7 +373,7 @@ export declare class CognitoClient {
|
|
|
373
373
|
* @param currentPassword Current user password.
|
|
374
374
|
* @param newPassword New user password.
|
|
375
375
|
*
|
|
376
|
-
* @throws {
|
|
376
|
+
* @throws {ChangePasswordError}
|
|
377
377
|
*/
|
|
378
378
|
changePassword(currentPassword: string, newPassword: string, accessToken: string): Promise<void>;
|
|
379
379
|
/**
|
|
@@ -382,7 +382,7 @@ export declare class CognitoClient {
|
|
|
382
382
|
* @param userAttributes List of user attributes to update.
|
|
383
383
|
* @param accessToken Access token of the current user.
|
|
384
384
|
*
|
|
385
|
-
* @throws {
|
|
385
|
+
* @throws {UpdateUserAttributesError}
|
|
386
386
|
*/
|
|
387
387
|
updateUserAttributes(userAttributes: UserAttribute[], accessToken: string): Promise<void>;
|
|
388
388
|
/**
|
|
@@ -392,7 +392,7 @@ export declare class CognitoClient {
|
|
|
392
392
|
* @param code Verification code
|
|
393
393
|
* @param accessToken Access token of the current user.
|
|
394
394
|
*
|
|
395
|
-
* @throws {
|
|
395
|
+
* @throws {VerifyUserAttributeError}
|
|
396
396
|
*/
|
|
397
397
|
verifyUserAttribute(attributeName: string, code: string, accessToken: string): Promise<void>;
|
|
398
398
|
/**
|
|
@@ -400,14 +400,14 @@ export declare class CognitoClient {
|
|
|
400
400
|
*
|
|
401
401
|
* @param refreshToken Refresh token from a previous session.
|
|
402
402
|
* @param username Username is required when using a client secret and needs to be the cognito user id.
|
|
403
|
-
* @throws {
|
|
403
|
+
* @throws {RevokeTokenError}
|
|
404
404
|
*/
|
|
405
405
|
revokeToken(refreshToken: string): Promise<void>;
|
|
406
406
|
/**
|
|
407
407
|
* Request forgot password.
|
|
408
408
|
* @param username Username
|
|
409
409
|
*
|
|
410
|
-
* @throws {
|
|
410
|
+
* @throws {ForgotPasswordError}
|
|
411
411
|
*/
|
|
412
412
|
forgotPassword(username: string): Promise<void>;
|
|
413
413
|
/**
|
|
@@ -417,14 +417,14 @@ export declare class CognitoClient {
|
|
|
417
417
|
* @param newPassword New password
|
|
418
418
|
* @param confirmationCode Confirmation code which the user got through E-mail
|
|
419
419
|
*
|
|
420
|
-
* @throws {
|
|
420
|
+
* @throws {ConfirmForgotPasswordError}
|
|
421
421
|
*/
|
|
422
422
|
confirmForgotPassword(username: string, newPassword: string, confirmationCode: string): Promise<void>;
|
|
423
423
|
/**
|
|
424
424
|
* Triggers cognito to resend the confirmation code
|
|
425
425
|
* @param username Username
|
|
426
426
|
*
|
|
427
|
-
* @throws {
|
|
427
|
+
* @throws {ResendConfirmationCodeError}
|
|
428
428
|
*/
|
|
429
429
|
resendConfirmationCode(username: string): Promise<void>;
|
|
430
430
|
/**
|
|
@@ -436,7 +436,7 @@ export declare class CognitoClient {
|
|
|
436
436
|
*
|
|
437
437
|
* @throws {Error}
|
|
438
438
|
*/
|
|
439
|
-
generateOAuthSignInUrl(identityProvider?:
|
|
439
|
+
generateOAuthSignInUrl(identityProvider?: IdentityProvider): Promise<{
|
|
440
440
|
url: string;
|
|
441
441
|
state: string;
|
|
442
442
|
pkce: string;
|
package/lib/cognito-client.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
import hashJs from 'hash.js';
|
|
2
2
|
import { BigInteger } from 'jsbn';
|
|
3
3
|
import { Buffer } from 'buffer';
|
|
4
|
-
import {
|
|
4
|
+
import { ChangePasswordError, ConfirmForgotPasswordError, ConfirmSignUpError, ForgotPasswordError, GlobalSignOutError, InitAuthError, ResendConfirmationCodeError, RespondToAuthChallengeError, RevokeTokenError, SignUpError, UpdateUserAttributesError, VerifyUserAttributeError } from './error.js';
|
|
5
5
|
import { calculateSecretHash, calculateSignature, calculateU, decodeJwt, generateA, generateSmallA, getPasswordAuthenticationKey, randomBytes } from './utils.js';
|
|
6
6
|
/**
|
|
7
7
|
* List of used and supported Cognito API calls.
|
|
8
8
|
* @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_Operations.html for more details
|
|
9
9
|
*/
|
|
10
|
-
export var
|
|
11
|
-
(function (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
})(
|
|
10
|
+
export var ServiceTarget;
|
|
11
|
+
(function (ServiceTarget) {
|
|
12
|
+
ServiceTarget["InitiateAuth"] = "InitiateAuth";
|
|
13
|
+
ServiceTarget["RespondToAuthChallenge"] = "RespondToAuthChallenge";
|
|
14
|
+
ServiceTarget["SignUp"] = "SignUp";
|
|
15
|
+
ServiceTarget["ConfirmSignUp"] = "ConfirmSignUp";
|
|
16
|
+
ServiceTarget["ChangePassword"] = "ChangePassword";
|
|
17
|
+
ServiceTarget["RevokeToken"] = "RevokeToken";
|
|
18
|
+
ServiceTarget["ForgotPassword"] = "ForgotPassword";
|
|
19
|
+
ServiceTarget["ConfirmForgotPassword"] = "ConfirmForgotPassword";
|
|
20
|
+
ServiceTarget["ResendConfirmationCode"] = "ResendConfirmationCode";
|
|
21
|
+
ServiceTarget["UpdateUserAttributes"] = "UpdateUserAttributes";
|
|
22
|
+
ServiceTarget["VerifyUserAttribute"] = "VerifyUserAttribute";
|
|
23
|
+
ServiceTarget["GlobalSignOut"] = "GlobalSignOut";
|
|
24
|
+
})(ServiceTarget || (ServiceTarget = {}));
|
|
25
25
|
/**
|
|
26
26
|
* Cognito supported federated identities public providers.
|
|
27
27
|
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-identity.html for more information.
|
|
28
28
|
*/
|
|
29
|
-
export var
|
|
30
|
-
(function (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
})(
|
|
29
|
+
export var IdentityProvider;
|
|
30
|
+
(function (IdentityProvider) {
|
|
31
|
+
IdentityProvider["Cognito"] = "COGNITO";
|
|
32
|
+
IdentityProvider["Google"] = "Google";
|
|
33
|
+
IdentityProvider["Facebook"] = "Facebook";
|
|
34
|
+
IdentityProvider["Amazon"] = "LoginWithAmazon";
|
|
35
|
+
IdentityProvider["Apple"] = "SignInWithApple";
|
|
36
|
+
})(IdentityProvider || (IdentityProvider = {}));
|
|
37
37
|
export function authResultToSession(authenticationResult) {
|
|
38
38
|
return {
|
|
39
39
|
accessToken: authenticationResult.AccessToken,
|
|
@@ -73,8 +73,33 @@ export async function cognitoRequest(body, serviceTarget, cognitoEndpoint) {
|
|
|
73
73
|
const cognitoException = sanitizeErrorType(cognitoResponse.headers.get('X-Amzn-ErrorType') ??
|
|
74
74
|
cognitoResponseBody.code ??
|
|
75
75
|
cognitoResponseBody.__type ??
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
'Unknown');
|
|
77
|
+
switch (serviceTarget) {
|
|
78
|
+
case ServiceTarget.InitiateAuth:
|
|
79
|
+
throw new InitAuthError(errorMessage, cognitoException);
|
|
80
|
+
case ServiceTarget.RespondToAuthChallenge:
|
|
81
|
+
throw new RespondToAuthChallengeError(errorMessage, cognitoException);
|
|
82
|
+
case ServiceTarget.SignUp:
|
|
83
|
+
throw new SignUpError(errorMessage, cognitoException);
|
|
84
|
+
case ServiceTarget.ConfirmSignUp:
|
|
85
|
+
throw new ConfirmSignUpError(errorMessage, cognitoException);
|
|
86
|
+
case ServiceTarget.ChangePassword:
|
|
87
|
+
throw new ChangePasswordError(errorMessage, cognitoException);
|
|
88
|
+
case ServiceTarget.RevokeToken:
|
|
89
|
+
throw new RevokeTokenError(errorMessage, cognitoException);
|
|
90
|
+
case ServiceTarget.ForgotPassword:
|
|
91
|
+
throw new ForgotPasswordError(errorMessage, cognitoException);
|
|
92
|
+
case ServiceTarget.ConfirmForgotPassword:
|
|
93
|
+
throw new ConfirmForgotPasswordError(errorMessage, cognitoException);
|
|
94
|
+
case ServiceTarget.ResendConfirmationCode:
|
|
95
|
+
throw new ResendConfirmationCodeError(errorMessage, cognitoException);
|
|
96
|
+
case ServiceTarget.UpdateUserAttributes:
|
|
97
|
+
throw new UpdateUserAttributesError(errorMessage, cognitoException);
|
|
98
|
+
case ServiceTarget.VerifyUserAttribute:
|
|
99
|
+
throw new VerifyUserAttributeError(errorMessage, cognitoException);
|
|
100
|
+
case ServiceTarget.GlobalSignOut:
|
|
101
|
+
throw new GlobalSignOutError(errorMessage, cognitoException);
|
|
102
|
+
}
|
|
78
103
|
}
|
|
79
104
|
/**
|
|
80
105
|
* Lightweight AWS Cogito client without any AWS SDK dependencies.
|
|
@@ -104,7 +129,7 @@ export class CognitoClient {
|
|
|
104
129
|
* @param username Username
|
|
105
130
|
* @param password Password
|
|
106
131
|
*
|
|
107
|
-
* @throws {
|
|
132
|
+
* @throws {InitAuthError, CognitoRespondToAuthChallengeError}
|
|
108
133
|
*/
|
|
109
134
|
async authenticateUserSrp(username, password) {
|
|
110
135
|
const smallA = await generateSmallA();
|
|
@@ -119,7 +144,7 @@ export class CognitoClient {
|
|
|
119
144
|
},
|
|
120
145
|
ClientMetadata: {}
|
|
121
146
|
};
|
|
122
|
-
const challenge = (await cognitoRequest(initiateAuthPayload,
|
|
147
|
+
const challenge = (await cognitoRequest(initiateAuthPayload, ServiceTarget.InitiateAuth, this.cognitoEndpoint));
|
|
123
148
|
const B = new BigInteger(challenge.ChallengeParameters.SRP_B, 16);
|
|
124
149
|
const salt = new BigInteger(challenge.ChallengeParameters.SALT, 16);
|
|
125
150
|
const U = calculateU(A, B);
|
|
@@ -138,7 +163,7 @@ export class CognitoClient {
|
|
|
138
163
|
},
|
|
139
164
|
ClientMetadata: {}
|
|
140
165
|
};
|
|
141
|
-
const { AuthenticationResult } = await cognitoRequest(respondToAuthChallengeRequest,
|
|
166
|
+
const { AuthenticationResult } = await cognitoRequest(respondToAuthChallengeRequest, ServiceTarget.RespondToAuthChallenge, this.cognitoEndpoint);
|
|
142
167
|
return authResultToSession(AuthenticationResult);
|
|
143
168
|
}
|
|
144
169
|
/**
|
|
@@ -148,7 +173,7 @@ export class CognitoClient {
|
|
|
148
173
|
*
|
|
149
174
|
* @param username Username
|
|
150
175
|
* @param password Password
|
|
151
|
-
* @throws {
|
|
176
|
+
* @throws {InitAuthError}
|
|
152
177
|
*/
|
|
153
178
|
async authenticateUser(username, password) {
|
|
154
179
|
const initiateAuthPayload = {
|
|
@@ -161,7 +186,7 @@ export class CognitoClient {
|
|
|
161
186
|
},
|
|
162
187
|
ClientMetadata: {}
|
|
163
188
|
};
|
|
164
|
-
const { AuthenticationResult } = (await cognitoRequest(initiateAuthPayload,
|
|
189
|
+
const { AuthenticationResult } = (await cognitoRequest(initiateAuthPayload, ServiceTarget.InitiateAuth, this.cognitoEndpoint));
|
|
165
190
|
const session = authResultToSession(AuthenticationResult);
|
|
166
191
|
return session;
|
|
167
192
|
}
|
|
@@ -171,7 +196,7 @@ export class CognitoClient {
|
|
|
171
196
|
* @param refreshToken Refresh token from a previous session.
|
|
172
197
|
* @param username Username is required when using a client secret and needs to be the cognito user id.
|
|
173
198
|
* @returns @see Session
|
|
174
|
-
* @throws {
|
|
199
|
+
* @throws {InitAuthError}
|
|
175
200
|
*/
|
|
176
201
|
async refreshSession(refreshToken, username) {
|
|
177
202
|
const refreshTokenPayload = {
|
|
@@ -183,7 +208,7 @@ export class CognitoClient {
|
|
|
183
208
|
},
|
|
184
209
|
ClientMetadata: {}
|
|
185
210
|
};
|
|
186
|
-
const { AuthenticationResult } = (await cognitoRequest(refreshTokenPayload,
|
|
211
|
+
const { AuthenticationResult } = (await cognitoRequest(refreshTokenPayload, ServiceTarget.InitiateAuth, this.cognitoEndpoint));
|
|
187
212
|
if (!AuthenticationResult.RefreshToken) {
|
|
188
213
|
AuthenticationResult.RefreshToken = refreshToken;
|
|
189
214
|
}
|
|
@@ -194,7 +219,7 @@ export class CognitoClient {
|
|
|
194
219
|
* @param username Username
|
|
195
220
|
* @param password Password
|
|
196
221
|
*
|
|
197
|
-
* @throws {
|
|
222
|
+
* @throws {SignUpError}
|
|
198
223
|
*/
|
|
199
224
|
async signUp(username, password, userAttributes) {
|
|
200
225
|
const signUpRequest = {
|
|
@@ -204,7 +229,7 @@ export class CognitoClient {
|
|
|
204
229
|
UserAttributes: userAttributes,
|
|
205
230
|
SecretHash: this.clientSecret && calculateSecretHash(this.clientSecret, this.userPoolClientId, username)
|
|
206
231
|
};
|
|
207
|
-
const data = await cognitoRequest(signUpRequest,
|
|
232
|
+
const data = await cognitoRequest(signUpRequest, ServiceTarget.SignUp, this.cognitoEndpoint);
|
|
208
233
|
return {
|
|
209
234
|
id: data.UserSub,
|
|
210
235
|
confirmed: data.UserConfirmed
|
|
@@ -216,7 +241,7 @@ export class CognitoClient {
|
|
|
216
241
|
* @param username Username
|
|
217
242
|
* @param code Confirmation code the user gets through the registration E-Mail
|
|
218
243
|
*
|
|
219
|
-
* @throws {
|
|
244
|
+
* @throws {ConfirmSignUpError}
|
|
220
245
|
*/
|
|
221
246
|
async confirmSignUp(username, code) {
|
|
222
247
|
const confirmSignUpRequest = {
|
|
@@ -225,14 +250,14 @@ export class CognitoClient {
|
|
|
225
250
|
Username: username,
|
|
226
251
|
SecretHash: this.clientSecret && calculateSecretHash(this.clientSecret, this.userPoolClientId, username)
|
|
227
252
|
};
|
|
228
|
-
await cognitoRequest(confirmSignUpRequest,
|
|
253
|
+
await cognitoRequest(confirmSignUpRequest, ServiceTarget.ConfirmSignUp, this.cognitoEndpoint);
|
|
229
254
|
}
|
|
230
255
|
/**
|
|
231
256
|
*
|
|
232
257
|
* @param currentPassword Current user password.
|
|
233
258
|
* @param newPassword New user password.
|
|
234
259
|
*
|
|
235
|
-
* @throws {
|
|
260
|
+
* @throws {ChangePasswordError}
|
|
236
261
|
*/
|
|
237
262
|
async changePassword(currentPassword, newPassword, accessToken) {
|
|
238
263
|
const changePasswordPayload = {
|
|
@@ -240,7 +265,7 @@ export class CognitoClient {
|
|
|
240
265
|
ProposedPassword: newPassword,
|
|
241
266
|
AccessToken: accessToken
|
|
242
267
|
};
|
|
243
|
-
await cognitoRequest(changePasswordPayload,
|
|
268
|
+
await cognitoRequest(changePasswordPayload, ServiceTarget.ChangePassword, this.cognitoEndpoint);
|
|
244
269
|
}
|
|
245
270
|
/**
|
|
246
271
|
* Updates the user attributes.
|
|
@@ -248,14 +273,14 @@ export class CognitoClient {
|
|
|
248
273
|
* @param userAttributes List of user attributes to update.
|
|
249
274
|
* @param accessToken Access token of the current user.
|
|
250
275
|
*
|
|
251
|
-
* @throws {
|
|
276
|
+
* @throws {UpdateUserAttributesError}
|
|
252
277
|
*/
|
|
253
278
|
async updateUserAttributes(userAttributes, accessToken) {
|
|
254
279
|
const updateUserAttributesPayload = {
|
|
255
280
|
UserAttributes: userAttributes,
|
|
256
281
|
AccessToken: accessToken
|
|
257
282
|
};
|
|
258
|
-
await cognitoRequest(updateUserAttributesPayload,
|
|
283
|
+
await cognitoRequest(updateUserAttributesPayload, ServiceTarget.UpdateUserAttributes, this.cognitoEndpoint);
|
|
259
284
|
}
|
|
260
285
|
/**
|
|
261
286
|
* Verifies a given user attribute
|
|
@@ -264,7 +289,7 @@ export class CognitoClient {
|
|
|
264
289
|
* @param code Verification code
|
|
265
290
|
* @param accessToken Access token of the current user.
|
|
266
291
|
*
|
|
267
|
-
* @throws {
|
|
292
|
+
* @throws {VerifyUserAttributeError}
|
|
268
293
|
*/
|
|
269
294
|
async verifyUserAttribute(attributeName, code, accessToken) {
|
|
270
295
|
const verifyUserAttributePayload = {
|
|
@@ -272,14 +297,14 @@ export class CognitoClient {
|
|
|
272
297
|
Code: code,
|
|
273
298
|
AccessToken: accessToken
|
|
274
299
|
};
|
|
275
|
-
await cognitoRequest(verifyUserAttributePayload,
|
|
300
|
+
await cognitoRequest(verifyUserAttributePayload, ServiceTarget.VerifyUserAttribute, this.cognitoEndpoint);
|
|
276
301
|
}
|
|
277
302
|
/**
|
|
278
303
|
* Revokes all of the access tokens generated by, and at the same time as, the specified refresh token. After a token is revoked, you can't use the revoked token to access Amazon Cognito user APIs, or to authorize access to your resource server.
|
|
279
304
|
*
|
|
280
305
|
* @param refreshToken Refresh token from a previous session.
|
|
281
306
|
* @param username Username is required when using a client secret and needs to be the cognito user id.
|
|
282
|
-
* @throws {
|
|
307
|
+
* @throws {RevokeTokenError}
|
|
283
308
|
*/
|
|
284
309
|
async revokeToken(refreshToken) {
|
|
285
310
|
const revokeTokenPayload = {
|
|
@@ -287,13 +312,13 @@ export class CognitoClient {
|
|
|
287
312
|
ClientId: this.userPoolClientId,
|
|
288
313
|
ClientSecret: this.clientSecret
|
|
289
314
|
};
|
|
290
|
-
await cognitoRequest(revokeTokenPayload,
|
|
315
|
+
await cognitoRequest(revokeTokenPayload, ServiceTarget.RevokeToken, this.cognitoEndpoint);
|
|
291
316
|
}
|
|
292
317
|
/**
|
|
293
318
|
* Request forgot password.
|
|
294
319
|
* @param username Username
|
|
295
320
|
*
|
|
296
|
-
* @throws {
|
|
321
|
+
* @throws {ForgotPasswordError}
|
|
297
322
|
*/
|
|
298
323
|
async forgotPassword(username) {
|
|
299
324
|
const forgotPasswordRequest = {
|
|
@@ -301,7 +326,7 @@ export class CognitoClient {
|
|
|
301
326
|
Username: username,
|
|
302
327
|
SecretHash: this.clientSecret && calculateSecretHash(this.clientSecret, this.userPoolClientId, username)
|
|
303
328
|
};
|
|
304
|
-
await cognitoRequest(forgotPasswordRequest,
|
|
329
|
+
await cognitoRequest(forgotPasswordRequest, ServiceTarget.ForgotPassword, this.cognitoEndpoint);
|
|
305
330
|
}
|
|
306
331
|
/**
|
|
307
332
|
* Confirms the new password via the given code send via cognito triggered by @see forgotPassword .
|
|
@@ -310,7 +335,7 @@ export class CognitoClient {
|
|
|
310
335
|
* @param newPassword New password
|
|
311
336
|
* @param confirmationCode Confirmation code which the user got through E-mail
|
|
312
337
|
*
|
|
313
|
-
* @throws {
|
|
338
|
+
* @throws {ConfirmForgotPasswordError}
|
|
314
339
|
*/
|
|
315
340
|
async confirmForgotPassword(username, newPassword, confirmationCode) {
|
|
316
341
|
const confirmForgotPasswordRequest = {
|
|
@@ -320,13 +345,13 @@ export class CognitoClient {
|
|
|
320
345
|
Password: newPassword,
|
|
321
346
|
SecretHash: this.clientSecret && calculateSecretHash(this.clientSecret, this.userPoolClientId, username)
|
|
322
347
|
};
|
|
323
|
-
await cognitoRequest(confirmForgotPasswordRequest,
|
|
348
|
+
await cognitoRequest(confirmForgotPasswordRequest, ServiceTarget.ConfirmForgotPassword, this.cognitoEndpoint);
|
|
324
349
|
}
|
|
325
350
|
/**
|
|
326
351
|
* Triggers cognito to resend the confirmation code
|
|
327
352
|
* @param username Username
|
|
328
353
|
*
|
|
329
|
-
* @throws {
|
|
354
|
+
* @throws {ResendConfirmationCodeError}
|
|
330
355
|
*/
|
|
331
356
|
async resendConfirmationCode(username) {
|
|
332
357
|
const resendConfirmationCodeRequest = {
|
|
@@ -334,7 +359,7 @@ export class CognitoClient {
|
|
|
334
359
|
Username: username,
|
|
335
360
|
SecretHash: this.clientSecret && calculateSecretHash(this.clientSecret, this.userPoolClientId, username)
|
|
336
361
|
};
|
|
337
|
-
await cognitoRequest(resendConfirmationCodeRequest,
|
|
362
|
+
await cognitoRequest(resendConfirmationCodeRequest, ServiceTarget.ResendConfirmationCode, this.cognitoEndpoint);
|
|
338
363
|
}
|
|
339
364
|
/**
|
|
340
365
|
* Returns a link to Cognito`s Hosted UI for OAuth2 authentication.
|
|
@@ -426,6 +451,6 @@ export class CognitoClient {
|
|
|
426
451
|
const globalSignOutPayload = {
|
|
427
452
|
AccessToken: accessToken
|
|
428
453
|
};
|
|
429
|
-
await cognitoRequest(globalSignOutPayload,
|
|
454
|
+
await cognitoRequest(globalSignOutPayload, ServiceTarget.GlobalSignOut, this.cognitoEndpoint);
|
|
430
455
|
}
|
|
431
456
|
}
|
package/lib/error.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export declare enum CognitoCommonException {
|
|
2
|
-
Unknown = "Unknown"
|
|
3
|
-
}
|
|
4
1
|
export declare enum AssociateSoftwareTokenException {
|
|
5
2
|
ConcurrentModificationException = "ConcurrentModificationException",
|
|
6
3
|
ForbiddenException = "ForbiddenException",
|
|
@@ -351,8 +348,51 @@ export declare enum RevokeTokenException {
|
|
|
351
348
|
UnsupportedOperationException = "UnsupportedOperationException",
|
|
352
349
|
UnsupportedTokenTypeException = "UnsupportedTokenTypeException"
|
|
353
350
|
}
|
|
354
|
-
export
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
351
|
+
export declare class InitAuthError extends Error {
|
|
352
|
+
readonly cognitoException: InitiateAuthException;
|
|
353
|
+
constructor(message: string, cognitoException: InitiateAuthException);
|
|
354
|
+
}
|
|
355
|
+
export declare class RespondToAuthChallengeError extends Error {
|
|
356
|
+
readonly cognitoException: RespondToAuthChallengeException;
|
|
357
|
+
constructor(message: string, cognitoException: RespondToAuthChallengeException);
|
|
358
|
+
}
|
|
359
|
+
export declare class SignUpError extends Error {
|
|
360
|
+
readonly cognitoException: SignUpException;
|
|
361
|
+
constructor(message: string, cognitoException: SignUpException);
|
|
362
|
+
}
|
|
363
|
+
export declare class ConfirmSignUpError extends Error {
|
|
364
|
+
readonly cognitoException: ConfirmSignUpException;
|
|
365
|
+
constructor(message: string, cognitoException: ConfirmSignUpException);
|
|
366
|
+
}
|
|
367
|
+
export declare class ChangePasswordError extends Error {
|
|
368
|
+
readonly cognitoException: ChangePasswordException;
|
|
369
|
+
constructor(message: string, cognitoException: ChangePasswordException);
|
|
370
|
+
}
|
|
371
|
+
export declare class RevokeTokenError extends Error {
|
|
372
|
+
readonly cognitoException: RevokeTokenException;
|
|
373
|
+
constructor(message: string, cognitoException: RevokeTokenException);
|
|
374
|
+
}
|
|
375
|
+
export declare class ForgotPasswordError extends Error {
|
|
376
|
+
readonly cognitoException: ForgotPasswordException;
|
|
377
|
+
constructor(message: string, cognitoException: ForgotPasswordException);
|
|
378
|
+
}
|
|
379
|
+
export declare class ConfirmForgotPasswordError extends Error {
|
|
380
|
+
readonly cognitoException: ConfirmForgotPasswordException;
|
|
381
|
+
constructor(message: string, cognitoException: ConfirmForgotPasswordException);
|
|
382
|
+
}
|
|
383
|
+
export declare class ResendConfirmationCodeError extends Error {
|
|
384
|
+
readonly cognitoException: ResendConfirmationException;
|
|
385
|
+
constructor(message: string, cognitoException: ResendConfirmationException);
|
|
386
|
+
}
|
|
387
|
+
export declare class UpdateUserAttributesError extends Error {
|
|
388
|
+
readonly cognitoException: UpdateUserAttributesException;
|
|
389
|
+
constructor(message: string, cognitoException: UpdateUserAttributesException);
|
|
390
|
+
}
|
|
391
|
+
export declare class VerifyUserAttributeError extends Error {
|
|
392
|
+
readonly cognitoException: VerifyUserAttributeException;
|
|
393
|
+
constructor(message: string, cognitoException: VerifyUserAttributeException);
|
|
394
|
+
}
|
|
395
|
+
export declare class GlobalSignOutError extends Error {
|
|
396
|
+
readonly cognitoException: GlobalSignOutException;
|
|
397
|
+
constructor(message: string, cognitoException: GlobalSignOutException);
|
|
358
398
|
}
|
package/lib/error.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export var CognitoCommonException;
|
|
2
|
-
(function (CognitoCommonException) {
|
|
3
|
-
CognitoCommonException["Unknown"] = "Unknown";
|
|
4
|
-
})(CognitoCommonException || (CognitoCommonException = {}));
|
|
5
1
|
export var AssociateSoftwareTokenException;
|
|
6
2
|
(function (AssociateSoftwareTokenException) {
|
|
7
3
|
AssociateSoftwareTokenException["ConcurrentModificationException"] = "ConcurrentModificationException";
|
|
@@ -377,7 +373,73 @@ export var RevokeTokenException;
|
|
|
377
373
|
RevokeTokenException["UnsupportedOperationException"] = "UnsupportedOperationException";
|
|
378
374
|
RevokeTokenException["UnsupportedTokenTypeException"] = "UnsupportedTokenTypeException";
|
|
379
375
|
})(RevokeTokenException || (RevokeTokenException = {}));
|
|
380
|
-
export class
|
|
376
|
+
export class InitAuthError extends Error {
|
|
377
|
+
constructor(message, cognitoException) {
|
|
378
|
+
super(message);
|
|
379
|
+
this.cognitoException = cognitoException;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
export class RespondToAuthChallengeError extends Error {
|
|
383
|
+
constructor(message, cognitoException) {
|
|
384
|
+
super(message);
|
|
385
|
+
this.cognitoException = cognitoException;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
export class SignUpError extends Error {
|
|
389
|
+
constructor(message, cognitoException) {
|
|
390
|
+
super(message);
|
|
391
|
+
this.cognitoException = cognitoException;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
export class ConfirmSignUpError extends Error {
|
|
395
|
+
constructor(message, cognitoException) {
|
|
396
|
+
super(message);
|
|
397
|
+
this.cognitoException = cognitoException;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
export class ChangePasswordError extends Error {
|
|
401
|
+
constructor(message, cognitoException) {
|
|
402
|
+
super(message);
|
|
403
|
+
this.cognitoException = cognitoException;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
export class RevokeTokenError extends Error {
|
|
407
|
+
constructor(message, cognitoException) {
|
|
408
|
+
super(message);
|
|
409
|
+
this.cognitoException = cognitoException;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
export class ForgotPasswordError extends Error {
|
|
413
|
+
constructor(message, cognitoException) {
|
|
414
|
+
super(message);
|
|
415
|
+
this.cognitoException = cognitoException;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
export class ConfirmForgotPasswordError extends Error {
|
|
419
|
+
constructor(message, cognitoException) {
|
|
420
|
+
super(message);
|
|
421
|
+
this.cognitoException = cognitoException;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
export class ResendConfirmationCodeError extends Error {
|
|
425
|
+
constructor(message, cognitoException) {
|
|
426
|
+
super(message);
|
|
427
|
+
this.cognitoException = cognitoException;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
export class UpdateUserAttributesError extends Error {
|
|
431
|
+
constructor(message, cognitoException) {
|
|
432
|
+
super(message);
|
|
433
|
+
this.cognitoException = cognitoException;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
export class VerifyUserAttributeError extends Error {
|
|
437
|
+
constructor(message, cognitoException) {
|
|
438
|
+
super(message);
|
|
439
|
+
this.cognitoException = cognitoException;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
export class GlobalSignOutError extends Error {
|
|
381
443
|
constructor(message, cognitoException) {
|
|
382
444
|
super(message);
|
|
383
445
|
this.cognitoException = cognitoException;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vardario/cognito-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Sahin Vardar",
|
|
@@ -56,5 +56,10 @@
|
|
|
56
56
|
],
|
|
57
57
|
"package.json": "prettier-package-json --write"
|
|
58
58
|
},
|
|
59
|
-
"packageManager": "pnpm@8.10.5"
|
|
59
|
+
"packageManager": "pnpm@8.10.5",
|
|
60
|
+
"release": {
|
|
61
|
+
"branches": [
|
|
62
|
+
"release"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
60
65
|
}
|