@sudoplatform/sudo-user 11.0.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.
Files changed (180) hide show
  1. package/{lib → cjs/src}/client/apiClient.d.ts +0 -0
  2. package/cjs/src/client/apiClient.js +149 -0
  3. package/cjs/src/client/apiClient.js.map +1 -0
  4. package/{lib → cjs/src}/core/api-key-names.d.ts +0 -0
  5. package/cjs/src/core/api-key-names.js +12 -0
  6. package/cjs/src/core/api-key-names.js.map +1 -0
  7. package/{lib → cjs/src}/core/auth-store.d.ts +0 -0
  8. package/cjs/src/core/auth-store.js +92 -0
  9. package/cjs/src/core/auth-store.js.map +1 -0
  10. package/{lib → cjs/src}/core/crypto.d.ts +0 -0
  11. package/cjs/src/core/crypto.js +3 -0
  12. package/cjs/src/core/crypto.js.map +1 -0
  13. package/{lib → cjs/src}/core/key-manager.d.ts +0 -0
  14. package/cjs/src/core/key-manager.js +113 -0
  15. package/cjs/src/core/key-manager.js.map +1 -0
  16. package/cjs/src/core/protected-store.d.ts +5 -0
  17. package/cjs/src/core/protected-store.js +3 -0
  18. package/cjs/src/core/protected-store.js.map +1 -0
  19. package/{lib → cjs/src}/core/publisher.d.ts +0 -0
  20. package/cjs/src/core/publisher.js +3 -0
  21. package/cjs/src/core/publisher.js.map +1 -0
  22. package/{lib → cjs/src}/core/sdk-config.d.ts +0 -0
  23. package/cjs/src/core/sdk-config.js +61 -0
  24. package/cjs/src/core/sdk-config.js.map +1 -0
  25. package/{lib → cjs/src}/core/subscriber.d.ts +0 -0
  26. package/cjs/src/core/subscriber.js +3 -0
  27. package/cjs/src/core/subscriber.js.map +1 -0
  28. package/{lib → cjs/src}/gen/graphql-types.d.ts +0 -0
  29. package/cjs/src/gen/graphql-types.js +105 -0
  30. package/cjs/src/gen/graphql-types.js.map +1 -0
  31. package/{lib → cjs/src}/index.d.ts +0 -0
  32. package/cjs/src/index.js +13 -0
  33. package/cjs/src/index.js.map +1 -0
  34. package/{lib/runtimes/node/node-crypto.d.ts → cjs/src/runtimes/browser/browser-crypto.d.ts} +0 -0
  35. package/cjs/src/runtimes/browser/browser-crypto.js +10 -0
  36. package/cjs/src/runtimes/browser/browser-crypto.js.map +1 -0
  37. package/cjs/src/runtimes/node/node-crypto.d.ts +2 -0
  38. package/cjs/src/runtimes/node/node-crypto.js +9 -0
  39. package/cjs/src/runtimes/node/node-crypto.js.map +1 -0
  40. package/{lib → cjs/src}/sdk.d.ts +0 -0
  41. package/cjs/src/sdk.js +9 -0
  42. package/cjs/src/sdk.js.map +1 -0
  43. package/{lib → cjs/src}/user/auth-provider.d.ts +0 -0
  44. package/cjs/src/user/auth-provider.js +116 -0
  45. package/cjs/src/user/auth-provider.js.map +1 -0
  46. package/{lib → cjs/src}/user/auth.d.ts +0 -0
  47. package/cjs/src/user/auth.js +136 -0
  48. package/cjs/src/user/auth.js.map +1 -0
  49. package/{lib → cjs/src}/user/error.d.ts +0 -0
  50. package/{lib → cjs/src}/user/error.js +16 -29
  51. package/cjs/src/user/error.js.map +1 -0
  52. package/{lib → cjs/src}/user/identity-provider.d.ts +0 -0
  53. package/cjs/src/user/identity-provider.js +245 -0
  54. package/cjs/src/user/identity-provider.js.map +1 -0
  55. package/{lib → cjs/src}/user/user-client-interface.d.ts +0 -0
  56. package/cjs/src/user/user-client-interface.js +3 -0
  57. package/cjs/src/user/user-client-interface.js.map +1 -0
  58. package/{lib → cjs/src}/user/user-client.d.ts +0 -0
  59. package/cjs/src/user/user-client.js +440 -0
  60. package/cjs/src/user/user-client.js.map +1 -0
  61. package/{lib → cjs/src}/user/user-key-names.d.ts +0 -0
  62. package/cjs/src/user/user-key-names.js +10 -0
  63. package/cjs/src/user/user-key-names.js.map +1 -0
  64. package/{lib → cjs/src}/utils/resolvable-promise.d.ts +0 -0
  65. package/cjs/src/utils/resolvable-promise.js +20 -0
  66. package/cjs/src/utils/resolvable-promise.js.map +1 -0
  67. package/cjs/test/integration/user-client-int.spec.d.ts +1 -0
  68. package/cjs/test/integration/user-client-int.spec.js +206 -0
  69. package/cjs/test/integration/user-client-int.spec.js.map +1 -0
  70. package/cjs/test/unit/core/sdk-config.spec.d.ts +1 -0
  71. package/cjs/test/unit/core/sdk-config.spec.js +51 -0
  72. package/cjs/test/unit/core/sdk-config.spec.js.map +1 -0
  73. package/cjs/test/unit/key-manager.spec.d.ts +1 -0
  74. package/cjs/test/unit/key-manager.spec.js +23 -0
  75. package/cjs/test/unit/key-manager.spec.js.map +1 -0
  76. package/cjs/test/unit/user-client.spec.d.ts +1 -0
  77. package/cjs/test/unit/user-client.spec.js +323 -0
  78. package/cjs/test/unit/user-client.spec.js.map +1 -0
  79. package/docs/classes/AlreadyRegisteredError.html +4 -4
  80. package/docs/classes/IdentityServiceConfigNotFoundError.html +4 -4
  81. package/lib/src/client/apiClient.d.ts +25 -0
  82. package/lib/src/client/apiClient.js +145 -0
  83. package/lib/src/client/apiClient.js.map +1 -0
  84. package/lib/src/core/api-key-names.d.ts +8 -0
  85. package/lib/src/core/api-key-names.js +9 -0
  86. package/lib/src/core/api-key-names.js.map +1 -0
  87. package/lib/src/core/auth-store.d.ts +51 -0
  88. package/lib/src/core/auth-store.js +88 -0
  89. package/lib/src/core/auth-store.js.map +1 -0
  90. package/lib/src/core/crypto.d.ts +3 -0
  91. package/lib/src/core/crypto.js +2 -0
  92. package/lib/src/core/crypto.js.map +1 -0
  93. package/lib/src/core/key-manager.d.ts +31 -0
  94. package/lib/src/core/key-manager.js +108 -0
  95. package/lib/src/core/key-manager.js.map +1 -0
  96. package/lib/src/core/protected-store.d.ts +5 -0
  97. package/lib/src/core/protected-store.js +2 -0
  98. package/lib/src/core/protected-store.js.map +1 -0
  99. package/lib/src/core/publisher.d.ts +6 -0
  100. package/lib/src/core/publisher.js +2 -0
  101. package/lib/src/core/publisher.js.map +1 -0
  102. package/lib/src/core/sdk-config.d.ts +52 -0
  103. package/lib/src/core/sdk-config.js +56 -0
  104. package/lib/src/core/sdk-config.js.map +1 -0
  105. package/lib/src/core/subscriber.d.ts +3 -0
  106. package/lib/src/core/subscriber.js +2 -0
  107. package/lib/src/core/subscriber.js.map +1 -0
  108. package/lib/src/gen/graphql-types.d.ts +101 -0
  109. package/lib/src/gen/graphql-types.js +102 -0
  110. package/lib/src/gen/graphql-types.js.map +1 -0
  111. package/lib/src/index.d.ts +4 -0
  112. package/lib/src/index.js +6 -0
  113. package/lib/src/index.js.map +1 -0
  114. package/lib/src/runtimes/browser/browser-crypto.d.ts +2 -0
  115. package/lib/src/runtimes/browser/browser-crypto.js +7 -0
  116. package/lib/src/runtimes/browser/browser-crypto.js.map +1 -0
  117. package/lib/src/runtimes/node/node-crypto.d.ts +2 -0
  118. package/lib/src/runtimes/node/node-crypto.js +6 -0
  119. package/lib/src/runtimes/node/node-crypto.js.map +1 -0
  120. package/lib/src/sdk.d.ts +1 -0
  121. package/lib/src/sdk.js +6 -0
  122. package/lib/src/sdk.js.map +1 -0
  123. package/lib/src/user/auth-provider.d.ts +97 -0
  124. package/lib/src/user/auth-provider.js +108 -0
  125. package/lib/src/user/auth-provider.js.map +1 -0
  126. package/lib/src/user/auth.d.ts +64 -0
  127. package/lib/src/user/auth.js +131 -0
  128. package/lib/src/user/auth.js.map +1 -0
  129. package/lib/src/user/error.d.ts +18 -0
  130. package/lib/src/user/error.js +28 -0
  131. package/lib/src/user/error.js.map +1 -0
  132. package/lib/src/user/identity-provider.d.ts +73 -0
  133. package/lib/src/user/identity-provider.js +241 -0
  134. package/lib/src/user/identity-provider.js.map +1 -0
  135. package/lib/src/user/user-client-interface.d.ts +168 -0
  136. package/lib/src/user/user-client-interface.js +2 -0
  137. package/lib/src/user/user-client-interface.js.map +1 -0
  138. package/lib/src/user/user-client.d.ts +82 -0
  139. package/lib/src/user/user-client.js +435 -0
  140. package/lib/src/user/user-client.js.map +1 -0
  141. package/lib/src/user/user-key-names.d.ts +6 -0
  142. package/lib/src/user/user-key-names.js +7 -0
  143. package/lib/src/user/user-key-names.js.map +1 -0
  144. package/lib/src/utils/resolvable-promise.d.ts +9 -0
  145. package/lib/src/utils/resolvable-promise.js +16 -0
  146. package/lib/src/utils/resolvable-promise.js.map +1 -0
  147. package/lib/test/integration/user-client-int.spec.d.ts +1 -0
  148. package/lib/test/integration/user-client-int.spec.js +203 -0
  149. package/lib/test/integration/user-client-int.spec.js.map +1 -0
  150. package/lib/test/unit/core/sdk-config.spec.d.ts +1 -0
  151. package/lib/test/unit/core/sdk-config.spec.js +49 -0
  152. package/lib/test/unit/core/sdk-config.spec.js.map +1 -0
  153. package/lib/test/unit/key-manager.spec.d.ts +1 -0
  154. package/lib/test/unit/key-manager.spec.js +21 -0
  155. package/lib/test/unit/key-manager.spec.js.map +1 -0
  156. package/lib/test/unit/user-client.spec.d.ts +1 -0
  157. package/lib/test/unit/user-client.spec.js +320 -0
  158. package/lib/test/unit/user-client.spec.js.map +1 -0
  159. package/package.json +23 -22
  160. package/lib/client/apiClient.js +0 -190
  161. package/lib/core/api-key-names.js +0 -15
  162. package/lib/core/auth-store.js +0 -144
  163. package/lib/core/crypto.js +0 -5
  164. package/lib/core/key-manager.js +0 -158
  165. package/lib/core/protected-store.js +0 -5
  166. package/lib/core/publisher.js +0 -5
  167. package/lib/core/sdk-config.js +0 -56
  168. package/lib/core/subscriber.js +0 -5
  169. package/lib/gen/graphql-types.js +0 -141
  170. package/lib/index.js +0 -67
  171. package/lib/runtimes/browser/browser-crypto.js +0 -15
  172. package/lib/runtimes/node/node-crypto.js +0 -12
  173. package/lib/sdk.js +0 -18
  174. package/lib/user/auth-provider.js +0 -158
  175. package/lib/user/auth.js +0 -183
  176. package/lib/user/identity-provider.js +0 -270
  177. package/lib/user/user-client-interface.js +0 -5
  178. package/lib/user/user-client.js +0 -522
  179. package/lib/user/user-key-names.js +0 -13
  180. package/lib/utils/resolvable-promise.js +0 -22
