@sudoplatform/sudo-user 11.0.0 → 12.0.1
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/cjs/client/apiClient.d.ts +25 -0
- package/cjs/client/apiClient.js +149 -0
- package/cjs/client/apiClient.js.map +1 -0
- package/cjs/core/api-key-names.d.ts +8 -0
- package/cjs/core/api-key-names.js +12 -0
- package/cjs/core/api-key-names.js.map +1 -0
- package/cjs/core/auth-store.d.ts +51 -0
- package/cjs/core/auth-store.js +92 -0
- package/cjs/core/auth-store.js.map +1 -0
- package/cjs/core/crypto.d.ts +3 -0
- package/cjs/core/crypto.js +3 -0
- package/cjs/core/crypto.js.map +1 -0
- package/cjs/core/key-manager.d.ts +31 -0
- package/cjs/core/key-manager.js +113 -0
- package/cjs/core/key-manager.js.map +1 -0
- package/cjs/core/protected-store.d.ts +5 -0
- package/cjs/core/protected-store.js +3 -0
- package/cjs/core/protected-store.js.map +1 -0
- package/cjs/core/publisher.d.ts +6 -0
- package/cjs/core/publisher.js +3 -0
- package/cjs/core/publisher.js.map +1 -0
- package/cjs/core/sdk-config.d.ts +52 -0
- package/cjs/core/sdk-config.js +61 -0
- package/cjs/core/sdk-config.js.map +1 -0
- package/cjs/core/subscriber.d.ts +3 -0
- package/cjs/core/subscriber.js +3 -0
- package/cjs/core/subscriber.js.map +1 -0
- package/cjs/gen/graphql-types.d.ts +101 -0
- package/cjs/gen/graphql-types.js +105 -0
- package/cjs/gen/graphql-types.js.map +1 -0
- package/cjs/index.d.ts +4 -0
- package/cjs/index.js +13 -0
- package/cjs/index.js.map +1 -0
- package/cjs/runtimes/browser/browser-crypto.d.ts +2 -0
- package/cjs/runtimes/browser/browser-crypto.js +10 -0
- package/cjs/runtimes/browser/browser-crypto.js.map +1 -0
- package/cjs/runtimes/node/node-crypto.d.ts +2 -0
- package/cjs/runtimes/node/node-crypto.js +9 -0
- package/cjs/runtimes/node/node-crypto.js.map +1 -0
- package/cjs/sdk.d.ts +1 -0
- package/cjs/sdk.js +9 -0
- package/cjs/sdk.js.map +1 -0
- package/cjs/user/auth-provider.d.ts +97 -0
- package/cjs/user/auth-provider.js +116 -0
- package/cjs/user/auth-provider.js.map +1 -0
- package/cjs/user/auth.d.ts +64 -0
- package/cjs/user/auth.js +136 -0
- package/cjs/user/auth.js.map +1 -0
- package/cjs/user/error.d.ts +18 -0
- package/cjs/user/error.js +33 -0
- package/cjs/user/error.js.map +1 -0
- package/cjs/user/identity-provider.d.ts +73 -0
- package/cjs/user/identity-provider.js +245 -0
- package/cjs/user/identity-provider.js.map +1 -0
- package/cjs/user/user-client-interface.d.ts +168 -0
- package/cjs/user/user-client-interface.js +3 -0
- package/cjs/user/user-client-interface.js.map +1 -0
- package/cjs/user/user-client.d.ts +82 -0
- package/cjs/user/user-client.js +440 -0
- package/cjs/user/user-client.js.map +1 -0
- package/cjs/user/user-key-names.d.ts +6 -0
- package/cjs/user/user-key-names.js +10 -0
- package/cjs/user/user-key-names.js.map +1 -0
- package/cjs/utils/resolvable-promise.d.ts +9 -0
- package/cjs/utils/resolvable-promise.js +20 -0
- package/cjs/utils/resolvable-promise.js.map +1 -0
- package/docs/classes/AlreadyRegisteredError.html +4 -4
- package/docs/classes/IdentityServiceConfigNotFoundError.html +4 -4
- package/lib/client/apiClient.js +135 -180
- package/lib/client/apiClient.js.map +1 -0
- package/lib/core/api-key-names.js +8 -14
- package/lib/core/api-key-names.js.map +1 -0
- package/lib/core/auth-store.js +82 -138
- package/lib/core/auth-store.js.map +1 -0
- package/lib/core/crypto.js +2 -5
- package/lib/core/crypto.js.map +1 -0
- package/lib/core/key-manager.js +98 -148
- package/lib/core/key-manager.js.map +1 -0
- package/lib/core/protected-store.d.ts +5 -0
- package/lib/core/protected-store.js +2 -5
- package/lib/core/protected-store.js.map +1 -0
- package/lib/core/publisher.js +2 -5
- package/lib/core/publisher.js.map +1 -0
- package/lib/core/sdk-config.js +56 -56
- package/lib/core/sdk-config.js.map +1 -0
- package/lib/core/subscriber.js +2 -5
- package/lib/core/subscriber.js.map +1 -0
- package/lib/gen/graphql-types.js +96 -135
- package/lib/gen/graphql-types.js.map +1 -0
- package/lib/index.js +6 -67
- package/lib/index.js.map +1 -0
- package/lib/runtimes/browser/browser-crypto.d.ts +2 -0
- package/lib/runtimes/browser/browser-crypto.js +6 -14
- package/lib/runtimes/browser/browser-crypto.js.map +1 -0
- package/lib/runtimes/node/node-crypto.js +5 -11
- package/lib/runtimes/node/node-crypto.js.map +1 -0
- package/lib/sdk.js +6 -18
- package/lib/sdk.js.map +1 -0
- package/lib/user/auth-provider.js +81 -131
- package/lib/user/auth-provider.js.map +1 -0
- package/lib/user/auth.js +127 -179
- package/lib/user/auth.js.map +1 -0
- package/lib/user/error.js +15 -33
- package/lib/user/error.js.map +1 -0
- package/lib/user/identity-provider.js +232 -261
- package/lib/user/identity-provider.js.map +1 -0
- package/lib/user/user-client-interface.js +2 -5
- package/lib/user/user-client-interface.js.map +1 -0
- package/lib/user/user-client.js +423 -510
- package/lib/user/user-client.js.map +1 -0
- package/lib/user/user-key-names.js +6 -12
- package/lib/user/user-key-names.js.map +1 -0
- package/lib/utils/resolvable-promise.js +13 -19
- package/lib/utils/resolvable-promise.js.map +1 -0
- package/package.json +22 -21
|
@@ -1,270 +1,241 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
-
|
|
20
|
-
class CognitoUserPoolIdentityProvider {
|
|
21
|
-
constructor(keyManager, config, logger) {
|
|
22
|
-
this.keyManager = keyManager;
|
|
23
|
-
this.config = config;
|
|
24
|
-
|
|
25
|
-
_defineProperty(this, "idpService", void 0);
|
|
26
|
-
|
|
27
|
-
_defineProperty(this, "refreshTokenLifetime", void 0);
|
|
28
|
-
|
|
29
|
-
_defineProperty(this, "logger", void 0);
|
|
30
|
-
|
|
31
|
-
this.idpService = this.initCognitoIdpService();
|
|
32
|
-
const refreshTokenLifetime = this.config.identityService.refreshTokenLifetime;
|
|
33
|
-
this.refreshTokenLifetime = refreshTokenLifetime ?? 60;
|
|
34
|
-
this.logger = logger;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
initCognitoIdpService() {
|
|
38
|
-
const idpService = new _clientCognitoIdentityProvider.CognitoIdentityProviderClient({
|
|
39
|
-
region: this.config.identityService.region
|
|
40
|
-
});
|
|
41
|
-
return idpService;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async globalSignOut(accessToken) {
|
|
45
|
-
return new Promise((resolve, reject) => {
|
|
46
|
-
const params = {
|
|
47
|
-
AccessToken: accessToken
|
|
48
|
-
};
|
|
49
|
-
const globalSignOut = new _clientCognitoIdentityProvider.GlobalSignOutCommand(params);
|
|
50
|
-
this.idpService.send(globalSignOut, (error, data) => {
|
|
51
|
-
if (error) {
|
|
52
|
-
this.logger.error(error.message);
|
|
53
|
-
reject(new _sudoCommon.SignOutError(error.message));
|
|
54
|
-
} else {
|
|
55
|
-
this.logger.info('User successfully signed out.', {
|
|
56
|
-
data
|
|
57
|
-
});
|
|
58
|
-
resolve();
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async register(uid, validationData) {
|
|
65
|
-
try {
|
|
66
|
-
const signUp = new _clientCognitoIdentityProvider.SignUpCommand({
|
|
67
|
-
ValidationData: validationData,
|
|
68
|
-
Username: uid,
|
|
69
|
-
Password: `@FF57&Z1)123!-${(0, _uuid.v4)()}`,
|
|
70
|
-
ClientId: this.config.identityService.clientId
|
|
71
|
-
});
|
|
72
|
-
const response = await this.idpService.send(signUp);
|
|
73
|
-
|
|
74
|
-
if (response.UserConfirmed) {
|
|
75
|
-
this.logger.info('User successfully signed up.', {
|
|
76
|
-
uid
|
|
1
|
+
import { CognitoIdentityProviderClient, GlobalSignOutCommand, InitiateAuthCommand, RespondToAuthChallengeCommand, RevokeTokenCommand, SignUpCommand, } from '@aws-sdk/client-cognito-identity-provider';
|
|
2
|
+
import { apiKeyNames } from '../core/api-key-names';
|
|
3
|
+
import { v4 } from 'uuid';
|
|
4
|
+
import { AuthenticationError, NotAuthorizedError, SignOutError, ServiceError, FatalError, UserNotConfirmedError, } from '@sudoplatform/sudo-common';
|
|
5
|
+
import { AlreadyRegisteredError } from './error';
|
|
6
|
+
export class CognitoUserPoolIdentityProvider {
|
|
7
|
+
constructor(keyManager, config, logger) {
|
|
8
|
+
this.keyManager = keyManager;
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.idpService = this.initCognitoIdpService();
|
|
11
|
+
const refreshTokenLifetime = this.config.identityService.refreshTokenLifetime;
|
|
12
|
+
this.refreshTokenLifetime = refreshTokenLifetime ?? 60;
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
}
|
|
15
|
+
initCognitoIdpService() {
|
|
16
|
+
const idpService = new CognitoIdentityProviderClient({
|
|
17
|
+
region: this.config.identityService.region,
|
|
77
18
|
});
|
|
78
|
-
return
|
|
79
|
-
} else {
|
|
80
|
-
throw new _sudoCommon.UserNotConfirmedError();
|
|
81
|
-
}
|
|
82
|
-
} catch (err) {
|
|
83
|
-
const error = err;
|
|
84
|
-
const errorMsg = error.message;
|
|
85
|
-
|
|
86
|
-
if (errorMsg.includes('sudoplatform.ServiceError')) {
|
|
87
|
-
throw new _sudoCommon.ServiceError(errorMsg);
|
|
88
|
-
} else if (errorMsg.includes('sudoplatform.identity.UserValidationFailed') || errorMsg.includes('sudoplatform.identity.TestRegCheckFailed')) {
|
|
89
|
-
throw new _sudoCommon.NotAuthorizedError(errorMsg);
|
|
90
|
-
} else if (errorMsg.includes('sudoplatform.identity.AlreadyRegistered')) {
|
|
91
|
-
throw new _error.AlreadyRegisteredError();
|
|
92
|
-
} else {
|
|
93
|
-
throw new _sudoCommon.FatalError(errorMsg);
|
|
94
|
-
}
|
|
19
|
+
return idpService;
|
|
95
20
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
USERNAME: userId
|
|
21
|
+
async globalSignOut(accessToken) {
|
|
22
|
+
try {
|
|
23
|
+
const params = {
|
|
24
|
+
AccessToken: accessToken,
|
|
25
|
+
};
|
|
26
|
+
const globalSignOut = new GlobalSignOutCommand(params);
|
|
27
|
+
const response = await this.idpService.send(globalSignOut);
|
|
28
|
+
this.logger.info('User successfully signed out.', { response });
|
|
105
29
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
USERNAME: userId,
|
|
128
|
-
ANSWER: answer
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
const respondToAuthChallengeResult = await this.idpService.send(respondToAuthChallenge);
|
|
132
|
-
const authResult = respondToAuthChallengeResult.AuthenticationResult;
|
|
133
|
-
const idToken = authResult?.IdToken;
|
|
134
|
-
const accessToken = authResult?.AccessToken;
|
|
135
|
-
const refreshToken = authResult?.RefreshToken;
|
|
136
|
-
const tokenExpiry = authResult?.ExpiresIn;
|
|
137
|
-
|
|
138
|
-
if (idToken && accessToken && refreshToken && tokenExpiry) {
|
|
139
|
-
const authTokens = {
|
|
140
|
-
idToken: idToken,
|
|
141
|
-
accessToken: accessToken,
|
|
142
|
-
refreshToken: refreshToken,
|
|
143
|
-
tokenExpiry: tokenExpiry
|
|
144
|
-
};
|
|
145
|
-
await this.storeRefreshTokenLifetime(this.refreshTokenLifetime);
|
|
146
|
-
resolve(authTokens);
|
|
147
|
-
} else {
|
|
148
|
-
reject(new _sudoCommon.AuthenticationError('Authentication tokens not found.'));
|
|
30
|
+
catch (err) {
|
|
31
|
+
const error = err;
|
|
32
|
+
throw new SignOutError(error.message);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async register(uid, validationData) {
|
|
36
|
+
try {
|
|
37
|
+
const signUp = new SignUpCommand({
|
|
38
|
+
ValidationData: validationData,
|
|
39
|
+
Username: uid,
|
|
40
|
+
Password: `@FF57&Z1)123!-${v4()}`,
|
|
41
|
+
ClientId: this.config.identityService.clientId,
|
|
42
|
+
});
|
|
43
|
+
const response = await this.idpService.send(signUp);
|
|
44
|
+
if (response.UserConfirmed) {
|
|
45
|
+
this.logger.info('User successfully signed up.', { uid });
|
|
46
|
+
return uid;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
throw new UserNotConfirmedError();
|
|
50
|
+
}
|
|
149
51
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
52
|
+
catch (err) {
|
|
53
|
+
const error = err;
|
|
54
|
+
const errorMsg = error.message;
|
|
55
|
+
if (errorMsg.includes('sudoplatform.ServiceError')) {
|
|
56
|
+
throw new ServiceError(errorMsg);
|
|
57
|
+
}
|
|
58
|
+
else if (errorMsg.includes('sudoplatform.identity.UserValidationFailed') ||
|
|
59
|
+
errorMsg.includes('sudoplatform.identity.TestRegCheckFailed')) {
|
|
60
|
+
throw new NotAuthorizedError(errorMsg);
|
|
61
|
+
}
|
|
62
|
+
else if (errorMsg.includes('sudoplatform.identity.AlreadyRegistered')) {
|
|
63
|
+
throw new AlreadyRegisteredError();
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new FatalError(errorMsg);
|
|
67
|
+
}
|
|
163
68
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
69
|
+
}
|
|
70
|
+
async signInWithKey(userId, keyId) {
|
|
71
|
+
try {
|
|
72
|
+
const initiateAuthCommand = new InitiateAuthCommand({
|
|
73
|
+
ClientId: this.config.identityService.clientId,
|
|
74
|
+
AuthFlow: 'CUSTOM_AUTH',
|
|
75
|
+
AuthParameters: {
|
|
76
|
+
USERNAME: userId,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const initiateAuthResult = await this.idpService.send(initiateAuthCommand);
|
|
80
|
+
const challengeName = initiateAuthResult.ChallengeName;
|
|
81
|
+
const session = initiateAuthResult.Session;
|
|
82
|
+
const params = initiateAuthResult.ChallengeParameters;
|
|
83
|
+
if (params &&
|
|
84
|
+
params['nonce'] &&
|
|
85
|
+
params['audience'] &&
|
|
86
|
+
challengeName &&
|
|
87
|
+
session) {
|
|
88
|
+
const nonce = params['nonce'];
|
|
89
|
+
const audience = params['audience'];
|
|
90
|
+
const answer = await this.keyManager.signJWT(keyId, {
|
|
91
|
+
jti: nonce,
|
|
92
|
+
iss: userId,
|
|
93
|
+
aud: audience,
|
|
94
|
+
sub: userId,
|
|
95
|
+
exp: Math.floor(+new Date() / 1000) + 300,
|
|
96
|
+
});
|
|
97
|
+
const respondToAuthChallenge = new RespondToAuthChallengeCommand({
|
|
98
|
+
Session: session,
|
|
99
|
+
ClientId: this.config.identityService.clientId,
|
|
100
|
+
ChallengeName: challengeName,
|
|
101
|
+
ChallengeResponses: {
|
|
102
|
+
USERNAME: userId,
|
|
103
|
+
ANSWER: answer,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
const respondToAuthChallengeResult = await this.idpService.send(respondToAuthChallenge);
|
|
107
|
+
const authResult = respondToAuthChallengeResult.AuthenticationResult;
|
|
108
|
+
const idToken = authResult?.IdToken;
|
|
109
|
+
const accessToken = authResult?.AccessToken;
|
|
110
|
+
const refreshToken = authResult?.RefreshToken;
|
|
111
|
+
const tokenExpiry = authResult?.ExpiresIn;
|
|
112
|
+
if (idToken && accessToken && refreshToken && tokenExpiry) {
|
|
113
|
+
const authTokens = {
|
|
114
|
+
idToken: idToken,
|
|
115
|
+
accessToken: accessToken,
|
|
116
|
+
refreshToken: refreshToken,
|
|
117
|
+
tokenExpiry: tokenExpiry,
|
|
118
|
+
};
|
|
119
|
+
await this.storeRefreshTokenLifetime(this.refreshTokenLifetime);
|
|
120
|
+
return authTokens;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
throw new AuthenticationError('Authentication tokens not found.');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
throw new AuthenticationError('Invalid initiate auth result.');
|
|
128
|
+
}
|
|
200
129
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async refreshTokens(refreshToken) {
|
|
208
|
-
return new Promise(async (resolve, reject) => {
|
|
209
|
-
try {
|
|
210
|
-
const initiateAuth = new _clientCognitoIdentityProvider.InitiateAuthCommand({
|
|
211
|
-
ClientId: this.config.identityService.clientId,
|
|
212
|
-
AuthFlow: 'REFRESH_TOKEN_AUTH',
|
|
213
|
-
AuthParameters: {
|
|
214
|
-
REFRESH_TOKEN: refreshToken
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
const initiateAuthResult = await this.idpService.send(initiateAuth);
|
|
218
|
-
const idToken = initiateAuthResult.AuthenticationResult?.IdToken;
|
|
219
|
-
const accessToken = initiateAuthResult.AuthenticationResult?.AccessToken;
|
|
220
|
-
const tokenExpiry = initiateAuthResult.AuthenticationResult?.ExpiresIn;
|
|
221
|
-
|
|
222
|
-
if (idToken && accessToken && tokenExpiry) {
|
|
223
|
-
const authTokens = {
|
|
224
|
-
idToken: idToken,
|
|
225
|
-
accessToken: accessToken,
|
|
226
|
-
refreshToken: refreshToken,
|
|
227
|
-
tokenExpiry: tokenExpiry
|
|
228
|
-
};
|
|
229
|
-
await this.storeRefreshTokenLifetime(this.refreshTokenLifetime);
|
|
230
|
-
resolve(authTokens);
|
|
231
|
-
} else {
|
|
232
|
-
reject(new _sudoCommon.AuthenticationError('Authentication tokens not found.'));
|
|
130
|
+
catch (err) {
|
|
131
|
+
const error = err;
|
|
132
|
+
throw new AuthenticationError(error.message);
|
|
233
133
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
134
|
+
}
|
|
135
|
+
async signInWithToken(userId, token, type) {
|
|
136
|
+
try {
|
|
137
|
+
const initiateAuth = new InitiateAuthCommand({
|
|
138
|
+
ClientId: this.config.identityService.clientId,
|
|
139
|
+
AuthFlow: 'CUSTOM_AUTH',
|
|
140
|
+
AuthParameters: {
|
|
141
|
+
USERNAME: userId,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
const initiateAuthResult = await this.idpService.send(initiateAuth);
|
|
145
|
+
const challengeName = initiateAuthResult.ChallengeName;
|
|
146
|
+
const session = initiateAuthResult.Session;
|
|
147
|
+
if (challengeName && session) {
|
|
148
|
+
const respondToAuthChallenge = new RespondToAuthChallengeCommand({
|
|
149
|
+
Session: session,
|
|
150
|
+
ClientId: this.config.identityService.clientId,
|
|
151
|
+
ChallengeName: challengeName,
|
|
152
|
+
ChallengeResponses: {
|
|
153
|
+
USERNAME: userId,
|
|
154
|
+
ANSWER: token,
|
|
155
|
+
},
|
|
156
|
+
ClientMetadata: { challengeType: type },
|
|
157
|
+
});
|
|
158
|
+
const respondToAuthChallengeResult = await this.idpService.send(respondToAuthChallenge);
|
|
159
|
+
const authResult = respondToAuthChallengeResult.AuthenticationResult;
|
|
160
|
+
const idToken = authResult?.IdToken;
|
|
161
|
+
const accessToken = authResult?.AccessToken;
|
|
162
|
+
const refreshToken = authResult?.RefreshToken;
|
|
163
|
+
const tokenExpiry = authResult?.ExpiresIn;
|
|
164
|
+
if (idToken && accessToken && refreshToken && tokenExpiry) {
|
|
165
|
+
const authTokens = {
|
|
166
|
+
idToken: idToken,
|
|
167
|
+
accessToken: accessToken,
|
|
168
|
+
refreshToken: refreshToken,
|
|
169
|
+
tokenExpiry: tokenExpiry,
|
|
170
|
+
};
|
|
171
|
+
await this.storeRefreshTokenLifetime(this.refreshTokenLifetime);
|
|
172
|
+
return authTokens;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
throw new AuthenticationError('Authentication tokens not found.');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
throw new AuthenticationError('Invalid initiate auth result.');
|
|
180
|
+
}
|
|
257
181
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
182
|
+
catch (err) {
|
|
183
|
+
const error = err;
|
|
184
|
+
throw new AuthenticationError(error.message);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async refreshTokens(refreshToken) {
|
|
188
|
+
try {
|
|
189
|
+
const initiateAuth = new InitiateAuthCommand({
|
|
190
|
+
ClientId: this.config.identityService.clientId,
|
|
191
|
+
AuthFlow: 'REFRESH_TOKEN_AUTH',
|
|
192
|
+
AuthParameters: {
|
|
193
|
+
REFRESH_TOKEN: refreshToken,
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
const initiateAuthResult = await this.idpService.send(initiateAuth);
|
|
197
|
+
const idToken = initiateAuthResult.AuthenticationResult?.IdToken;
|
|
198
|
+
const accessToken = initiateAuthResult.AuthenticationResult?.AccessToken;
|
|
199
|
+
const tokenExpiry = initiateAuthResult.AuthenticationResult?.ExpiresIn;
|
|
200
|
+
if (idToken && accessToken && tokenExpiry) {
|
|
201
|
+
const authTokens = {
|
|
202
|
+
idToken: idToken,
|
|
203
|
+
accessToken: accessToken,
|
|
204
|
+
refreshToken: refreshToken,
|
|
205
|
+
tokenExpiry: tokenExpiry,
|
|
206
|
+
};
|
|
207
|
+
await this.storeRefreshTokenLifetime(this.refreshTokenLifetime);
|
|
208
|
+
return authTokens;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
throw new AuthenticationError('Authentication tokens not found.');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
const error = err;
|
|
216
|
+
throw new AuthenticationError(error.message);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async signOut(refreshToken) {
|
|
220
|
+
try {
|
|
221
|
+
const params = {
|
|
222
|
+
Token: refreshToken,
|
|
223
|
+
ClientId: this.config.identityService.clientId,
|
|
224
|
+
};
|
|
225
|
+
const revokeToken = new RevokeTokenCommand(params);
|
|
226
|
+
const response = await this.idpService.send(revokeToken);
|
|
227
|
+
this.logger.info('User successfully signed out.', { response });
|
|
228
|
+
}
|
|
229
|
+
catch (err) {
|
|
230
|
+
const error = err;
|
|
231
|
+
this.logger.error(error.message);
|
|
232
|
+
throw new SignOutError(error.message);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async storeRefreshTokenLifetime(refreshTokenLifetime) {
|
|
236
|
+
const tokenLifetime = refreshTokenLifetime * 24 * 60 * 60 * 1000 + new Date().getTime();
|
|
237
|
+
await this.keyManager.removeItem(apiKeyNames.refreshTokenExpiry);
|
|
238
|
+
await this.keyManager.addString(apiKeyNames.refreshTokenExpiry, tokenLifetime.toString());
|
|
239
|
+
}
|
|
268
240
|
}
|
|
269
|
-
|
|
270
|
-
exports.CognitoUserPoolIdentityProvider = CognitoUserPoolIdentityProvider;
|
|
241
|
+
//# sourceMappingURL=identity-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-provider.js","sourceRoot":"","sources":["../../src/user/identity-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,mBAAmB,EACnB,6BAA6B,EAC7B,kBAAkB,EAClB,aAAa,GACd,MAAM,2CAA2C,CAAA;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGnD,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAA;AACzB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,qBAAqB,GAEtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AA4DhD,MAAM,OAAO,+BAA+B;IAK1C,YACU,UAAsB,EACtB,MAAc,EACtB,MAAc;QAFN,eAAU,GAAV,UAAU,CAAY;QACtB,WAAM,GAAN,MAAM,CAAQ;QAGtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAA;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