@sudoplatform/sudo-user 11.1.0 → 12.0.2

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