@@ -0,0 +1,320 @@
1
+ import { CognitoAuthUI } from '../../src/user/auth';
2
+ import { DefaultSudoUserClient } from '../../src/user/user-client';
3
+ import { Config } from '../../src/core/sdk-config';
4
+ import { mock, instance, when, reset, anyString } from 'ts-mockito';
5
+ import * as JWT from 'jsonwebtoken';
6
+ import { generateKeyPairSync } from 'crypto';
7
+ import { apiKeyNames } from '../../src/core/api-key-names';
8
+ import { AuthenticationError, DefaultConfigurationManager, DefaultLogger, NotSignedInError, } from '@sudoplatform/sudo-common';
9
+ import { generateKeyPair } from 'crypto';
10
+ import { promisify } from 'util';
11
+ import { LocalAuthenticationProvider } from '../../src/user/auth-provider';
12
+ import { userKeyNames } from '../../src/user/user-key-names';
13
+ const generateKeyPairAsync = promisify(generateKeyPair);
14
+ const globalAny = global;
15
+ globalAny.WebSocket = require('ws');
16
+ require('isomorphic-fetch');
17
+ const testConfig = {
18
+ federatedSignIn: {
19
+ appClientId: '120q904mra9d5l4psmvdbrgm49',
20
+ signInRedirectUri: 'http://localhost:3000/callback',
21
+ signOutRedirectUri: 'http://localhost:3000/',
22
+ webDomain: 'id-dev-fsso-sudoplatform.auth.us-east-1.amazoncognito.com',
23
+ },
24
+ identityService: {
25
+ region: 'us-east-1',
26
+ poolId: 'us-east-1_ZiPDToF73',
27
+ clientId: '120q904mra9d5l4psmvdbrgm49',
28
+ identityPoolId: 'us-east-1:8fe6d8ed-cd77-4622-b1bb-3f0c147638ad',
29
+ apiUrl: 'https://mqn7cjrzcrd75jpsma3xw4744a.appsync-api.us-east-1.amazonaws.com/graphql',
30
+ apiKey: 'da2-xejsa343urfifmzkycmz3rqdom',
31
+ bucket: 'ids-userdata-id-dev-fsso-userdatabucket2d841c35-j9x47k5042fk',
32
+ transientBucket: 'ids-userdata-id-dev-fsso-transientuserdatabucket0-1enoeyoho1sjl',
33
+ registrationMethods: ['TEST', 'FSSO'],
34
+ },
35
+ };
36
+ const privateKey = generateKeyPairSync('rsa', {
37
+ modulusLength: 2048,
38
+ publicKeyEncoding: {
39
+ format: 'pem',
40
+ type: 'pkcs1',
41
+ },
42
+ privateKeyEncoding: {
43
+ format: 'pem',
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8IYgnEwyfoDu3Lz5-fb2tBCANz4lykW5lzS7-FxCZ2Ba4Ywr89b2cCayp3Aw3dVSHwwPtFu7-odwnHR9tpZd7jHeIVBlKQIn0WLppRTU9H1AIJh8Pq9FS6YK7uIFaOmNZxe_S18HlT8GQJNwqPZk4P8QEVyazKN9fKidO8EcQVrJoCZnJHCPP9hzum7yo2HJWvWhhlN2Si-VnqfCwDG4hpig9NcCUkGbrOYKCpDjCRZhBhcnpec310X8Lf3Qya8wZEFs1IcYHnhdKpfX4A1DYLQ';
49
+ function customLaunchUriFunction(url) {
50
+ location.replace(url);
51
+ }
52
+ function toArrayBuffer(value) {
53
+ return new TextEncoder().encode(value).buffer;
54
+ }
55
+ const authUIMock = mock();
56
+ const authUI = instance(authUIMock);
57
+ const identityProviderMock = mock();
58
+ const identityProvider = instance(identityProviderMock);
59
+ const authenticationStoreMock = mock();
60
+ const authenticationStore = instance(authenticationStoreMock);
61
+ const keyManagerMock = mock();
62
+ const keyManager = instance(keyManagerMock);
63
+ const sudoKeyManagerMock = mock();
64
+ const sudoKeyManager = instance(sudoKeyManagerMock);
65
+ const apiClientMock = mock();
66
+ const apiClient = instance(apiClientMock);
67
+ DefaultConfigurationManager.getInstance().setConfig(JSON.stringify(testConfig));
68
+ const userClient = new DefaultSudoUserClient({
69
+ authenticationStore,
70
+ apiClient,
71
+ authUI,
72
+ identityProvider,
73
+ sudoKeyManager,
74
+ });
75
+ const config = DefaultConfigurationManager.getInstance().bindConfigSet(Config, undefined);
76
+ const logger = new DefaultLogger();
77
+ afterEach(() => {
78
+ reset(authUIMock);
79
+ reset(authenticationStoreMock);
80
+ reset(keyManagerMock);
81
+ reset(sudoKeyManagerMock);
82
+ reset(identityProviderMock);
83
+ userClient.setAuthUI(authUI);
84
+ userClient.setIdentityProvider(identityProvider);
85
+ });
86
+ describe('SudoUserClient', () => {
87
+ describe('presentFederatedSignInUI()', () => {
88
+ it('should fail with authentication error - default launchUri - attempt to launch UI with window.open', async () => {
89
+ if (!config.federatedSignIn) {
90
+ fail('federatedSignIn unexpectedly falsy');
91
+ }
92
+ const authUI = new CognitoAuthUI(authenticationStore, config.federatedSignIn, keyManager, logger);
93
+ userClient.setAuthUI(authUI);
94
+ expect(() => userClient.presentFederatedSignInUI()).toThrowError(AuthenticationError);
95
+ });
96
+ it('should fail with authentication error - custom launchUri - attempt to launch UI with location.replace(url)', async () => {
97
+ if (!config.federatedSignIn) {
98
+ fail('federatedSignIn unexpectedly falsy');
99
+ }
100
+ const authUI = new CognitoAuthUI(authenticationStore, config.federatedSignIn, keyManager, logger, customLaunchUriFunction);
101
+ userClient.setAuthUI(authUI);
102
+ expect(() => userClient.presentFederatedSignInUI()).toThrowError(AuthenticationError);
103
+ });
104
+ });
105
+ describe('processFederatedSignInTokens()', () => {
106
+ it('should complete successfully', async () => {
107
+ when(authUIMock.processFederatedSignInTokens('dummy_url')).thenResolve({
108
+ idToken: 'dummy_id_token',
109
+ accessToken: 'dummy_access_token',
110
+ refreshToken: 'dummy_refresh_token',
111
+ tokenExpiry: 12345,
112
+ });
113
+ when(sudoKeyManagerMock.getPassword(userKeyNames.userId)).thenResolve(toArrayBuffer('dummy_username'));
114
+ when(identityProviderMock.refreshTokens('dummy_refresh_token')).thenResolve({
115
+ idToken: mockIdToken,
116
+ accessToken: 'dummy_access_token',
117
+ refreshToken: 'dummy_refresh_token',
118
+ tokenExpiry: 12345,
119
+ });
120
+ const authTokens = await userClient.processFederatedSignInTokens('dummy_url');
121
+ expect(authTokens.idToken).toBe(mockIdToken);
122
+ expect(authTokens.accessToken).toBe('dummy_access_token');
123
+ expect(authTokens.refreshToken).toBe('dummy_refresh_token');
124
+ expect(authTokens.tokenExpiry).toBe(12345);
125
+ });
126
+ it('should fail with authentication error', async () => {
127
+ when(authUIMock.processFederatedSignInTokens('dummy_url')).thenReject();
128
+ await expect(userClient.processFederatedSignInTokens('dummy_url')).rejects.toThrowError(AuthenticationError);
129
+ });
130
+ });
131
+ describe('getSubject()', () => {
132
+ const token = JWT.sign({}, privateKey, {
133
+ jwtid: '123',
134
+ audience: 'testAudience',
135
+ expiresIn: '10s',
136
+ notBefore: '0m',
137
+ subject: 'dummy_sub',
138
+ issuer: 'https://test.sudoplatform.com',
139
+ header: { alg: 'RS256', kid },
140
+ algorithm: 'RS256',
141
+ });
142
+ it('should complete successfully', async () => {
143
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.idToken)).thenResolve(toArrayBuffer(token));
144
+ const sub = await userClient.getSubject();
145
+ expect(sub).toBe('dummy_sub');
146
+ });
147
+ });
148
+ describe('getUserName()', () => {
149
+ it('should complete successfully', async () => {
150
+ when(sudoKeyManagerMock.getPassword(userKeyNames.userId)).thenResolve(toArrayBuffer('test_user'));
151
+ const userName = await userClient.getUserName();
152
+ expect(userName).toBe('test_user');
153
+ });
154
+ });
155
+ describe('refreshTokens()', () => {
156
+ it('should complete successfully', async () => {
157
+ when(sudoKeyManagerMock.getPassword(userKeyNames.userId)).thenResolve(toArrayBuffer('test_user'));
158
+ when(identityProviderMock.refreshTokens('refresh_token')).thenResolve({
159
+ idToken: 'dummy_id_token',
160
+ accessToken: 'dummy_access_token',
161
+ refreshToken: 'dummy_refresh_token',
162
+ tokenExpiry: 12345,
163
+ });
164
+ const authTokens = await userClient.refreshTokens('refresh_token');
165
+ expect(authTokens.idToken).toBe('dummy_id_token');
166
+ expect(authTokens.accessToken).toBe('dummy_access_token');
167
+ expect(authTokens.refreshToken).toBe('dummy_refresh_token');
168
+ expect(authTokens.tokenExpiry).toBe(12345);
169
+ });
170
+ it('should fail with authentication error', async () => {
171
+ when(sudoKeyManagerMock.getPassword(userKeyNames.userId)).thenResolve(toArrayBuffer('test_user'));
172
+ when(identityProviderMock.refreshTokens('refresh_token')).thenReject();
173
+ await expect(userClient.refreshTokens('refresh_token')).rejects.toThrowError(AuthenticationError);
174
+ });
175
+ });
176
+ describe('getLatestAuthToken()', () => {
177
+ it('should complete successfully', async () => {
178
+ const tokenExpiry = new Date().getTime() + 3600000;
179
+ const validTokenExpiry = tokenExpiry / 1000;
180
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.idToken)).thenResolve(toArrayBuffer('dummy_id_token'));
181
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.refreshToken)).thenResolve(toArrayBuffer('dummy_refresh_token'));
182
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.tokenExpiry)).thenResolve(toArrayBuffer(validTokenExpiry.toString()));
183
+ const idToken = await userClient.getLatestAuthToken();
184
+ expect(idToken).toBe('dummy_id_token');
185
+ });
186
+ it('should return empty token - user not signed in', async () => {
187
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.idToken)).thenResolve();
188
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.refreshToken)).thenResolve();
189
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.tokenExpiry)).thenResolve();
190
+ const empty = '';
191
+ const idToken = await userClient.getLatestAuthToken();
192
+ expect(idToken).toBe(empty);
193
+ });
194
+ it('should return empty token - error encountered calling refreshTokens', async () => {
195
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.idToken)).thenResolve(toArrayBuffer('id_token'));
196
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.refreshToken)).thenResolve(toArrayBuffer('refresh_token'));
197
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.tokenExpiry)).thenResolve(toArrayBuffer('100'));
198
+ when(identityProviderMock.refreshTokens('refresh_token')).thenReject();
199
+ const empty = '';
200
+ const idToken = await userClient.getLatestAuthToken();
201
+ expect(idToken).toBe(empty);
202
+ });
203
+ });
204
+ describe('signOut()', () => {
205
+ it('should complete successfully', async () => {
206
+ let isSignedOut = false;
207
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.refreshToken)).thenResolve(toArrayBuffer('dummy_refresh_token'));
208
+ await userClient.signOut();
209
+ isSignedOut = true;
210
+ expect(isSignedOut).toBeTruthy();
211
+ });
212
+ it('should fail if not signed in', async () => {
213
+ await expect(userClient.signOut()).rejects.toThrowError(NotSignedInError);
214
+ });
215
+ });
216
+ describe('globalSignOut()', () => {
217
+ it('should complete successfully', async () => {
218
+ let isSignedOut = false;
219
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.idToken)).thenResolve(toArrayBuffer('dummy_id_token'));
220
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.accessToken)).thenResolve(toArrayBuffer('dummy_access_token'));
221
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.refreshToken)).thenResolve(toArrayBuffer('dummy_refresh_token'));
222
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.tokenExpiry)).thenResolve(toArrayBuffer(Number(new Date().getTime() + 60 * 1000).toString()));
223
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.refreshTokenExpiry)).thenResolve(toArrayBuffer(Number(new Date().getTime() + 60 * 60 * 1000 + 10000).toString()));
224
+ await userClient.globalSignOut();
225
+ isSignedOut = true;
226
+ expect(isSignedOut).toBeTruthy();
227
+ });
228
+ it('should fail if not signed in', async () => {
229
+ await expect(userClient.globalSignOut()).rejects.toThrowError(NotSignedInError);
230
+ });
231
+ });
232
+ describe('presentSignOutUI()', () => {
233
+ it('should fail trying to invoke signout url - attempt to launch UI with window.open', async () => {
234
+ if (!config.federatedSignIn) {
235
+ fail('federatedSignIn unexpectedly falsy');
236
+ }
237
+ const authUI = new CognitoAuthUI(authenticationStore, config.federatedSignIn, keyManager, logger);
238
+ userClient.setAuthUI(authUI);
239
+ expect(() => userClient.presentSignOutUI()).toThrowError(new Error('window is not defined'));
240
+ });
241
+ });
242
+ describe('isSignedIn()', () => {
243
+ it('should complete successfully', async () => {
244
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.idToken)).thenResolve(toArrayBuffer('dummy_id_token'));
245
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.accessToken)).thenResolve(toArrayBuffer('dummy_access_token'));
246
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.refreshToken)).thenResolve(toArrayBuffer('dummy_refresh_token'));
247
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.tokenExpiry)).thenResolve(toArrayBuffer(Number(new Date().getTime() + 60 * 1000).toString()));
248
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.refreshTokenExpiry)).thenResolve(toArrayBuffer(Number(new Date().getTime() + 60 * 60 * 1000 + 10000).toString()));
249
+ expect(await userClient.isSignedIn()).toBeTruthy();
250
+ });
251
+ });
252
+ describe('customFSSO()', () => {
253
+ it('should complete successfully', async () => {
254
+ const keyPair = await generateKeyPairAsync('rsa', {
255
+ modulusLength: 2048,
256
+ publicKeyEncoding: {
257
+ format: 'pem',
258
+ type: 'pkcs1',
259
+ },
260
+ privateKeyEncoding: {
261
+ format: 'pem',
262
+ type: 'pkcs1',
263
+ },
264
+ });
265
+ const authenticationProvider = new LocalAuthenticationProvider('client_system_test_iss', keyPair.privateKey, 'dummy_key_id', 'dummy_username');
266
+ const authInfo = await authenticationProvider.getAuthenticationInfo();
267
+ expect(authInfo.isValid()).toBeTruthy();
268
+ expect(authInfo.getUsername()).toBe('dummy_username');
269
+ const token = authInfo.encode();
270
+ const decoded = JWT.decode(token, { complete: true });
271
+ expect(decoded.header['kid']).toBe('dummy_key_id');
272
+ const verified = JWT.verify(token, keyPair.publicKey, {
273
+ issuer: 'client_system_test_iss',
274
+ audience: 'identity-service',
275
+ subject: 'dummy_username',
276
+ algorithms: ['RS256'],
277
+ });
278
+ expect(verified).toBeTruthy();
279
+ const authUIMock = mock();
280
+ const authUI = instance(authUIMock);
281
+ userClient.setAuthUI(authUI);
282
+ when(identityProviderMock.signInWithToken('dummy_username', anyString(), 'FSSO')).thenResolve({
283
+ idToken: mockIdToken,
284
+ accessToken: 'dummy_access_token',
285
+ refreshToken: 'dummy_refresh_token',
286
+ tokenExpiry: 1,
287
+ });
288
+ when(keyManagerMock.getString(apiKeyNames.idToken)).thenResolve(mockIdToken);
289
+ when(sudoKeyManagerMock.getPassword(apiKeyNames.idToken)).thenResolve(toArrayBuffer(mockIdToken));
290
+ const tokens = await userClient.signInWithAuthenticationProvider(authenticationProvider);
291
+ expect(tokens.idToken).toBe(mockIdToken);
292
+ expect(tokens.accessToken).toBe('dummy_access_token');
293
+ expect(tokens.refreshToken).toBe('dummy_refresh_token');
294
+ expect(tokens.tokenExpiry).toBe(1);
295
+ expect(await userClient.getUserClaim('custom:identityId')).toBeTruthy();
296
+ });
297
+ });
298
+ describe('disabledUser()', () => {
299
+ it('signInWithToken should fail due to user being disabled', async () => {
300
+ const keyPair = await generateKeyPairAsync('rsa', {
301
+ modulusLength: 2048,
302
+ publicKeyEncoding: {
303
+ format: 'pem',
304
+ type: 'pkcs1',
305
+ },
306
+ privateKeyEncoding: {
307
+ format: 'pem',
308
+ type: 'pkcs1',
309
+ },
310
+ });
311
+ const authenticationProvider = new LocalAuthenticationProvider('client_system_test_iss', keyPair.privateKey, 'dummy_key_id', 'disabled_username');
312
+ const authInfo = await authenticationProvider.getAuthenticationInfo();
313
+ expect(authInfo.isValid()).toBeTruthy();
314
+ expect(authInfo.getUsername()).toBe('disabled_username');
315
+ when(identityProviderMock.signInWithToken('disabled_username', anyString(), anyString())).thenReject(new AuthenticationError('User disabled')); // reject due to user disabled error being returned from Cognito
316
+ await expect(userClient.signInWithAuthenticationProvider(authenticationProvider)).rejects.toThrowError(AuthenticationError);
317
+ });
318
+ });
319
+ });
320
+ //# sourceMappingURL=user-client.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-client.spec.js","sourceRoot":"","sources":["../../../test/unit/user-client.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAElD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACnE,OAAO,KAAK,GAAG,MAAM,c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AAO;iBACd;aACF,CAAC,CAAA;YAEF,MAAM,sBAAsB,GAAG,IAAI,2BAA2B,CAC5D,wBAAwB,EACxB,OAAO,CAAC,UAAU,EAClB,cAAc,EACd,mBAAmB,CACpB,CAAA;YAED,MAAM,QAAQ,GAAG,MAAM,sBAAsB,CAAC,qBAAqB,EAAE,CAAA;YACrE,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE,CAAA;YACvC,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;YAExD,IAAI,CACF,oBAAoB,CAAC,eAAe,CAClC,mBAAmB,EACnB,SAAS,EAAE,EACX,SAAS,EAAE,CACZ,CACF,CAAC,UAAU,CAAC,IAAI,mBAAmB,CAAC,eAAe,CAAC,CAAC,CAAA,CAAC,gEAAgE;YAEvH,MAAM,MAAM,CACV,UAAU,CAAC,gCAAgC,CAAC,sBAAsB,CAAC,CACpE,CAAC,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAA;QAC7C,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudoplatform/sudo-user",
3
- "version": "11.0.0",
3
+ "version": "12.0.0",
4
4
  "author": "Anonyome Labs, Inc.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,20 +11,24 @@
