@aws-amplify/core 6.0.1-console-preview.e8aa063.0 → 6.0.1-console-preview.096eee3.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.
Files changed (39) hide show
  1. package/lib/Platform/version.d.ts +1 -1
  2. package/lib/Platform/version.js +1 -1
  3. package/lib/index.d.ts +1 -1
  4. package/lib/index.js +2 -1
  5. package/lib/libraryUtils.d.ts +1 -0
  6. package/lib/singleton/Auth/index.d.ts +1 -8
  7. package/lib/singleton/Auth/index.js +24 -26
  8. package/lib/singleton/Auth/types.d.ts +2 -0
  9. package/lib/singleton/Auth/utils/index.js +8 -3
  10. package/lib/singleton/apis/clearCredentials.d.ts +1 -0
  11. package/lib/singleton/apis/clearCredentials.js +10 -0
  12. package/lib/singleton/index.d.ts +1 -0
  13. package/lib/singleton/index.js +3 -1
  14. package/lib/tsconfig.tsbuildinfo +1 -1
  15. package/lib-esm/Platform/version.d.ts +1 -1
  16. package/lib-esm/Platform/version.js +1 -1
  17. package/lib-esm/index.d.ts +1 -1
  18. package/lib-esm/index.js +1 -1
  19. package/lib-esm/libraryUtils.d.ts +1 -0
  20. package/lib-esm/singleton/Auth/index.d.ts +1 -8
  21. package/lib-esm/singleton/Auth/index.js +24 -26
  22. package/lib-esm/singleton/Auth/types.d.ts +2 -0
  23. package/lib-esm/singleton/Auth/utils/index.js +8 -3
  24. package/lib-esm/singleton/apis/clearCredentials.d.ts +1 -0
  25. package/lib-esm/singleton/apis/clearCredentials.js +6 -0
  26. package/lib-esm/singleton/index.d.ts +1 -0
  27. package/lib-esm/singleton/index.js +1 -0
  28. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +3 -5
  30. package/polyfills/URL/index.ts +2 -2
  31. package/src/Platform/version.ts +1 -1
  32. package/src/index.ts +1 -0
  33. package/src/libraryUtils.ts +1 -0
  34. package/src/singleton/Auth/index.ts +9 -19
  35. package/src/singleton/Auth/types.ts +2 -0
  36. package/src/singleton/Auth/utils/index.ts +10 -7
  37. package/src/singleton/apis/clearCredentials.ts +8 -0
  38. package/src/singleton/index.ts +1 -0
  39. package/polyfills/URL/index.js +0 -1
@@ -34,9 +34,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
38
- // SPDX-License-Identifier: Apache-2.0
39
- import { Observable } from 'rxjs';
40
37
  import { asserts } from '../../Util/errors/AssertError';
41
38
  import { AUTH_CONFING_EXCEPTION } from '../../Util/Constants';
