triangle-utils 1.4.25 → 1.4.27
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/dist/src/UtilsCognito.d.ts +1 -1
- package/dist/src/UtilsCognito.js +22 -17
- package/package.json +1 -1
- package/src/UtilsCognito.ts +22 -17
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export declare class UtilsCognito {
|
|
2
2
|
private readonly cognito;
|
|
3
3
|
constructor(region: string);
|
|
4
|
-
get_username(token: string): Promise<string | undefined>;
|
|
5
4
|
admin_get_user(user_pool_id: string, username: string): Promise<import("@aws-sdk/client-cognito-identity-provider").AdminGetUserCommandOutput | undefined>;
|
|
6
5
|
admin_create_user(user_pool_id: string, username: string, user_id: string): Promise<Error | import("@aws-sdk/client-cognito-identity-provider").AdminCreateUserCommandOutput>;
|
|
7
6
|
admin_reset_password(user_pool_id: string, username: string): Promise<Error | import("@aws-sdk/client-cognito-identity-provider").AdminCreateUserCommandOutput>;
|
|
7
|
+
get_email(token: string): Promise<string | undefined>;
|
|
8
8
|
get_user_id(token: string): Promise<string | undefined>;
|
|
9
9
|
get_new_token(client_id: string, client_secret: string, refresh_token: string): Promise<string | undefined>;
|
|
10
10
|
sign_out(token: string): Promise<void>;
|
package/dist/src/UtilsCognito.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
import { CognitoIdentityProvider
|
|
1
|
+
import { CognitoIdentityProvider } from "@aws-sdk/client-cognito-identity-provider";
|
|
2
2
|
export class UtilsCognito {
|
|
3
3
|
cognito;
|
|
4
4
|
constructor(region) {
|
|
5
5
|
this.cognito = new CognitoIdentityProvider({ region: region });
|
|
6
6
|
}
|
|
7
|
-
async get_username(token) {
|
|
8
|
-
try {
|
|
9
|
-
const user_info = await this.cognito.getUser({
|
|
10
|
-
AccessToken: token
|
|
11
|
-
});
|
|
12
|
-
const username = user_info.Username;
|
|
13
|
-
return username;
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
7
|
async admin_get_user(user_pool_id, username) {
|
|
20
8
|
try {
|
|
21
9
|
return await this.cognito.adminGetUser({
|
|
@@ -64,6 +52,26 @@ export class UtilsCognito {
|
|
|
64
52
|
return new Error();
|
|
65
53
|
}
|
|
66
54
|
}
|
|
55
|
+
async get_email(token) {
|
|
56
|
+
try {
|
|
57
|
+
const user_info = await this.cognito.getUser({
|
|
58
|
+
AccessToken: token
|
|
59
|
+
});
|
|
60
|
+
const user_attributes = user_info.UserAttributes;
|
|
61
|
+
if (user_attributes === undefined) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const user_attribute = user_attributes.filter(attribute => attribute.Name === "email")[0];
|
|
65
|
+
if (user_attribute === undefined) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const email = user_attribute.Value;
|
|
69
|
+
return email;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
67
75
|
async get_user_id(token) {
|
|
68
76
|
try {
|
|
69
77
|
const user_info = await this.cognito.getUser({
|
|
@@ -91,10 +99,7 @@ export class UtilsCognito {
|
|
|
91
99
|
return user_id;
|
|
92
100
|
}
|
|
93
101
|
catch (error) {
|
|
94
|
-
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
throw error;
|
|
102
|
+
return undefined;
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
105
|
async get_new_token(client_id, client_secret, refresh_token) {
|
package/package.json
CHANGED
package/src/UtilsCognito.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CognitoIdentityProvider, NotAuthorizedException } from "@aws-sdk/client-cognito-identity-provider"
|
|
1
|
+
import { CognitoIdentityProvider, NotAuthorizedException, UserNotFoundException } from "@aws-sdk/client-cognito-identity-provider"
|
|
2
2
|
|
|
3
3
|
export class UtilsCognito {
|
|
4
4
|
|
|
@@ -8,18 +8,6 @@ export class UtilsCognito {
|
|
|
8
8
|
this.cognito = new CognitoIdentityProvider({ region : region })
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
async get_username(token : string) {
|
|
12
|
-
try {
|
|
13
|
-
const user_info = await this.cognito.getUser({
|
|
14
|
-
AccessToken : token
|
|
15
|
-
})
|
|
16
|
-
const username = user_info.Username
|
|
17
|
-
return username
|
|
18
|
-
} catch (error) {
|
|
19
|
-
return undefined
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
11
|
async admin_get_user(user_pool_id : string, username : string) {
|
|
24
12
|
try {
|
|
25
13
|
return await this.cognito.adminGetUser({
|
|
@@ -68,6 +56,26 @@ export class UtilsCognito {
|
|
|
68
56
|
}
|
|
69
57
|
}
|
|
70
58
|
|
|
59
|
+
async get_email(token : string) {
|
|
60
|
+
try {
|
|
61
|
+
const user_info = await this.cognito.getUser({
|
|
62
|
+
AccessToken : token
|
|
63
|
+
})
|
|
64
|
+
const user_attributes = user_info.UserAttributes
|
|
65
|
+
if (user_attributes === undefined) {
|
|
66
|
+
return undefined
|
|
67
|
+
}
|
|
68
|
+
const user_attribute = user_attributes.filter(attribute => attribute.Name === "email")[0]
|
|
69
|
+
if (user_attribute === undefined) {
|
|
70
|
+
return undefined
|
|
71
|
+
}
|
|
72
|
+
const email = user_attribute.Value
|
|
73
|
+
return email
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return undefined
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
71
79
|
async get_user_id(token : string) : Promise<string | undefined> {
|
|
72
80
|
try {
|
|
73
81
|
const user_info = await this.cognito.getUser({
|
|
@@ -94,10 +102,7 @@ export class UtilsCognito {
|
|
|
94
102
|
const user_id = user_attribute.Value
|
|
95
103
|
return user_id
|
|
96
104
|
} catch (error) {
|
|
97
|
-
|
|
98
|
-
return undefined
|
|
99
|
-
}
|
|
100
|
-
throw error
|
|
105
|
+
return undefined
|
|
101
106
|
}
|
|
102
107
|
}
|
|
103
108
|
|