11
11
  "prepare": "husky install",
12
12
  "lint": "yarn lint:eslint && yarn lint:prettier",
13
13
  "lint:eslint": "eslint \"{bin,test,src}/**/*.{ts,tsx}\"",
14
- "lint:prettier": "prettier -l \"{bin,test,src}/**/*.{js,json,jsx,ts,tsx}\"",
14
+ "lint:prettier": "prettier -l \"{bin,test,src}/**/*.{js,json,jsx,ts,tsx,yml}\"",
15
15
  "codegen": "graphql-codegen -c codegen.yml",
16
16
  "verify": "yarn audit && yarn lint",
17
17
  "unit-test": "yarn jest test/unit --verbose --coverage",
18
18
  "integration-test": "/bin/bash -c 'jest test/integration'",
19
19
  "test": "yarn unit-test",
20
- "build": "yarn codegen && yarn verify && yarn build:transpile && yarn build:declarations && yarn build:docs",
21
- "build:transpile": "babel src --out-dir lib --extensions '.ts'",
22
- "build:declarations": "tsc --project tsconfig.declarations.json",
20
+ "build": "yarn codegen && yarn verify && yarn build:transpile && yarn build:docs",
21
+ "build:transpile": "concurrently \"yarn build:transpile:cjs\" \"yarn build:transpile:esm\"",
22
+ "build:transpile:cjs": "tsc --project tsconfig.commonjs.json",
23
+ "build:transpile:esm": "tsc",
23
24
  "build:docs": "typedoc --excludePrivate --out docs src/index.ts"
