@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
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { Observable, Observer } from 'rxjs';
|
|
4
|
-
|
|
5
3
|
import {
|
|
6
4
|
AWSCredentialsAndIdentityId,
|
|
7
5
|
AuthConfig,
|
|
@@ -25,13 +23,10 @@ export function isTokenExpired({
|
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
export class AuthClass {
|
|
28
|
-
private authSessionObservers: Set<Observer<AuthSession>>;
|
|
29
26
|
private authConfig?: AuthConfig;
|
|
30
27
|
private authOptions?: LibraryAuthOptions;
|
|
31
28
|
|
|
32
|
-
constructor() {
|
|
33
|
-
this.authSessionObservers = new Set();
|
|
34
|
-
}
|
|
29
|
+
constructor() {}
|
|
35
30
|
|
|
36
31
|
/**
|
|
37
32
|
* Configure Auth category
|
|
@@ -56,6 +51,7 @@ export class AuthClass {
|
|
|
56
51
|
): Promise<AuthSession> {
|
|
57
52
|
let tokens: AuthTokens | undefined;
|
|
58
53
|
let credentialsAndIdentityId: AWSCredentialsAndIdentityId | undefined;
|
|
54
|
+
let userSub: string | undefined;
|
|
59
55
|
|
|
60
56
|
asserts(!!this.authConfig, {
|
|
61
57
|
name: AUTH_CONFING_EXCEPTION,
|
|
@@ -69,6 +65,8 @@ export class AuthClass {
|
|
|
69
65
|
(await this.authOptions?.tokenProvider?.getTokens(options)) ?? undefined;
|
|
70
66
|
|
|
71
67
|
if (tokens) {
|
|
68
|
+
userSub = tokens.accessToken?.payload?.sub;
|
|
69
|
+
|
|
72
70
|
// getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
|
|
73
71
|
credentialsAndIdentityId =
|
|
74
72
|
await this.authOptions?.credentialsProvider?.getCredentialsAndIdentityId(
|
|
@@ -95,21 +93,13 @@ export class AuthClass {
|
|
|
95
93
|
tokens,
|
|
96
94
|
credentials: credentialsAndIdentityId?.credentials,
|
|
97
95
|
identityId: credentialsAndIdentityId?.identityId,
|
|
96
|
+
userSub,
|
|
98
97
|
};
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*/
|
|
106
|
-
listenSessionChanges(): Observable<AuthSession> {
|
|
107
|
-
return new Observable(observer => {
|
|
108
|
-
this.authSessionObservers.add(observer);
|
|
109
|
-
|
|
110
|
-
return () => {
|
|
111
|
-
this.authSessionObservers.delete(observer);
|
|
112
|
-
};
|
|
113
|
-
});
|
|
100
|
+
async clearCredentials(): Promise<void> {
|
|
101
|
+
if (this.authOptions?.credentialsProvider) {
|
|
102
|
+
return await this.authOptions.credentialsProvider.clearCredentials();
|
|
103
|
+
}
|
|
114
104
|
}
|
|
115
105
|
}
|
|
@@ -11,6 +11,7 @@ interface JwtPayloadStandardFields {
|
|
|
11
11
|
iat?: number; // issued at: https://tools.ietf.org/html/rfc7519#section-4.1.6
|
|
12
12
|
scope?: string; // scopes: https://tools.ietf.org/html/rfc6749#section-3.3
|
|
13
13
|
jti?: string; // JWT ID: https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7
|
|
14
|
+
sub?: string; // JWT sub https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
/** JSON type */
|
|
@@ -32,6 +33,7 @@ export type AuthSession = {
|
|
|
32
33
|
tokens?: AuthTokens;
|
|
33
34
|
credentials?: AWSCredentials;
|
|
34
35
|
identityId?: string;
|
|
36
|
+
userSub?: string;
|
|
35
37
|
};
|
|
36
38
|
|
|
37
39
|
export type LibraryAuthOptions = {
|
|
@@ -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
|
import {
|
|
6
5
|
AuthConfig,
|
|
@@ -77,13 +76,12 @@ export function decodeJWT(token: string): JWT {
|
|
|
77
76
|
if (tokenSplitted.length !== 3) {
|
|
78
77
|
throw new Error('Invalid token');
|
|
79
78
|
}
|
|
80
|
-
|
|
81
|
-
const payloadString = tokenSplitted[1];
|
|
82
|
-
const payload = JSON.parse(
|
|
83
|
-
Buffer.from(payloadString, 'base64').toString('utf8')
|
|
84
|
-
);
|
|
85
|
-
|
|
86
79
|
try {
|
|
80
|
+
const payloadStringb64 = tokenSplitted[1];
|
|
81
|
+
const payloadArrayBuffer = base64ToBytes(payloadStringb64);
|
|
82
|
+
const decodeString = new TextDecoder().decode(payloadArrayBuffer);
|
|
83
|
+
const payload = JSON.parse(decodeString);
|
|
84
|
+
|
|
87
85
|
return {
|
|
88
86
|
toString: () => token,
|
|
89
87
|
payload,
|
|
@@ -92,3 +90,8 @@ export function decodeJWT(token: string): JWT {
|
|
|
92
90
|
throw new Error('Invalid token payload');
|
|
93
91
|
}
|
|
94
92
|
}
|
|
93
|
+
|
|
94
|
+
function base64ToBytes(base64: string): Uint8Array {
|
|
95
|
+
const binString = atob(base64);
|
|
96
|
+
return Uint8Array.from(binString, m => m.codePointAt(0) || 0);
|
|
97
|
+
}
|
package/src/singleton/index.ts
CHANGED
package/polyfills/URL/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(()=>{var e={128:e=>{"use strict";e.exports=require("react-native-url-polyfill/auto")}},r={};var o,t={};"test"!==(null===(o=null===process||void 0===process?void 0:process.env)||void 0===o?void 0:o.NODE_ENV)&&function o(t){var s=r[t];if(void 0!==s)return s.exports;var v=r[t]={exports:{}};return e[t](v,v.exports,o),v.exports}(128);var s=exports;for(var v in t)s[v]=t[v];t.__esModule&&Object.defineProperty(s,"__esModule",{value:!0})})();
|