@aws-amplify/auth 4.5.8 → 4.5.9-auto-sign-in.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.
@@ -14,5 +14,6 @@ export var AuthErrorStrings;
14
14
  AuthErrorStrings["NO_USER_SESSION"] = "Failed to get the session because the user is empty";
15
15
  AuthErrorStrings["NETWORK_ERROR"] = "Network Error";
16
16
  AuthErrorStrings["DEVICE_CONFIG"] = "Device tracking has not been configured in this User Pool";
17
+ AuthErrorStrings["AUTOSIGNIN_ERROR"] = "Please use your credentials to sign in";
17
18
  })(AuthErrorStrings || (AuthErrorStrings = {}));
18
19
  //# sourceMappingURL=AuthErrorStrings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AuthErrorStrings.js","sourceRoot":"","sources":["../../src/common/AuthErrorStrings.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,gBAeX;AAfD,WAAY,gBAAgB;IAC3B,wDAAoC,CAAA;IACpC,yDAAqC,CAAA;IACrC,gEAA4C,CAAA;IAC5C,+DAA2C,CAAA;IAC3C,2GAAuF,CAAA;IACvF,+DAA2C,CAAA;IAC3C,oEAAgD,CAAA;IAChD,4DAAwC,CAAA;IACxC,2DAAuC,CAAA;IACvC,oDAAgC,CAAA;IAChC,0EAAsD,CAAA;IACtD,2FAAuE,CAAA;IACvE,mDAA+B,CAAA;IAC/B,+FAA2E,CAAA;AAC5E,CAAC,EAfW,gBAAgB,KAAhB,gBAAgB,QAe3B"}