24
25
  },
25
- "main": "lib/index.js",
26
- "types": "lib/index.d.ts",
26
+ "main": "./cjs/index.js",
27
+ "types": "./cjs/index.d.ts",
28
+ "module": "./lib/index.js",
29
+ "sideEffects": false,
27
30
  "files": [
31
+ "cjs",
28
32
  "lib",
29
33
  "docs",
30
34
  "types"
@@ -35,7 +39,7 @@
35
39
  "dependencies": {
36
40
  "@aws-sdk/client-cognito-identity-provider": "^3.131.0",
37
41
  "@graphql-typed-document-node/core": "^3.1.1",
38
- "@sudoplatform/sudo-web-crypto-provider": "^6.0.0",
42
+ "@sudoplatform/sudo-web-crypto-provider": "^7.0.0",
39
43
  "amazon-cognito-auth-js": "^1.3.3",
40
44
  "apollo-cache-inmemory": "^1.6.6",
41
45
  "aws-appsync": "^4.1.7",
@@ -58,16 +62,10 @@
58
62
  "cross-fetch": "^3.1.5",
59
63
  "node-fetch": "^2.6.7",
60
64
  "minimist": "^1.2.6",
61
- "undici": "^5.5.1",
65
+ "undici": "^5.8.2",
62
66
  "got": "^11.8.5"
63
67
  },
64
68
  "devDependencies": {
65
- "@babel/cli": "^7.18.9",
66
- "@babel/core": "^7.18.9",
67
- "@babel/plugin-proposal-class-properties": "^7.18.6",
68
- "@babel/plugin-proposal-private-methods": "^7.18.6",
69
- "@babel/preset-env": "^7.18.9",
70
- "@babel/preset-typescript": "^7.18.6",
71
69
  "@graphql-codegen/add": "^3.2.0",
72
70
  "@graphql-codegen/cli": "^2.9.1",
73
71
  "@graphql-codegen/plugin-helpers": "^2.6.0",
@@ -75,34 +73,37 @@
75
73
  "@graphql-codegen/typescript": "^2.7.2",
76
74
  "@graphql-codegen/typescript-operations": "^2.5.2",
77
75
  "@graphql-typed-document-node/apollo-client-2": "^1.0.0",
78
- "@sudoplatform/sudo-common": "^7.0.2",
76
+ "@sudoplatform/sudo-common": "^8.0.0",
79
77
  "@types/amazon-cognito-auth-js": "^1.3.0",
80
78
  "@types/firefox-webext-browser": "^94.0.1",
81
- "@types/jest": "^28.1.6",
79
+ "@types/jest": "^28.1.3",
82
80
  "@types/jsonwebtoken": "^8.5.8",
83
81
  "@types/lodash": "^4.14.182",
84
82
  "@types/node": "^16.11.45",
85
83
  "@types/uuid": "^8.3.4",
86
- "@typescript-eslint/eslint-plugin": "^5.30.7",
87
- "@typescript-eslint/parser": "^5.30.7",
84
+ "@typescript-eslint/eslint-plugin": "^5.33.1",
85
+ "@typescript-eslint/parser": "^5.33.1",
88
86
  "apollo-client": "^2.6.10",
89
- "eslint": "^8.20.0",
87
+ "concurrently": "^7.3.0",
88
+ "eslint": "^8.22.0",
90
89
  "eslint-config-prettier": "^8.5.0",
91
90
  "eslint-plugin-import": "^2.26.0",
92
91
  "eslint-plugin-prettier": "^4.2.1",
92
+ "eslint-plugin-tree-shaking": "^1.10.0",
93
93
  "husky": "^8.0.1",
94
94
  "isomorphic-fetch": "^3.0.0",
95
95
  "jest": "^28.1.3",
96
96
  "jest-environment-node": "^28.1.3",
97
97
  "prettier": "^2.7.1",
98
98
  "subscriptions-transport-ws": "^0.11.0",
99
+ "ts-jest": "^28.0.8",
99
100
  "ts-mockito": "^2.6.1",
100
- "typedoc": "^0.23.9",
101
+ "typedoc": "^0.23.10",
101
102
  "typescript": "^4.7.4",
102
103
  "websocket": "^1.0.34"
103
104
  },
104
105
  "peerDependencies": {
105
- "@sudoplatform/sudo-common": "^7.0.2",
106
+ "@sudoplatform/sudo-common": "^8.0.0",
106
107
  "io-ts": "^2.2.16"
107
108
  }
108
109
  }
