@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.
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/libraryUtils.d.ts +1 -0
- package/lib/singleton/Auth/index.d.ts +1 -8
- package/lib/singleton/Auth/index.js +24 -26
- package/lib/singleton/Auth/types.d.ts +2 -0
- package/lib/singleton/Auth/utils/index.js +8 -3
- package/lib/singleton/apis/clearCredentials.d.ts +1 -0
- package/lib/singleton/apis/clearCredentials.js +10 -0
- package/lib/singleton/index.d.ts +1 -0
- package/lib/singleton/index.js +3 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/libraryUtils.d.ts +1 -0
- package/lib-esm/singleton/Auth/index.d.ts +1 -8
- package/lib-esm/singleton/Auth/index.js +24 -26
- package/lib-esm/singleton/Auth/types.d.ts +2 -0
- package/lib-esm/singleton/Auth/utils/index.js +8 -3
- package/lib-esm/singleton/apis/clearCredentials.d.ts +1 -0
- package/lib-esm/singleton/apis/clearCredentials.js +6 -0
- package/lib-esm/singleton/index.d.ts +1 -0
- package/lib-esm/singleton/index.js +1 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -5
- package/polyfills/URL/index.ts +2 -2
- package/src/Platform/version.ts +1 -1
- package/src/index.ts +1 -0
- package/src/libraryUtils.ts +1 -0
- package/src/singleton/Auth/index.ts +9 -19
- package/src/singleton/Auth/types.ts +2 -0
- package/src/singleton/Auth/utils/index.ts +10 -7
- package/src/singleton/apis/clearCredentials.ts +8 -0
- package/src/singleton/index.ts +1 -0
- 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 (
|
|
71
|
-
switch (
|
|
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 = (
|
|
78
|
+
(_c = (_k.sent())) !== null && _c !== void 0 ? _c : undefined;
|
|
83
79
|
if (!tokens) return [3 /*break*/, 3];
|
|
84
|
-
|
|
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
|
-
|
|
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*/, ((
|
|
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
|
-
|
|
106
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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>;
|