@sudoplatform/sudo-user 10.1.0 → 12.0.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 → cjs/src}/client/apiClient.d.ts +0 -0
- package/cjs/src/client/apiClient.js +149 -0
- package/cjs/src/client/apiClient.js.map +1 -0
- package/{lib → cjs/src}/core/api-key-names.d.ts +0 -0
- package/cjs/src/core/api-key-names.js +12 -0
- package/cjs/src/core/api-key-names.js.map +1 -0
- package/{lib → cjs/src}/core/auth-store.d.ts +0 -0
- package/cjs/src/core/auth-store.js +92 -0
- package/cjs/src/core/auth-store.js.map +1 -0
- package/{lib → cjs/src}/core/crypto.d.ts +0 -0
- package/cjs/src/core/crypto.js +3 -0
- package/cjs/src/core/crypto.js.map +1 -0
- package/{lib → cjs/src}/core/key-manager.d.ts +0 -0
- package/cjs/src/core/key-manager.js +113 -0
- package/cjs/src/core/key-manager.js.map +1 -0
- package/cjs/src/core/protected-store.d.ts +5 -0
- package/cjs/src/core/protected-store.js +3 -0
- package/cjs/src/core/protected-store.js.map +1 -0
- package/{lib → cjs/src}/core/publisher.d.ts +0 -0
- package/cjs/src/core/publisher.js +3 -0
- package/cjs/src/core/publisher.js.map +1 -0
- package/{lib → cjs/src}/core/sdk-config.d.ts +0 -0
- package/cjs/src/core/sdk-config.js +61 -0
- package/cjs/src/core/sdk-config.js.map +1 -0
- package/{lib → cjs/src}/core/subscriber.d.ts +0 -0
- package/cjs/src/core/subscriber.js +3 -0
- package/cjs/src/core/subscriber.js.map +1 -0
- package/{lib → cjs/src}/gen/graphql-types.d.ts +5 -4
- package/cjs/src/gen/graphql-types.js +105 -0
- package/cjs/src/gen/graphql-types.js.map +1 -0
- package/{lib → cjs/src}/index.d.ts +0 -0
- package/cjs/src/index.js +13 -0
- package/cjs/src/index.js.map +1 -0
- package/{lib/runtimes/node/node-crypto.d.ts → cjs/src/runtimes/browser/browser-crypto.d.ts} +0 -0
- package/cjs/src/runtimes/browser/browser-crypto.js +10 -0
- package/cjs/src/runtimes/browser/browser-crypto.js.map +1 -0
- package/cjs/src/runtimes/node/node-crypto.d.ts +2 -0
- package/cjs/src/runtimes/node/node-crypto.js +9 -0
- package/cjs/src/runtimes/node/node-crypto.js.map +1 -0
- package/{lib → cjs/src}/sdk.d.ts +0 -0
- package/cjs/src/sdk.js +9 -0
- package/cjs/src/sdk.js.map +1 -0
- package/{lib → cjs/src}/user/auth-provider.d.ts +0 -0
- package/cjs/src/user/auth-provider.js +116 -0
- package/cjs/src/user/auth-provider.js.map +1 -0
- package/{lib → cjs/src}/user/auth.d.ts +0 -0
- package/cjs/src/user/auth.js +136 -0
- package/cjs/src/user/auth.js.map +1 -0
- package/{lib → cjs/src}/user/error.d.ts +0 -0
- package/{lib → cjs/src}/user/error.js +16 -29
- package/cjs/src/user/error.js.map +1 -0
- package/{lib → cjs/src}/user/identity-provider.d.ts +0 -0
- package/cjs/src/user/identity-provider.js +245 -0
- package/cjs/src/user/identity-provider.js.map +1 -0
- package/{lib → cjs/src}/user/user-client-interface.d.ts +0 -0
- package/cjs/src/user/user-client-interface.js +3 -0
- package/cjs/src/user/user-client-interface.js.map +1 -0
- package/{lib → cjs/src}/user/user-client.d.ts +0 -0
- package/cjs/src/user/user-client.js +440 -0
- package/cjs/src/user/user-client.js.map +1 -0
- package/{lib → cjs/src}/user/user-key-names.d.ts +0 -0
- package/cjs/src/user/user-key-names.js +10 -0
- package/cjs/src/user/user-key-names.js.map +1 -0
- package/{lib → cjs/src}/utils/resolvable-promise.d.ts +0 -0
- package/cjs/src/utils/resolvable-promise.js +20 -0
- package/cjs/src/utils/resolvable-promise.js.map +1 -0
- package/cjs/test/integration/user-client-int.spec.d.ts +1 -0
- package/cjs/test/integration/user-client-int.spec.js +206 -0
- package/cjs/test/integration/user-client-int.spec.js.map +1 -0
- package/cjs/test/unit/core/sdk-config.spec.d.ts +1 -0
- package/cjs/test/unit/core/sdk-config.spec.js +51 -0
- package/cjs/test/unit/core/sdk-config.spec.js.map +1 -0
- package/cjs/test/unit/key-manager.spec.d.ts +1 -0
- package/cjs/test/unit/key-manager.spec.js +23 -0
- package/cjs/test/unit/key-manager.spec.js.map +1 -0
- package/cjs/test/unit/user-client.spec.d.ts +1 -0
- package/cjs/test/unit/user-client.spec.js +323 -0
- package/cjs/test/unit/user-client.spec.js.map +1 -0
- package/docs/assets/highlight.css +3 -3
- package/docs/assets/main.js +4 -2
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +427 -617
- package/docs/classes/AlreadyRegisteredError.html +163 -8
- package/docs/classes/DefaultSudoUserClient.html +568 -57
- package/docs/classes/IdentityServiceConfigNotFoundError.html +163 -8
- package/docs/classes/LocalAuthenticationProvider.html +131 -12
- package/docs/classes/TESTAuthenticationProvider.html +146 -11
- package/docs/index.html +47 -2
- package/docs/interfaces/AuthenticationProvider.html +89 -6
- package/docs/interfaces/AuthenticationTokens.html +97 -7
- package/docs/interfaces/SudoUserClient.html +431 -80
- package/docs/modules.html +62 -1
- package/lib/src/client/apiClient.d.ts +25 -0
- package/lib/src/client/apiClient.js +145 -0
- package/lib/src/client/apiClient.js.map +1 -0
- package/lib/src/core/api-key-names.d.ts +8 -0
- package/lib/src/core/api-key-names.js +9 -0
- package/lib/src/core/api-key-names.js.map +1 -0
- package/lib/src/core/auth-store.d.ts +51 -0
- package/lib/src/core/auth-store.js +88 -0
- package/lib/src/core/auth-store.js.map +1 -0
- package/lib/src/core/crypto.d.ts +3 -0
- package/lib/src/core/crypto.js +2 -0
- package/lib/src/core/crypto.js.map +1 -0
- package/lib/src/core/key-manager.d.ts +31 -0
- package/lib/src/core/key-manager.js +108 -0
- package/lib/src/core/key-manager.js.map +1 -0
- package/lib/src/core/protected-store.d.ts +5 -0
- package/lib/src/core/protected-store.js +2 -0
- package/lib/src/core/protected-store.js.map +1 -0
- package/lib/src/core/publisher.d.ts +6 -0
- package/lib/src/core/publisher.js +2 -0
- package/lib/src/core/publisher.js.map +1 -0
- package/lib/src/core/sdk-config.d.ts +52 -0
- package/lib/src/core/sdk-config.js +56 -0
- package/lib/src/core/sdk-config.js.map +1 -0
- package/lib/src/core/subscriber.d.ts +3 -0
- package/lib/src/core/subscriber.js +2 -0
- package/lib/src/core/subscriber.js.map +1 -0
- package/lib/src/gen/graphql-types.d.ts +101 -0
- package/lib/src/gen/graphql-types.js +102 -0
- package/lib/src/gen/graphql-types.js.map +1 -0
- package/lib/src/index.d.ts +4 -0
- package/lib/src/index.js +6 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/runtimes/browser/browser-crypto.d.ts +2 -0
- package/lib/src/runtimes/browser/browser-crypto.js +7 -0
- package/lib/src/runtimes/browser/browser-crypto.js.map +1 -0
- package/lib/src/runtimes/node/node-crypto.d.ts +2 -0
- package/lib/src/runtimes/node/node-crypto.js +6 -0
- package/lib/src/runtimes/node/node-crypto.js.map +1 -0
- package/lib/src/sdk.d.ts +1 -0
- package/lib/src/sdk.js +6 -0
- package/lib/src/sdk.js.map +1 -0
- package/lib/src/user/auth-provider.d.ts +97 -0
- package/lib/src/user/auth-provider.js +108 -0
- package/lib/src/user/auth-provider.js.map +1 -0
- package/lib/src/user/auth.d.ts +64 -0
- package/lib/src/user/auth.js +131 -0
- package/lib/src/user/auth.js.map +1 -0
- package/lib/src/user/error.d.ts +18 -0
- package/lib/src/user/error.js +28 -0
- package/lib/src/user/error.js.map +1 -0
- package/lib/src/user/identity-provider.d.ts +73 -0
- package/lib/src/user/identity-provider.js +241 -0
- package/lib/src/user/identity-provider.js.map +1 -0
- package/lib/src/user/user-client-interface.d.ts +168 -0
- package/lib/src/user/user-client-interface.js +2 -0
- package/lib/src/user/user-client-interface.js.map +1 -0
- package/lib/src/user/user-client.d.ts +82 -0
- package/lib/src/user/user-client.js +435 -0
- package/lib/src/user/user-client.js.map +1 -0
- package/lib/src/user/user-key-names.d.ts +6 -0
- package/lib/src/user/user-key-names.js +7 -0
- package/lib/src/user/user-key-names.js.map +1 -0
- package/lib/src/utils/resolvable-promise.d.ts +9 -0
- package/lib/src/utils/resolvable-promise.js +16 -0
- package/lib/src/utils/resolvable-promise.js.map +1 -0
- package/lib/test/integration/user-client-int.spec.d.ts +1 -0
- package/lib/test/integration/user-client-int.spec.js +203 -0
- package/lib/test/integration/user-client-int.spec.js.map +1 -0
- package/lib/test/unit/core/sdk-config.spec.d.ts +1 -0
- package/lib/test/unit/core/sdk-config.spec.js +49 -0
- package/lib/test/unit/core/sdk-config.spec.js.map +1 -0
- package/lib/test/unit/key-manager.spec.d.ts +1 -0
- package/lib/test/unit/key-manager.spec.js +21 -0
- package/lib/test/unit/key-manager.spec.js.map +1 -0
- package/lib/test/unit/user-client.spec.d.ts +1 -0
- package/lib/test/unit/user-client.spec.js +320 -0
- package/lib/test/unit/user-client.spec.js.map +1 -0
- package/package.json +47 -41
- package/docs/assets/icons.css +0 -1043
- package/docs/assets/icons.png +0 -0
- package/docs/assets/icons@2x.png +0 -0
- package/lib/client/apiClient.js +0 -206
- package/lib/core/api-key-names.js +0 -15
- package/lib/core/auth-store.js +0 -144
- package/lib/core/crypto.js +0 -5
- package/lib/core/key-manager.js +0 -158
- package/lib/core/protected-store.js +0 -5
- package/lib/core/publisher.js +0 -5
- package/lib/core/sdk-config.js +0 -56
- package/lib/core/subscriber.js +0 -5
- package/lib/gen/graphql-types.js +0 -141
- package/lib/index.js +0 -67
- package/lib/runtimes/browser/browser-crypto.js +0 -15
- package/lib/runtimes/node/node-crypto.js +0 -12
- package/lib/sdk.js +0 -18
- package/lib/user/auth-provider.js +0 -158
- package/lib/user/auth.js +0 -185
- package/lib/user/identity-provider.js +0 -272
- package/lib/user/user-client-interface.js +0 -5
- package/lib/user/user-client.js +0 -530
- package/lib/user/user-key-names.js +0 -13
- package/lib/utils/resolvable-promise.js +0 -22
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.CognitoUserPoolIdentityProvider = void 0;
|
|
7
|
-
|
|
8
|
-
var _clientCognitoIdentityProvider = require("@aws-sdk/client-cognito-identity-provider");
|
|
9
|
-
|
|
10
|
-
var _apiKeyNames = require("../core/api-key-names");
|
|
11
|
-
|
|
12
|
-
var _uuid = require("uuid");
|
|
13
|
-
|
|
14
|
-
var _sudoCommon = require("@sudoplatform/sudo-common");
|
|
15
|
-
|
|
16
|
-
var _error = require("./error");
|
|
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
|
|
77
|
-
});
|
|
78
|
-
return uid;
|
|
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
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async signInWithKey(userId, keyId) {
|
|
99
|
-
return new Promise(async (resolve, reject) => {
|
|
100
|
-
const initiateAuthCommand = new _clientCognitoIdentityProvider.InitiateAuthCommand({
|
|
101
|
-
ClientId: this.config.identityService.clientId,
|
|
102
|
-
AuthFlow: 'CUSTOM_AUTH',
|
|
103
|
-
AuthParameters: {
|
|
104
|
-
USERNAME: userId
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
const initiateAuthResult = await this.idpService.send(initiateAuthCommand);
|
|
108
|
-
const challengeName = initiateAuthResult.ChallengeName;
|
|
109
|
-
const session = initiateAuthResult.Session;
|
|
110
|
-
const params = initiateAuthResult.ChallengeParameters;
|
|
111
|
-
|
|
112
|
-
if (params && params['nonce'] && params['audience'] && challengeName && session) {
|
|
113
|
-
const nonce = params['nonce'];
|
|
114
|
-
const audience = params['audience'];
|
|
115
|
-
const answer = await this.keyManager.signJWT(keyId, {
|
|
116
|
-
jti: nonce,
|
|
117
|
-
iss: userId,
|
|
118
|
-
aud: audience,
|
|
119
|
-
sub: userId,
|
|
120
|
-
exp: Math.floor(+new Date() / 1000) + 300
|
|
121
|
-
});
|
|
122
|
-
const respondToAuthChallenge = new _clientCognitoIdentityProvider.RespondToAuthChallengeCommand({
|
|
123
|
-
Session: session,
|
|
124
|
-
ClientId: this.config.identityService.clientId,
|
|
125
|
-
ChallengeName: challengeName,
|
|
126
|
-
ChallengeResponses: {
|
|
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 === null || authResult === void 0 ? void 0 : authResult.IdToken;
|
|
134
|
-
const accessToken = authResult === null || authResult === void 0 ? void 0 : authResult.AccessToken;
|
|
135
|
-
const refreshToken = authResult === null || authResult === void 0 ? void 0 : authResult.RefreshToken;
|
|
136
|
-
const tokenExpiry = authResult === null || authResult === void 0 ? void 0 : 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.'));
|
|
149
|
-
}
|
|
150
|
-
} else {
|
|
151
|
-
reject(new _sudoCommon.AuthenticationError('Invalid initiate auth result.'));
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async signInWithToken(userId, token, type) {
|
|
157
|
-
return new Promise(async (resolve, reject) => {
|
|
158
|
-
const initiateAuth = new _clientCognitoIdentityProvider.InitiateAuthCommand({
|
|
159
|
-
ClientId: this.config.identityService.clientId,
|
|
160
|
-
AuthFlow: 'CUSTOM_AUTH',
|
|
161
|
-
AuthParameters: {
|
|
162
|
-
USERNAME: userId
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
const initiateAuthResult = await this.idpService.send(initiateAuth);
|
|
166
|
-
const challengeName = initiateAuthResult.ChallengeName;
|
|
167
|
-
const session = initiateAuthResult.Session;
|
|
168
|
-
|
|
169
|
-
if (challengeName && session) {
|
|
170
|
-
const respondToAuthChallenge = new _clientCognitoIdentityProvider.RespondToAuthChallengeCommand({
|
|
171
|
-
Session: session,
|
|
172
|
-
ClientId: this.config.identityService.clientId,
|
|
173
|
-
ChallengeName: challengeName,
|
|
174
|
-
ChallengeResponses: {
|
|
175
|
-
USERNAME: userId,
|
|
176
|
-
ANSWER: token
|
|
177
|
-
},
|
|
178
|
-
ClientMetadata: {
|
|
179
|
-
challengeType: type
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
const respondToAuthChallengeResult = await this.idpService.send(respondToAuthChallenge);
|
|
183
|
-
const authResult = respondToAuthChallengeResult.AuthenticationResult;
|
|
184
|
-
const idToken = authResult === null || authResult === void 0 ? void 0 : authResult.IdToken;
|
|
185
|
-
const accessToken = authResult === null || authResult === void 0 ? void 0 : authResult.AccessToken;
|
|
186
|
-
const refreshToken = authResult === null || authResult === void 0 ? void 0 : authResult.RefreshToken;
|
|
187
|
-
const tokenExpiry = authResult === null || authResult === void 0 ? void 0 : authResult.ExpiresIn;
|
|
188
|
-
|
|
189
|
-
if (idToken && accessToken && refreshToken && tokenExpiry) {
|
|
190
|
-
const authTokens = {
|
|
191
|
-
idToken: idToken,
|
|
192
|
-
accessToken: accessToken,
|
|
193
|
-
refreshToken: refreshToken,
|
|
194
|
-
tokenExpiry: tokenExpiry
|
|
195
|
-
};
|
|
196
|
-
await this.storeRefreshTokenLifetime(this.refreshTokenLifetime);
|
|
197
|
-
resolve(authTokens);
|
|
198
|
-
} else {
|
|
199
|
-
reject(new _sudoCommon.AuthenticationError('Authentication tokens not found.'));
|
|
200
|
-
}
|
|
201
|
-
} else {
|
|
202
|
-
reject(new _sudoCommon.AuthenticationError('Invalid initiate auth result.'));
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async refreshTokens(refreshToken) {
|
|
208
|
-
return new Promise(async (resolve, reject) => {
|
|
209
|
-
try {
|
|
210
|
-
var _initiateAuthResult$A, _initiateAuthResult$A2, _initiateAuthResult$A3;
|
|
211
|
-
|
|
212
|
-
const initiateAuth = new _clientCognitoIdentityProvider.InitiateAuthCommand({
|
|
213
|
-
ClientId: this.config.identityService.clientId,
|
|
214
|
-
AuthFlow: 'REFRESH_TOKEN_AUTH',
|
|
215
|
-
AuthParameters: {
|
|
216
|
-
REFRESH_TOKEN: refreshToken
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
const initiateAuthResult = await this.idpService.send(initiateAuth);
|
|
220
|
-
const idToken = (_initiateAuthResult$A = initiateAuthResult.AuthenticationResult) === null || _initiateAuthResult$A === void 0 ? void 0 : _initiateAuthResult$A.IdToken;
|
|
221
|
-
const accessToken = (_initiateAuthResult$A2 = initiateAuthResult.AuthenticationResult) === null || _initiateAuthResult$A2 === void 0 ? void 0 : _initiateAuthResult$A2.AccessToken;
|
|
222
|
-
const tokenExpiry = (_initiateAuthResult$A3 = initiateAuthResult.AuthenticationResult) === null || _initiateAuthResult$A3 === void 0 ? void 0 : _initiateAuthResult$A3.ExpiresIn;
|
|
223
|
-
|
|
224
|
-
if (idToken && accessToken && tokenExpiry) {
|
|
225
|
-
const authTokens = {
|
|
226
|
-
idToken: idToken,
|
|
227
|
-
accessToken: accessToken,
|
|
228
|
-
refreshToken: refreshToken,
|
|
229
|
-
tokenExpiry: tokenExpiry
|
|
230
|
-
};
|
|
231
|
-
await this.storeRefreshTokenLifetime(this.refreshTokenLifetime);
|
|
232
|
-
resolve(authTokens);
|
|
233
|
-
} else {
|
|
234
|
-
reject(new _sudoCommon.AuthenticationError('Authentication tokens not found.'));
|
|
235
|
-
}
|
|
236
|
-
} catch (err) {
|
|
237
|
-
const error = err;
|
|
238
|
-
reject(new _sudoCommon.AuthenticationError(error.message));
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
async signOut(refreshToken) {
|
|
244
|
-
return new Promise((resolve, reject) => {
|
|
245
|
-
const params = {
|
|
246
|
-
Token: refreshToken,
|
|
247
|
-
ClientId: this.config.identityService.clientId
|
|
248
|
-
};
|
|
249
|
-
const revokeToken = new _clientCognitoIdentityProvider.RevokeTokenCommand(params);
|
|
250
|
-
this.idpService.send(revokeToken, (error, data) => {
|
|
251
|
-
if (error) {
|
|
252
|
-
this.logger.error(error.message);
|
|
253
|
-
reject(new _sudoCommon.SignOutError(error.message));
|
|
254
|
-
} else {
|
|
255
|
-
this.logger.info('User successfully signed out.', {
|
|
256
|
-
data
|
|
257
|
-
});
|
|
258
|
-
resolve();
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
async storeRefreshTokenLifetime(refreshTokenLifetime) {
|
|
265
|
-
const tokenLifetime = refreshTokenLifetime * 24 * 60 * 60 * 1000 + new Date().getTime();
|
|
266
|
-
await this.keyManager.removeItem(_apiKeyNames.apiKeyNames.refreshTokenExpiry);
|
|
267
|
-
await this.keyManager.addString(_apiKeyNames.apiKeyNames.refreshTokenExpiry, tokenLifetime.toString());
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
exports.CognitoUserPoolIdentityProvider = CognitoUserPoolIdentityProvider;
|