@@ -1,190 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ApiClient = void 0;
7
-
8
- var _awsAppsync = require("aws-appsync");
9
-
10
- var _graphqlTypes = require("../gen/graphql-types");
11
-
12
- var _sudoCommon = require("@sudoplatform/sudo-common");
13
-
14
- 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; }
15
-
16
- /**
17
- * AppSync wrapper to use to invoke Identity Service APIs.
18
- */
19
- class ApiClient {
20
- constructor(region, graphqlUrl, sudoUserClient, logger) {
21
- _defineProperty(this, "client", void 0);
22
-
23
- _defineProperty(this, "region", void 0);
24
-
25
- _defineProperty(this, "graphqlUrl", void 0);
26
-
27
- _defineProperty(this, "sudoUserClient", void 0);
28
-
29
- _defineProperty(this, "logger", void 0);
30
-
31
- this.region = region;
32
- this.graphqlUrl = graphqlUrl;
33
- this.sudoUserClient = sudoUserClient;
34
- this.logger = logger;
35
- this.client = new _awsAppsync.AWSAppSyncClient({
36
- url: graphqlUrl,
37
- region: region,
38
- auth: {
39
- type: _awsAppsync.AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
40
- jwtToken: async () => await sudoUserClient.getLatestAuthToken()
41
- },
42
- disableOffline: true
43
- });
44
- }
45
-
46
- async deregister() {
47
- if (!(await this.sudoUserClient.isSignedIn())) {
48
- throw new _sudoCommon.NotSignedInError();
49
- }
50
-
51
- let result;
52
-
53
- try {
54
- result = await this.client.mutate({
55
- mutation: _graphqlTypes.DeregisterDocument,
56
- fetchPolicy: 'no-cache'
57
- });
58
- } catch (err) {
59
- const apolloError = err;
60
- const error = apolloError.graphQLErrors?.[0];
61
-
62
- if (error) {
63
- throw this.graphQLErrorsToClientError(error);
64
- } else {
65
- throw new _sudoCommon.UnknownGraphQLError(err);
66
- }
67
- }
68
-
69
- const error = result.errors?.[0];
70
-
71
- if (error) {
72
- throw this.graphQLErrorsToClientError(error);
73
- }
74
-
75
- if (result.data) {
76
- return {
77
- success: result.data.deregister?.success ? true : false
78
- };
79
- } else {
80
- throw new _sudoCommon.FatalError('deregister did not return any result.');
81
- }
82
- }
83
-
84
- async globalSignOut() {
85
- if (!(await this.sudoUserClient.isSignedIn())) {
86
- throw new _sudoCommon.NotSignedInError();
87
- }
88
-
89
- let result;
90
-
91
- try {
92
- result = await this.client.mutate({
93
- mutation: _graphqlTypes.GlobalSignOutDocument,
94
- fetchPolicy: 'no-cache'
95
- });
96
- } catch (err) {
97
- const apolloError = err;
98
- const error = apolloError.graphQLErrors?.[0];
99
-
100
- if (error) {
101
- throw this.graphQLErrorsToClientError(error);
102
- } else {
103
- throw new _sudoCommon.UnknownGraphQLError(err);
104
- }
105
- }
106
-
107
- const error = result.errors?.[0];
108
-
109
- if (error) {
110
- throw this.graphQLErrorsToClientError(error);
111
- }
112
-
113
- if (result.data) {
114
- return {
115
- success: result.data.globalSignOut?.success ? true : false
116
- };
117
- } else {
118
- throw new _sudoCommon.FatalError('globalSignOut did not return any result.');
119
- }
120
- }
121
-
122
- async registerFederatedId(input) {
123
- let result;
124
-
125
- try {
126
- result = await this.client.mutate({
127
- mutation: _graphqlTypes.RegisterFederatedIdDocument,
128
- variables: {
129
- input
130
- },
131
- fetchPolicy: 'no-cache'
132
- });
133
- } catch (err) {
134
- const apolloError = err;
135
- const error = apolloError.graphQLErrors?.[0];
136
-
137
- if (error) {
138
- throw this.graphQLErrorsToClientError(error);
139
- } else {
140
- throw new _sudoCommon.UnknownGraphQLError(err);
141
- }
142
- }
143
-
144
- const error = result.errors?.[0];
145
-
146
- if (error) {
147
- throw this.graphQLErrorsToClientError(error);
148
- }
149
-
150
- const identityId = result.data?.registerFederatedId?.identityId;
151
-
152
- if (identityId) {
153
- return {
154
- identityId
155
- };
156
- } else {
157
- throw new _sudoCommon.FatalError('registerFederatedId did not return expected result.');
158
- }
159
- }
160
-
161
- reset() {
162
- this.client.clearStore();
163
- this.client = new _awsAppsync.AWSAppSyncClient({
164
- url: this.graphqlUrl,
165
- region: this.region,
166
- auth: {
167
- type: _awsAppsync.AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
168
- jwtToken: async () => await this.sudoUserClient.getLatestAuthToken()
169
- },
170
- disableOffline: true
171
- });
172
- }
173
-
174
- graphQLErrorsToClientError(error) {
175
- this.logger.error('GraphQL call failed.', {
176
- error
177
- });
178
-
179
- if (error.errorType === 'sudoplatform.ServiceError') {
180
- return new _sudoCommon.ServiceError(error.message);
181
- } else if (error.errorType === 'sudoplatform.identity.TokenValidationError') {
182
- return new _sudoCommon.NotAuthorizedError();
183
- } else {
184
- return new _sudoCommon.UnknownGraphQLError(error);
185
- }
186
- }
187
-
188
- }
189
-
190
- exports.ApiClient = ApiClient;
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.apiKeyNames = void 0;
7
- const apiKeyNames = {
8
- idToken: 'idToken',
9
- accessToken: 'accessToken',
10
- refreshToken: 'refreshToken',
11
- tokenExpiry: 'tokenExpiry',
12
- refreshTokenExpiry: 'refreshTokenExpiry',
13
- userId: 'LastAuthUser'
14
- };
15
- exports.apiKeyNames = apiKeyNames;