1
+ {"version":3,"file":"AuthErrorStrings.js","sourceRoot":"","sources":["../../src/common/AuthErrorStrings.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,gBAgBX;AAhBD,WAAY,gBAAgB;IAC3B,wDAAoC,CAAA;IACpC,yDAAqC,CAAA;IACrC,gEAA4C,CAAA;IAC5C,+DAA2C,CAAA;IAC3C,2GAAuF,CAAA;IACvF,+DAA2C,CAAA;IAC3C,oEAAgD,CAAA;IAChD,4DAAwC,CAAA;IACxC,2DAAuC,CAAA;IACvC,oDAAgC,CAAA;IAChC,0EAAsD,CAAA;IACtD,2FAAuE,CAAA;IACvE,mDAA+B,CAAA;IAC/B,+FAA2E,CAAA;IAC3E,+EAA2D,CAAA;AAC5D,CAAC,EAhBW,gBAAgB,KAAhB,gBAAgB,QAgB3B"}
@@ -12,6 +12,7 @@ export interface SignUpParams {
12
12
  clientMetadata?: {
13
13
  [key: string]: string;
14
14
  };
15
+ autoSignIn?: AutoSignInOptions;
15
16
  }
16
17
  export interface AuthCache {
17
18
  setItem(): any;
@@ -35,6 +36,7 @@ export interface AuthOptions {
35
36
  identityPoolRegion?: string;
36
37
  clientMetadata?: any;
37
38
  endpoint?: string;
39
+ signUpVerificationMethod?: 'code' | 'link';
38
40
  }
39
41
  export declare enum CognitoHostedUIIdentityProvider {
40
42
  Cognito = "COGNITO",
@@ -133,7 +135,8 @@ export declare enum AuthErrorTypes {
133
135
  NoUserSession = "noUserSession",
134
136
  Default = "default",
135
137
  DeviceConfig = "deviceConfig",
136
- NetworkError = "networkError"
138
+ NetworkError = "networkError",
139
+ AutoSignInError = "autoSignInError"
137
140
  }
138
141
  export declare type AuthErrorMessages = {
139
142
  [key in AuthErrorTypes]: AuthErrorMessage;
@@ -151,6 +154,13 @@ export interface IAuthDevice {
151
154
  id: string;
152
155
  name: string;
153
156
  }
157
+ export interface AutoSignInOptions {
158
+ enabled: boolean;
159
+ clientMetaData?: ClientMetaData;
160
+ validationData?: {
161
+ [key: string]: any;
162
+ };
163
+ }
154
164
  export declare enum GRAPHQL_AUTH_MODE {
155
165
  API_KEY = "API_KEY",
156
166
  AWS_IAM = "AWS_IAM",
@@ -49,6 +49,7 @@ export var AuthErrorTypes;
49
49
  AuthErrorTypes["Default"] = "default";
50
50
  AuthErrorTypes["DeviceConfig"] = "deviceConfig";
51
51
  AuthErrorTypes["NetworkError"] = "networkError";
52
+ AuthErrorTypes["AutoSignInError"] = "autoSignInError";
52
53
  })(AuthErrorTypes || (AuthErrorTypes = {}));
53
54
  export function isUsernamePasswordOpts(obj) {
54
55
  return !!obj.username;
@@ -1 +1 @@
1
- {"version":3,"file":"Auth.js","sourceRoot":"","sources":["../../src/types/Auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA2CH,MAAM,CAAN,IAAY,+BAMX;AAND,WAAY,+BAA+B;IAC1C,sDAAmB,CAAA;IACnB,oDAAiB,CAAA;IACjB,wDAAqB,CAAA;IACrB,6DAA0B,CAAA;IAC1B,4DAAyB,CAAA;AAC1B,CAAC,EANW,+BAA+B,KAA/B,+BAA+B,QAM1C;AAmBD,MAAM,UAAU,wBAAwB,CACvC,GAAQ;IAER,IAAM,IAAI,GAAqC,CAAC,UAAU,CAAC,CAAC;IAC5D,OAAO,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAArB,CAAqB,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC7C,GAAQ;IAER,IAAM,IAAI,GAA2C,CAAC,gBAAgB,CAAC,CAAC;IACxE,OAAO,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAArB,CAAqB,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAQ;IACtC,IAAM,IAAI,GAGH,CAAC,aAAa,CAAC,CAAC;IACvB,OAAO,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAArB,CAAqB,CAAC,CAAC;AACvD,CAAC;AAyCD,MAAM,UAAU,mBAAmB,CAClC,KAAgB;IAEhB,OAA6B,KAAM,CAAC,cAAc,KAAK,SAAS,CAAC;AAClE,CAAC;AA4CD,MA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,CAAA;IACvD,8CAAyB,CAAA;AAC1B,CAAC,EANW,iBAAiB,KAAjB,iBAAiB,QAM5B"}
@@ -10,13 +10,13 @@
10
10
  * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
11
  * and limitations under the License.
12
12
  */
13
- import { JS } from '@aws-amplify/core';
13
+ import { browserOrNode } from '@aws-amplify/core';
14
14
  export default (function (callback) {
15
- if (JS.browserOrNode().isBrowser && window.location) {
15
+ if (browserOrNode().isBrowser && window.location) {
16
16
  var url = window.location.href;
17
17
  callback({ url: url });
18
18
  }
19
- else if (JS.browserOrNode().isNode) {
19
+ else if (browserOrNode().isNode) {
20
20
  // continue building on ssr
21
21
  (function () { }); // noop
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"urlListener.js","sourceRoot":"","sources":["../src/urlListener.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAEvC,gBAAe,UAAA,QAAQ;IACtB,IAAI,EAAE,CAAC,aAAa,EAAE,CAAC,SAAS,IAAI,MAAM,CAAC,QAAQ,EAAE;QACpD,IAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAEjC,QAAQ,CAAC,EAAE,GAAG,KAAA,EAAE,CAAC,CAAC;KAClB;SAAM,IAAI,EAAE,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE;QACrC,2BAA2B;QAC3B,CAAA,cAAO,CAAC,CAAA,CAAC,CAAC,OAAO;KACjB;SAAM;QACN,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;KACjC;AACF,CAAC,EAAC"}
1
+ {"version":3,"file":"urlListener.js","sourceRoot":"","sources":["../src/urlListener.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,gBAAe,UAAA,QAAQ;IACtB,IAAI,aAAa,EAAE,CAAC,SAAS,IAAI,MAAM,CAAC,QAAQ,EAAE;QACjD,IAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAEjC,QAAQ,CAAC,EAAE,GAAG,KAAA,EAAE,CAAC,CAAC;KAClB;SAAM,IAAI,aAAa,EAAE,CAAC,MAAM,EAAE;QAClC,2BAA2B;QAC3B,CAAA,cAAO,CAAC,CAAA,CAAC,CAAC,OAAO;KACjB;SAAM;QACN,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;KACjC;AACF,CAAC,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/auth",
3
- "version": "4.5.8",
3
+ "version": "4.5.9-auto-sign-in.10+c910d5f59",
4
4
  "description": "Auth category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -41,9 +41,9 @@
41
41
  },
42
42
  "homepage": "https://aws-amplify.github.io/",
43
43
  "dependencies": {
44
- "@aws-amplify/cache": "4.0.46",
45
- "@aws-amplify/core": "4.5.8",
46
- "amazon-cognito-identity-js": "5.2.9",
44
+ "@aws-amplify/cache": "4.0.47-auto-sign-in.10+c910d5f59",
45
+ "@aws-amplify/core": "4.5.9-auto-sign-in.10+c910d5f59",
46
+ "amazon-cognito-identity-js": "5.2.10-auto-sign-in.44+c910d5f59",
47
47
  "crypto-js": "^4.1.1"
48
48
  },
49
49
  "devDependencies": {
@@ -95,5 +95,5 @@
95
95
  ],
96
96
  "testSequencer": "./testSequencer.js"
97
97
  },
98
- "gitHead": "f206bf675cd63bee4147984b050036c82905bf27"
98
+ "gitHead": "c910d5f59f357c585aed8633755322ab431a5512"
99
99
  }
package/src/Auth.ts CHANGED
@@ -41,9 +41,10 @@ import {
41
41
  StorageHelper,
42
42
  ICredentials,
43
43
  Parser,
44
- JS,
44
+ browserOrNode,
45
45
  UniversalStorage,
46
46
  urlSafeDecode,
47
+ HubCallback,
47
48
  } from '@aws-amplify/core';
48
49
  import {
49
50
  CookieStorage,
@@ -70,6 +71,7 @@ import { default as urlListener } from './urlListener';
70
71
  import { AuthError, NoUserPoolError } from './Errors';
71
72
  import {
72
73
  AuthErrorTypes,
74
+ AutoSignInOptions,
73
75
  CognitoHostedUIIdentityProvider,
74
76
  IAuthDevice,
75
77
  } from './types/Auth';
@@ -95,6 +97,8 @@ const dispatchAuthEvent = (event: string, data: any, message: string) => {
95
97
  // https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListDevices.html#API_ListDevices_RequestSyntax
96
98
  const MAX_DEVICES = 60;
97
99
 
100
+ const MAX_AUTOSIGNIN_POLLING_MS = 3 * 60 * 1000;
101
+
98
102
  /**
99
103
  * Provide authentication steps
100
104
  */
@@ -107,6 +111,7 @@ export class AuthClass {
107
111
  private _storageSync;
108
112
  private oAuthFlowInProgress: boolean = false;
109
113
  private pendingSignIn: ReturnType<AuthClass['signInWithPassword']> | null;
114
+ private autoSignInInitiated: boolean = false;
110
115
 
111
116
  Credentials = Credentials;
112
117
 
@@ -257,6 +262,23 @@ export class AuthClass {
257
262
  null,
258
263
  `The Auth category has been configured successfully`
259
264
  );
265
+
266
+ if (
267
+ !this.autoSignInInitiated &&
268
+ typeof this._storage['getItem'] === 'function'
269
+ ) {
270
+ const pollingInitiated = this.isTrueStorageValue(
271
+ 'amplify-polling-started'
272
+ );
273
+ if (pollingInitiated) {
274
+ dispatchAuthEvent(
275
+ 'autoSignIn_failure',
276
+ null,
277
+ AuthErrorTypes.AutoSignInError
278
+ );
279
+ }
280
+ this._storage.removeItem('amplify-polling-started');
281
+ }
260
282
  return this._config;
261
283
  }
262
284
 
@@ -295,6 +317,9 @@ export class AuthClass {
295
317
  const attributes: CognitoUserAttribute[] = [];
296
318
  let validationData: CognitoUserAttribute[] = null;
297
319
  let clientMetadata;
320
+ let autoSignIn: AutoSignInOptions = { enabled: false };
321
+ let autoSignInValidationData = {};
322
+ let autoSignInClientMetaData: ClientMetaData = {};
298
323
 
299
324
  if (params && typeof params === 'string') {
300
325
  username = params;
@@ -345,6 +370,13 @@ export class AuthClass {
345
370
  );
346
371
  });
347
372
  }
373
+
374
+ autoSignIn = params.autoSignIn ?? { enabled: false };
375
+ if (autoSignIn.enabled) {
376
+ this._storage.setItem('amplify-auto-sign-in', true);
377
+ autoSignInValidationData = autoSignIn.validationData ?? {};
378
+ autoSignInClientMetaData = autoSignIn.clientMetaData ?? {};
379
+ }
348
380
  } else {
349
381
  return this.rejectAuthError(AuthErrorTypes.SignUpError);
350
382
  }
@@ -379,6 +411,15 @@ export class AuthClass {
379
411
  data,
380
412
  `${username} has signed up successfully`
381
413
  );
414
+ if (autoSignIn.enabled) {
415
+ this.handleAutoSignIn(
416
+ username,
417
+ password,
418
+ autoSignInValidationData,
419
+ autoSignInClientMetaData,
420
+ data
421
+ );
422
+ }
382
423
  resolve(data);
383
424
  }
384
425
  },
@@ -387,6 +428,95 @@ export class AuthClass {
387
428
  });
388
429
  }
389
430
 
431
+ private handleAutoSignIn(
432
+ username: string,
433
+ password: string,
434
+ validationData: {},
435
+ clientMetadata: any,
436
+ data: any
437
+ ) {
438
+ this.autoSignInInitiated = true;
439
+ const authDetails = new AuthenticationDetails({
440
+ Username: username,
441
+ Password: password,
442
+ ValidationData: validationData,
443
+ ClientMetadata: clientMetadata,
444
+ });
445
+ if (data.userConfirmed) {
446
+ this.signInAfterUserConfirmed(authDetails);
447
+ } else if (this._config.signUpVerificationMethod === 'link') {
448
+ this.handleLinkAutoSignIn(authDetails);
449
+ } else {
450
+ this.handleCodeAutoSignIn(authDetails);
451
+ }
452
+ }
453
+
454
+ private handleCodeAutoSignIn(authDetails: AuthenticationDetails) {
455
+ const listenEvent = ({ payload }) => {
456
+ if (payload.event === 'confirmSignUp') {
457
+ this.signInAfterUserConfirmed(authDetails, listenEvent);
458
+ }
459
+ };
460
+ Hub.listen('auth', listenEvent);
461
+ }
462
+
463
+ private handleLinkAutoSignIn(authDetails: AuthenticationDetails) {
464
+ this._storage.setItem('amplify-polling-started', true);
465
+ const start = Date.now();
466
+ const autoSignInPollingIntervalId = setInterval(() => {
467
+ if (Date.now() - start > MAX_AUTOSIGNIN_POLLING_MS) {
468
+ clearInterval(autoSignInPollingIntervalId);
469
+ dispatchAuthEvent(
470
+ 'autoSignIn_failure',
471
+ null,
472
+ 'Please confirm your account and use your credentials to sign in.'
473
+ );
474
+ } else {
475
+ this.signInAfterUserConfirmed(
476
+ authDetails,
477
+ null,
478
+ autoSignInPollingIntervalId
479
+ );
480
+ }
481
+ }, 5000);
482
+ }
483
+
484
+ private async signInAfterUserConfirmed(
485
+ authDetails: AuthenticationDetails,
486
+ listenEvent?: HubCallback,
487
+ autoSignInPollingIntervalId?: ReturnType<typeof setInterval>
488
+ ) {
489
+ const user = this.createCognitoUser(authDetails.getUsername());
490
+ try {
491
+ await user.authenticateUser(
492
+ authDetails,
493
+ this.authCallbacks(
494
+ user,
495
+ value => {
496
+ dispatchAuthEvent(
497
+ 'autoSignIn',
498
+ value,
499
+ `${authDetails.getUsername()} has signed in successfully`
500
+ );
501
+ if (listenEvent) {
502
+ Hub.remove('auth', listenEvent);
503
+ }
504
+ if (autoSignInPollingIntervalId) {
505
+ clearInterval(autoSignInPollingIntervalId);
506
+ this._storage.removeItem('amplify-polling-started');
507
+ }
508
+ this._storage.removeItem('amplify-auto-sign-in');
509
+ },
510
+ error => {
511
+ logger.error(error);
512
+ }
513
+ )
514
+ );
515
+ } catch (error) {
516
+ logger.error(error);
517
+ }
518
+ }
519
+
390
520
  /**
391
521
  * Send the verification code to confirm sign up
392
522
  * @param {String} username - The username to be confirmed
@@ -429,6 +559,19 @@ export class AuthClass {
429
559
  if (err) {
430
560
  reject(err);
431
561
  } else {
562
+ dispatchAuthEvent(
563
+ 'confirmSignUp',
564
+ data,
565
+ `${username} has been confirmed successfully`
566
+ );
567
+ const autoSignIn = this.isTrueStorageValue('amplify-auto-sign-in');
568
+ if (autoSignIn && !this.autoSignInInitiated) {
569
+ dispatchAuthEvent(
570
+ 'autoSignIn_failure',
571
+ null,
572
+ AuthErrorTypes.AutoSignInError
573
+ );
574
+ }
432
575
  resolve(data);
433
576
  }
434
577
  },
@@ -437,6 +580,11 @@ export class AuthClass {
437
580
  });
438
581
  }
439
582
 
583
+ private isTrueStorageValue(value: string) {
584
+ const item = this._storage.getItem(value);
585
+ return item ? item === 'true' : false;
586
+ }
587
+
440
588
  /**
441
589
  * Resend the verification code
442
590
  * @param {String} username - The username to be confirmed
@@ -1905,7 +2053,7 @@ export class AuthClass {
1905
2053
  resolve: () => void,
1906
2054
  reject: (reason?: any) => void
1907
2055
  ) {
1908
- const { isBrowser } = JS.browserOrNode();
2056
+ const { isBrowser } = browserOrNode();
1909
2057
 
1910
2058
  if (isBrowser) {
1911
2059
  this.oAuthSignOutRedirectOrReject(reject);
@@ -2273,7 +2421,7 @@ export class AuthClass {
2273
2421
  );
2274
2422
 
2275
2423
  const currentUrl =
2276
- URL || (JS.browserOrNode().isBrowser ? window.location.href : '');
2424
+ URL || (browserOrNode().isBrowser ? window.location.href : '');
2277
2425
 
2278
2426
  const hasCodeOrError = !!(parse(currentUrl).query || '')
2279
2427
  .split('&')
package/src/Errors.ts CHANGED
@@ -110,6 +110,9 @@ export const authErrorMessages: AuthErrorMessages = {
110
110
  networkError: {
111
111
  message: AuthErrorStrings.NETWORK_ERROR,
112
112
  },
113
+ autoSignInError: {
114
+ message: AuthErrorStrings.AUTOSIGNIN_ERROR,
115
+ },
113
116
  default: {
114
117
  message: AuthErrorStrings.DEFAULT_MSG,
115
118
  },
@@ -13,4 +13,5 @@ export enum AuthErrorStrings {
13
13
  NO_USER_SESSION = 'Failed to get the session because the user is empty',
14
14
  NETWORK_ERROR = 'Network Error',
15
15
  DEVICE_CONFIG = 'Device tracking has not been configured in this User Pool',
16
+ AUTOSIGNIN_ERROR = 'Please use your credentials to sign in',
16
17
  }
package/src/types/Auth.ts CHANGED
@@ -25,6 +25,7 @@ export interface SignUpParams {
25
25
  attributes?: object;
26
26
  validationData?: { [key: string]: any };
27
27
  clientMetadata?: { [key: string]: string };
28
+ autoSignIn?: AutoSignInOptions;
28
29
  }
29
30
 
30
31
  export interface AuthCache {
@@ -50,6 +51,7 @@ export interface AuthOptions {
50
51
  identityPoolRegion?: string;
51
52
  clientMetadata?: any;
52
53
  endpoint?: string;
54
+ signUpVerificationMethod?: 'code' | 'link';
53
55
  }
54
56
 
55
57
  export enum CognitoHostedUIIdentityProvider {
@@ -201,6 +203,7 @@ export enum AuthErrorTypes {
201
203
  Default = 'default',
202
204
  DeviceConfig = 'deviceConfig',
203
205
  NetworkError = 'networkError',
206
+ AutoSignInError = 'autoSignInError',
204
207
  }
205
208
 
206
209
  export type AuthErrorMessages = { [key in AuthErrorTypes]: AuthErrorMessage };
@@ -228,6 +231,12 @@ export interface IAuthDevice {
228
231
  name: string;
229
232
  }
230
233
 
234
+ export interface AutoSignInOptions {
235
+ enabled: boolean;
236
+ clientMetaData?: ClientMetaData;
237
+ validationData?: { [key: string]: any };
238
+ }
239
+
231
240
  export enum GRAPHQL_AUTH_MODE {
232
241
  API_KEY = 'API_KEY',
233
242
  AWS_IAM = 'AWS_IAM',
@@ -10,14 +10,14 @@
10
10
  * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
11
  * and limitations under the License.
12
12
  */
13
- import { JS } from '@aws-amplify/core';
13
+ import { browserOrNode } from '@aws-amplify/core';
14
14
 
15
15
  export default callback => {
16
- if (JS.browserOrNode().isBrowser && window.location) {
16
+ if (browserOrNode().isBrowser && window.location) {
17
17
  const url = window.location.href;
18
18
 
19
19
  callback({ url });
20
- } else if (JS.browserOrNode().isNode) {
20
+ } else if (browserOrNode().isNode) {
21
21
  // continue building on ssr
22
22
  () => {}; // noop
23
23
  } else {