@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.
- 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 +0 -0
- 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/classes/AlreadyRegisteredError.html +4 -4
- package/docs/classes/IdentityServiceConfigNotFoundError.html +4 -4
- 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 +23 -22
- package/lib/client/apiClient.js +0 -190
- 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 -183
- package/lib/user/identity-provider.js +0 -270
- package/lib/user/user-client-interface.js +0 -5
- package/lib/user/user-client.js +0 -522
- package/lib/user/user-key-names.js +0 -13
- package/lib/utils/resolvable-promise.js +0 -22
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TESTAuthenticationProvider = exports.TESTAuthenticationInfo = exports.LocalAuthenticationProvider = exports.LocalAuthenticationInfo = void 0;
|
|
7
|
-
|
|
8
|
-
var JWT = _interopRequireWildcard(require("jsonwebtoken"));
|
|
9
|
-
|
|
10
|
-
var _uuid = require("uuid");
|
|
11
|
-
|
|
12
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
-
|
|
14
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
-
|
|
16
|
-
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; }
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Authentication info consisting of a JWT signed using the TEST registration key.
|
|
20
|
-
*/
|
|
21
|
-
class TESTAuthenticationInfo {
|
|
22
|
-
constructor(jwt) {
|
|
23
|
-
this.jwt = jwt;
|
|
24
|
-
|
|
25
|
-
_defineProperty(this, "type", 'TEST');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
isValid() {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
encode() {
|
|
33
|
-
return this.jwt;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
getUsername() {
|
|
37
|
-
return '';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Authentication provider for generating authentication info using a TEST registration key.
|
|
43
|
-
*
|
|
44
|
-
* @param name provider name. This name will be prepended to the generated UUID in JWT sub.
|
|
45
|
-
* @param privateKey PEM encoded RSA private key.
|
|
46
|
-
* @param keyId key ID of the TEST registration key which is obtained from the admin console.
|
|
47
|
-
* @param attributes additional attributes to be added to the issued authentication info.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
exports.TESTAuthenticationInfo = TESTAuthenticationInfo;
|
|
52
|
-
|
|
53
|
-
class TESTAuthenticationProvider {
|
|
54
|
-
constructor(name, privateKey, keyId = 'register_key', attributes) {
|
|
55
|
-
this.name = name;
|
|
56
|
-
this.privateKey = privateKey;
|
|
57
|
-
this.keyId = keyId;
|
|
58
|
-
this.attributes = attributes;
|
|
59
|
-
|
|
60
|
-
_defineProperty(this, "testRegistrationIssuer", 'testRegisterIssuer');
|
|
61
|
-
|
|
62
|
-
_defineProperty(this, "testRegistrationAudience", 'testRegisterAudience');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async getAuthenticationInfo() {
|
|
66
|
-
const jwt = JWT.sign(this.attributes ? this.attributes : {}, this.privateKey, {
|
|
67
|
-
jwtid: (0, _uuid.v4)(),
|
|
68
|
-
audience: this.testRegistrationAudience,
|
|
69
|
-
expiresIn: '60s',
|
|
70
|
-
notBefore: '0m',
|
|
71
|
-
subject: `${this.name}-${(0, _uuid.v4)()}`,
|
|
72
|
-
issuer: this.testRegistrationIssuer,
|
|
73
|
-
header: {
|
|
74
|
-
alg: 'RS256',
|
|
75
|
-
kid: this.keyId
|
|
76
|
-
},
|
|
77
|
-
algorithm: 'RS256'
|
|
78
|
-
});
|
|
79
|
-
return new TESTAuthenticationInfo(jwt);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
reset() {// Not implemented
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Authentication info consisting of a JWT signed using the locally stored private key.
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
exports.TESTAuthenticationProvider = TESTAuthenticationProvider;
|
|
92
|
-
|
|
93
|
-
class LocalAuthenticationInfo {
|
|
94
|
-
constructor(jwt, username) {
|
|
95
|
-
this.jwt = jwt;
|
|
96
|
-
this.username = username;
|
|
97
|
-
|
|
98
|
-
_defineProperty(this, "type", 'FSSO');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
isValid() {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
encode() {
|
|
106
|
-
return this.jwt;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
getUsername() {
|
|
110
|
-
return this.username;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Authentication info consisting of a JWT signed using the locally stored private key.
|
|
116
|
-
*
|
|
117
|
-
* @param name provider name. This name will be used to populate JWT iss (issuer).
|
|
118
|
-
* @param privateKey PEM encoded RSA private key.
|
|
119
|
-
* @param keyId key ID.
|
|
120
|
-
* @param username username to be associated with the issued authentication info.
|
|
121
|
-
* @param attributes additional attributes to be added to the issued authentication info.
|
|
122
|
-
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
exports.LocalAuthenticationInfo = LocalAuthenticationInfo;
|
|
126
|
-
|
|
127
|
-
class LocalAuthenticationProvider {
|
|
128
|
-
constructor(name, privateKey, keyId, username, attributes) {
|
|
129
|
-
this.name = name;
|
|
130
|
-
this.privateKey = privateKey;
|
|
131
|
-
this.keyId = keyId;
|
|
132
|
-
this.username = username;
|
|
133
|
-
this.attributes = attributes;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async getAuthenticationInfo() {
|
|
137
|
-
const jwt = JWT.sign(this.attributes ? this.attributes : {}, this.privateKey, {
|
|
138
|
-
jwtid: (0, _uuid.v4)(),
|
|
139
|
-
audience: 'identity-service',
|
|
140
|
-
expiresIn: '60s',
|
|
141
|
-
notBefore: '0m',
|
|
142
|
-
subject: this.username,
|
|
143
|
-
issuer: this.name,
|
|
144
|
-
header: {
|
|
145
|
-
alg: 'RS256',
|
|
146
|
-
kid: this.keyId
|
|
147
|
-
},
|
|
148
|
-
algorithm: 'RS256'
|
|
149
|
-
});
|
|
150
|
-
return new LocalAuthenticationInfo(jwt, this.username);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
reset() {// Not implemented
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
exports.LocalAuthenticationProvider = LocalAuthenticationProvider;
|
package/lib/user/auth.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.DefaultRefreshTokenLifetime = exports.CognitoAuthUI = void 0;
|
|
7
|
-
|
|
8
|
-
var _sudoCommon = require("@sudoplatform/sudo-common");
|
|
9
|
-
|
|
10
|
-
var _amazonCognitoAuthJs = require("amazon-cognito-auth-js");
|
|
11
|
-
|
|
12
|
-
var _apiKeyNames = require("../core/api-key-names");
|
|
13
|
-
|
|
14
|
-
var _resolvablePromise = require("../utils/resolvable-promise");
|
|
15
|
-
|
|
16
|
-
var JWT = _interopRequireWildcard(require("jsonwebtoken"));
|
|
17
|
-
|
|
18
|
-
var _userKeyNames = require("./user-key-names");
|
|
19
|
-
|
|
20
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
-
|
|
22
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
|
|
24
|
-
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; }
|
|
25
|
-
|
|
26
|
-
const DefaultRefreshTokenLifetime = 60;
|
|
27
|
-
exports.DefaultRefreshTokenLifetime = DefaultRefreshTokenLifetime;
|
|
28
|
-
|
|
29
|
-
class CognitoAuthUI {
|
|
30
|
-
constructor(authenticationStore, federatedSignInConfig, keyManager, logger, launchUriFn) {
|
|
31
|
-
this.authenticationStore = authenticationStore;
|
|
32
|
-
this.federatedSignInConfig = federatedSignInConfig;
|
|
33
|
-
this.keyManager = keyManager;
|
|
34
|
-
this.launchUriFn = launchUriFn;
|
|
35
|
-
|
|
36
|
-
_defineProperty(this, "auth", void 0);
|
|
37
|
-
|
|
38
|
-
_defineProperty(this, "tokensRefreshedPromise", void 0);
|
|
39
|
-
|
|
40
|
-
_defineProperty(this, "refreshTokenLifetime", void 0);
|
|
41
|
-
|
|
42
|
-
_defineProperty(this, "logger", void 0);
|
|
43
|
-
|
|
44
|
-
this.authenticationStore.subscribe(this);
|
|
45
|
-
this.auth = this.initCognitoAuthSDK();
|
|
46
|
-
const refreshTokenLifetime = this.federatedSignInConfig.refreshTokenLifetime;
|
|
47
|
-
this.refreshTokenLifetime = refreshTokenLifetime ?? DefaultRefreshTokenLifetime;
|
|
48
|
-
this.logger = logger;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
initCognitoAuthSDK() {
|
|
52
|
-
const cognitoAuthConfig = {
|
|
53
|
-
ClientId: this.federatedSignInConfig.appClientId,
|
|
54
|
-
AppWebDomain: this.federatedSignInConfig.webDomain,
|
|
55
|
-
IdentityProvider: this.federatedSignInConfig.identityProvider,
|
|
56
|
-
RedirectUriSignIn: this.federatedSignInConfig.signInRedirectUri,
|
|
57
|
-
RedirectUriSignOut: this.federatedSignInConfig.signOutRedirectUri,
|
|
58
|
-
TokenScopesArray: ['openid'],
|
|
59
|
-
Storage: this.authenticationStore,
|
|
60
|
-
LaunchUri: this.launchUriFn
|
|
61
|
-
};
|
|
62
|
-
const auth = new _amazonCognitoAuthJs.CognitoAuth(cognitoAuthConfig);
|
|
63
|
-
auth.useCodeGrantFlow();
|
|
64
|
-
auth.userhandler = {
|
|
65
|
-
onSuccess: result => {
|
|
66
|
-
this.logger.info('Successfully signed in.', {
|
|
67
|
-
result
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
onFailure: error => {
|
|
71
|
-
this.logger.error(new _sudoCommon.AuthenticationError(error).message);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
return auth;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
presentFederatedSignInUI() {
|
|
78
|
-
this.auth.getSession();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async processFederatedSignInTokens(url) {
|
|
82
|
-
this.tokensRefreshedPromise = (0, _resolvablePromise.createResolvablePromise)();
|
|
83
|
-
this.auth.parseCognitoWebResponse(url);
|
|
84
|
-
const authDetails = await this.tokensRefreshedPromise;
|
|
85
|
-
await this.storeTokensInKeyManager(authDetails);
|
|
86
|
-
return authDetails.authenticationTokens;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* This function is called when the authentication store notifies subscribers of an item update.
|
|
90
|
-
*
|
|
91
|
-
* @param itemName the name of the item being updated
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
update(itemName) {
|
|
96
|
-
if (itemName === 'idToken') {
|
|
97
|
-
const authTokens = this.getAuthTokens();
|
|
98
|
-
const userId = this.authenticationStore.getItem(_apiKeyNames.apiKeyNames.userId);
|
|
99
|
-
|
|
100
|
-
if (authTokens && userId) {
|
|
101
|
-
this.tokensRefreshedPromise?.resolve({
|
|
102
|
-
authenticationTokens: authTokens,
|
|
103
|
-
userId
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
this.logger.debug('Updated: ', {
|
|
109
|
-
itemName
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
reset() {
|
|
114
|
-
const cognitoAuthAny = this.auth;
|
|
115
|
-
cognitoAuthAny.clearCachedTokensScopes();
|
|
116
|
-
cognitoAuthAny.signInUserSession = null;
|
|
117
|
-
cognitoAuthAny.signInUserSession = cognitoAuthAny.getCachedSession();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
presentSignOutUI() {
|
|
121
|
-
const signOutUrl = this.auth.getFQDNSignOut();
|
|
122
|
-
this.auth.launchUri(signOutUrl);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async storeRefreshTokenLifetime(refreshTokenLifetime) {
|
|
126
|
-
const tokenLifetime = refreshTokenLifetime * 24 * 60 * 60 * 1000 + new Date().getTime();
|
|
127
|
-
await this.keyManager.removeItem(_apiKeyNames.apiKeyNames.refreshTokenExpiry);
|
|
128
|
-
await this.keyManager.addString(_apiKeyNames.apiKeyNames.refreshTokenExpiry, tokenLifetime.toString());
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
getAuthTokens() {
|
|
132
|
-
const idToken = this.authenticationStore.getItem(_apiKeyNames.apiKeyNames.idToken);
|
|
133
|
-
const accessToken = this.authenticationStore.getItem(_apiKeyNames.apiKeyNames.accessToken);
|
|
134
|
-
const refreshToken = this.authenticationStore.getItem(_apiKeyNames.apiKeyNames.refreshToken);
|
|
135
|
-
const tokenExpiry = this.getTokenExpiry();
|
|
136
|
-
|
|
137
|
-
if (idToken && accessToken && refreshToken && tokenExpiry) {
|
|
138
|
-
return {
|
|
139
|
-
idToken: idToken,
|
|
140
|
-
accessToken: accessToken,
|
|
141
|
-
refreshToken: refreshToken,
|
|
142
|
-
tokenExpiry: tokenExpiry.getTime()
|
|
143
|
-
};
|
|
144
|
-
} else {
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
getTokenExpiry() {
|
|
150
|
-
const expiry = this.authenticationStore.getItem(_apiKeyNames.apiKeyNames.tokenExpiry);
|
|
151
|
-
return expiry ? new Date(Number(expiry) * 1000) : undefined;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Store the authentication tokens and user id of the signed in user in the key manager.
|
|
155
|
-
*/
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
async storeTokensInKeyManager(authDetails) {
|
|
159
|
-
await this.keyManager.removeItem(_userKeyNames.userKeyNames.userId);
|
|
160
|
-
await this.keyManager.removeItem(_apiKeyNames.apiKeyNames.idToken);
|
|
161
|
-
await this.keyManager.removeItem(_apiKeyNames.apiKeyNames.accessToken);
|
|
162
|
-
await this.keyManager.removeItem(_apiKeyNames.apiKeyNames.refreshToken);
|
|
163
|
-
await this.keyManager.removeItem(_apiKeyNames.apiKeyNames.tokenExpiry);
|
|
164
|
-
const authTokens = authDetails.authenticationTokens;
|
|
165
|
-
await this.keyManager.addString(_userKeyNames.userKeyNames.userId, authDetails.userId);
|
|
166
|
-
await this.keyManager.addString(_apiKeyNames.apiKeyNames.idToken, authTokens.idToken);
|
|
167
|
-
await this.keyManager.addString(_apiKeyNames.apiKeyNames.accessToken, authTokens.accessToken);
|
|
168
|
-
await this.keyManager.addString(_apiKeyNames.apiKeyNames.refreshToken, authTokens.refreshToken);
|
|
169
|
-
const decoded = JWT.decode(authTokens.idToken, {
|
|
170
|
-
complete: true
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
if (decoded) {
|
|
174
|
-
const tokenExpiry = decoded.payload['exp'];
|
|
175
|
-
await this.keyManager.addString(_apiKeyNames.apiKeyNames.tokenExpiry, tokenExpiry);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
await this.storeRefreshTokenLifetime(this.refreshTokenLifetime);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
exports.CognitoAuthUI = CognitoAuthUI;
|
|
@@ -1,270 +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?.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.'));
|
|
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?.IdToken;
|
|
185
|
-
const accessToken = authResult?.AccessToken;
|
|
186
|
-
const refreshToken = authResult?.RefreshToken;
|
|
187
|
-
const tokenExpiry = 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
|
-
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.'));
|
|
233
|
-
}
|
|
234
|
-
} catch (err) {
|
|
235
|
-
const error = err;
|
|
236
|
-
reject(new _sudoCommon.AuthenticationError(error.message));
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
async signOut(refreshToken) {
|
|
242
|
-
return new Promise((resolve, reject) => {
|
|
243
|
-
const params = {
|
|
244
|
-
Token: refreshToken,
|
|
245
|
-
ClientId: this.config.identityService.clientId
|
|
246
|
-
};
|
|
247
|
-
const revokeToken = new _clientCognitoIdentityProvider.RevokeTokenCommand(params);
|
|
248
|
-
this.idpService.send(revokeToken, (error, data) => {
|
|
249
|
-
if (error) {
|
|
250
|
-
this.logger.error(error.message);
|
|
251
|
-
reject(new _sudoCommon.SignOutError(error.message));
|
|
252
|
-
} else {
|
|
253
|
-
this.logger.info('User successfully signed out.', {
|
|
254
|
-
data
|
|
255
|
-
});
|
|
256
|
-
resolve();
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
async storeRefreshTokenLifetime(refreshTokenLifetime) {
|
|
263
|
-
const tokenLifetime = refreshTokenLifetime * 24 * 60 * 60 * 1000 + new Date().getTime();
|
|
264
|
-
await this.keyManager.removeItem(_apiKeyNames.apiKeyNames.refreshTokenExpiry);
|
|
265
|
-
await this.keyManager.addString(_apiKeyNames.apiKeyNames.refreshTokenExpiry, tokenLifetime.toString());
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
exports.CognitoUserPoolIdentityProvider = CognitoUserPoolIdentityProvider;
|