42
39
  export function isTokenExpired(_a) {
@@ -46,7 +43,6 @@ export function isTokenExpired(_a) {
46
43
  }
47
44
  var AuthClass = /** @class */ (function () {
48
45
  function AuthClass() {
49
- this.authSessionObservers = new Set();
50
46
  }
51
47
  /**
52
48
  * Configure Auth category
@@ -63,12 +59,12 @@ var AuthClass = /** @class */ (function () {
63
59
  this.authOptions = authOptions;
64
60
  };
65
61
  AuthClass.prototype.fetchAuthSession = function (options) {
66
- var _a, _b, _c, _d, _e, _f, _g;
62
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
67
63
  if (options === void 0) { options = {}; }
68
64
  return __awaiter(this, void 0, void 0, function () {
69
- var tokens, credentialsAndIdentityId;
70
- return __generator(this, function (_h) {
71
- switch (_h.label) {
65
+ var tokens, credentialsAndIdentityId, userSub;
66
+ return __generator(this, function (_k) {
67
+ switch (_k.label) {
72
68
  case 0:
73
69
  asserts(!!this.authConfig, {
74
70
  name: AUTH_CONFING_EXCEPTION,
@@ -79,9 +75,10 @@ var AuthClass = /** @class */ (function () {
79
75
  case 1:
80
76
  // Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available
81
77
  tokens =
82
- (_c = (_h.sent())) !== null && _c !== void 0 ? _c : undefined;
78
+ (_c = (_k.sent())) !== null && _c !== void 0 ? _c : undefined;
83
79
  if (!tokens) return [3 /*break*/, 3];
84
- return [4 /*yield*/, ((_e = (_d = this.authOptions) === null || _d === void 0 ? void 0 : _d.credentialsProvider) === null || _e === void 0 ? void 0 : _e.getCredentialsAndIdentityId({
80
+ userSub = (_e = (_d = tokens.accessToken) === null || _d === void 0 ? void 0 : _d.payload) === null || _e === void 0 ? void 0 : _e.sub;
81
+ return [4 /*yield*/, ((_g = (_f = this.authOptions) === null || _f === void 0 ? void 0 : _f.credentialsProvider) === null || _g === void 0 ? void 0 : _g.getCredentialsAndIdentityId({
85
82
  authConfig: this.authConfig,
86
83
  tokens: tokens,
87
84
  authenticated: true,
@@ -90,11 +87,11 @@ var AuthClass = /** @class */ (function () {
90
87
  case 2:
91
88
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
92
89
  credentialsAndIdentityId =
93
- _h.sent();
90
+ _k.sent();
94
91
  return [3 /*break*/, 5];
95
92
  case 3:
96
93
  if (!!this.authConfig.isMandatorySignInEnabled) return [3 /*break*/, 5];
97
- return [4 /*yield*/, ((_g = (_f = this.authOptions) === null || _f === void 0 ? void 0 : _f.credentialsProvider) === null || _g === void 0 ? void 0 : _g.getCredentialsAndIdentityId({
94
+ return [4 /*yield*/, ((_j = (_h = this.authOptions) === null || _h === void 0 ? void 0 : _h.credentialsProvider) === null || _j === void 0 ? void 0 : _j.getCredentialsAndIdentityId({
98
95
  authConfig: this.authConfig,
99
96
  authenticated: false,
100
97
  forceRefresh: options.forceRefresh,
@@ -102,29 +99,30 @@ var AuthClass = /** @class */ (function () {
102
99
  case 4:
103
100
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
104
101
  credentialsAndIdentityId =
105
- _h.sent();
106
- _h.label = 5;
102
+ _k.sent();
103
+ _k.label = 5;
107
104
  case 5: return [2 /*return*/, {
108
105
  tokens: tokens,
109
106
  credentials: credentialsAndIdentityId === null || credentialsAndIdentityId === void 0 ? void 0 : credentialsAndIdentityId.credentials,
110
107
  identityId: credentialsAndIdentityId === null || credentialsAndIdentityId === void 0 ? void 0 : credentialsAndIdentityId.identityId,
108
+ userSub: userSub,
111
109
  }];
112
110
  }
113
111
  });
114
112
  });
115
113
  };
116
- /**
117
- * Obtain an Observable that notifies on session changes
118
- *
119
- * @returns Observable<AmplifyUserSession>
120
- */
121
- AuthClass.prototype.listenSessionChanges = function () {
122
- var _this = this;
123
- return new Observable(function (observer) {
124
- _this.authSessionObservers.add(observer);
125
- return function () {
126
- _this.authSessionObservers.delete(observer);
127
- };
114
+ AuthClass.prototype.clearCredentials = function () {
115
+ var _a;
116
+ return __awaiter(this, void 0, void 0, function () {
117
+ return __generator(this, function (_b) {
118
+ switch (_b.label) {
119
+ case 0:
120
+ if (!((_a = this.authOptions) === null || _a === void 0 ? void 0 : _a.credentialsProvider)) return [3 /*break*/, 2];
121
+ return [4 /*yield*/, this.authOptions.credentialsProvider.clearCredentials()];
122
+ case 1: return [2 /*return*/, _b.sent()];
123
+ case 2: return [2 /*return*/];
124
+ }
125
+ });
128
126
  });
129
127
  };
130
128
  return AuthClass;
@@ -6,6 +6,7 @@ interface JwtPayloadStandardFields {
6
6
  iat?: number;
7
7
  scope?: string;
8
8
  jti?: string;
9
+ sub?: string;
9
10
  }
10
11
  /** JSON type */
11
12
  type Json = null | string | number | boolean | Json[] | JsonObject;
@@ -23,6 +24,7 @@ export type AuthSession = {
23
24
  tokens?: AuthTokens;
24
25
  credentials?: AWSCredentials;
25
26
  identityId?: string;
27
+ userSub?: string;
26
28
  };
27
29
  export type LibraryAuthOptions = {
28
30
  tokenProvider?: TokenProvider;
@@ -1,6 +1,5 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { Buffer } from 'buffer';
4
3
  import { asserts } from '../../../Util/errors/AssertError';
5
4
  export function assertTokenProviderConfig(authConfig) {
6
5
  var validConfig = !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.userPoolId) && !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.userPoolWebClientId);
@@ -44,9 +43,11 @@ export function decodeJWT(token) {
44
43
  if (tokenSplitted.length !== 3) {
45
44
  throw new Error('Invalid token');
46
45
  }
47
- var payloadString = tokenSplitted[1];
48
- var payload = JSON.parse(Buffer.from(payloadString, 'base64').toString('utf8'));
49
46
  try {
47
+ var payloadStringb64 = tokenSplitted[1];
48
+ var payloadArrayBuffer = base64ToBytes(payloadStringb64);
49
+ var decodeString = new TextDecoder().decode(payloadArrayBuffer);
50
+ var payload = JSON.parse(decodeString);
50
51
  return {
51
52
  toString: function () { return token; },
52
53
  payload: payload,
@@ -56,3 +57,7 @@ export function decodeJWT(token) {
56
57
  throw new Error('Invalid token payload');
57
58
  }
58
59
  }
60
+ function base64ToBytes(base64) {
61
+ var binString = atob(base64);
62
+ return Uint8Array.from(binString, function (m) { return m.codePointAt(0) || 0; });
63
+ }
@@ -0,0 +1 @@
1
+ export declare function clearCredentials(): Promise<void>;
@@ -0,0 +1,6 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Amplify } from '../Amplify';
4
+ export function clearCredentials() {
5
+ return Amplify.Auth.clearCredentials();
6
+ }
@@ -1,2 +1,3 @@
1
1
  export { AmplifyClass, Amplify } from './Amplify';
2
2
  export { fetchAuthSession } from './apis/fetchAuthSession';
3
+ export { clearCredentials } from './apis/clearCredentials';
@@ -2,3 +2,4 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  export { AmplifyClass, Amplify } from './Amplify';
4
4
  export { fetchAuthSession } from './apis/fetchAuthSession';
5
+ export { clearCredentials } from './apis/clearCredentials';