cidaas-javascript-sdk 2.4.3 → 2.5.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 (48) hide show
  1. package/CHANGELOG.md +5 -3
  2. package/README.md +2 -3
  3. package/package.json +10 -12
  4. package/src/main/authentication/index.ts +223 -0
  5. package/src/main/global.d.ts +10 -0
  6. package/src/main/index.ts +6 -0
  7. package/src/main/web-auth/ConsentService.ts +98 -0
  8. package/src/main/web-auth/Entities.ts +645 -0
  9. package/src/main/web-auth/Helper.ts +75 -0
  10. package/src/main/web-auth/LoginService.ts +248 -0
  11. package/src/main/web-auth/TokenService.ts +196 -0
  12. package/src/main/web-auth/UserService.ts +388 -0
  13. package/src/main/web-auth/VerificationService.ts +267 -0
  14. package/src/main/web-auth/WebAuth.ts +1706 -0
  15. package/types/authentication/index.d.ts +55 -0
  16. package/types/authentication/index.js +262 -0
  17. package/types/index.d.ts +4 -0
  18. package/types/index.js +9 -0
  19. package/types/web-auth/ConsentService.d.ts +59 -0
  20. package/types/web-auth/ConsentService.js +97 -0
  21. package/types/web-auth/Entities.d.ts +567 -0
  22. package/types/web-auth/Entities.js +88 -0
  23. package/types/web-auth/Helper.d.ts +24 -0
  24. package/types/web-auth/Helper.js +89 -0
  25. package/types/web-auth/LoginService.d.ts +102 -0
  26. package/types/web-auth/LoginService.js +248 -0
  27. package/types/web-auth/TokenService.d.ts +48 -0
  28. package/types/web-auth/TokenService.js +210 -0
  29. package/types/web-auth/UserService.d.ts +143 -0
  30. package/types/web-auth/UserService.js +408 -0
  31. package/types/web-auth/VerificationService.d.ts +125 -0
  32. package/types/web-auth/VerificationService.js +273 -0
  33. package/types/web-auth/WebAuth.d.ts +895 -0
  34. package/types/web-auth/WebAuth.js +1767 -0
  35. package/src/main/.gitkeep +0 -0
  36. package/src/main/authentication/index.js +0 -213
  37. package/src/main/index.js +0 -11
  38. package/src/main/web-auth/exception.js +0 -7
  39. package/src/main/web-auth/webauth.js +0 -1899
  40. package/src/test/sum.js +0 -4
  41. package/src/test/test.js +0 -5
  42. package/types/.DS_Store +0 -0
  43. package/types/main/authentication/index.d.ts +0 -15
  44. package/types/main/index.d.ts +0 -5
  45. package/types/main/web-auth/exception.d.ts +0 -7
  46. package/types/main/web-auth/webauth.d.ts +0 -141
  47. package/types/test/sum.d.ts +0 -2
  48. package/types/test/test.d.ts +0 -1
@@ -0,0 +1,248 @@
1
+ import { Helper, CustomException } from "./Helper";
2
+ import {
3
+ IUserEntity,
4
+ LoginFormRequestEntity,
5
+ PhysicalVerificationLoginRequest,
6
+ LoginFormRequestAsyncEntity,
7
+ IChangePasswordEntity
8
+ } from "./Entities"
9
+
10
+
11
+ export namespace LoginService {
12
+
13
+ /**
14
+ * login with username and password
15
+ * @param options
16
+ */
17
+ export function loginWithCredentials(options: LoginFormRequestEntity) {
18
+ try {
19
+ const url = window.webAuthSettings.authority + "/login-srv/login";
20
+ let form = Helper.createForm(url, options)
21
+ document.body.appendChild(form);
22
+ form.submit();
23
+ } catch (ex) {
24
+ throw new CustomException(ex, 417);
25
+ }
26
+ };
27
+
28
+ /**
29
+ * login with username and password and return response
30
+ * @param options
31
+ * @returns
32
+ */
33
+ export function loginWithCredentialsAsynFn(options: LoginFormRequestAsyncEntity) {
34
+ try {
35
+ var searchParams = new URLSearchParams(options);
36
+ var response = fetch(window.webAuthSettings.authority + "/login-srv/login", {
37
+ method: "POST",
38
+ redirect: "follow",
39
+ body: searchParams.toString(),
40
+ headers: {
41
+ "Content-Type": "application/x-www-form-urlencoded",
42
+ }
43
+ });
44
+
45
+ return response;
46
+ } catch (ex) {
47
+ throw new CustomException(ex, 417);
48
+ }
49
+ };
50
+
51
+ /**
52
+ * login with social
53
+ * @param options
54
+ * @param queryParams
55
+ */
56
+ export function loginWithSocial(
57
+ options: { provider: string; requestId: string; },
58
+ queryParams: { dc: string; device_fp: string }
59
+ ) {
60
+ try {
61
+ var _serviceURL = window.webAuthSettings.authority + "/login-srv/social/login/" + options.provider.toLowerCase() + "/" + options.requestId;
62
+ if (queryParams && queryParams.dc && queryParams.device_fp) {
63
+ _serviceURL = _serviceURL + "?dc=" + queryParams.dc + "&device_fp=" + queryParams.device_fp;
64
+ }
65
+ window.location.href = _serviceURL;
66
+ } catch (ex) {
67
+ console.log(ex);
68
+ }
69
+ };
70
+
71
+ /**
72
+ * register with social
73
+ * @param options
74
+ * @param queryParams
75
+ */
76
+ export function registerWithSocial(
77
+ options: { provider: string; requestId: string; },
78
+ queryParams: { dc: string; device_fp: string }) {
79
+ try {
80
+ var _serviceURL = window.webAuthSettings.authority + "/login-srv/social/register/" + options.provider.toLowerCase() + "/" + options.requestId;
81
+ if (queryParams && queryParams.dc && queryParams.device_fp) {
82
+ _serviceURL = _serviceURL + "?dc=" + queryParams.dc + "&device_fp=" + queryParams.device_fp;
83
+ }
84
+ window.location.href = _serviceURL;
85
+ } catch (ex) {
86
+ console.log(ex);
87
+ }
88
+ };
89
+
90
+ /**
91
+ * passwordless login
92
+ * @param options
93
+ */
94
+ export function passwordlessLogin(options: PhysicalVerificationLoginRequest) {
95
+ try {
96
+ const url = window.webAuthSettings.authority + "/login-srv/verification/login";
97
+ let form = Helper.createForm(url, options)
98
+ document.body.appendChild(form);
99
+ form.submit();
100
+ } catch (ex) {
101
+ throw new CustomException(ex, 417);
102
+ }
103
+ };
104
+
105
+ /**
106
+ * scope consent continue after token pre check
107
+ * @param options
108
+ */
109
+ export function scopeConsentContinue(options: { track_id: string }) {
110
+ try {
111
+ var form = document.createElement('form');
112
+ form.action = window.webAuthSettings.authority + "/login-srv/precheck/continue/" + options.track_id;
113
+ form.method = 'POST';
114
+ document.body.appendChild(form);
115
+ form.submit();
116
+ } catch (ex) {
117
+ throw new CustomException(ex, 417);
118
+ }
119
+ };
120
+
121
+ /**
122
+ * claim consent continue login
123
+ * @param options
124
+ */
125
+ export function claimConsentContinue(options: { track_id: string }) {
126
+ try {
127
+ var form = document.createElement('form');
128
+ form.action = window.webAuthSettings.authority + "/login-srv/precheck/continue/" + options.track_id;
129
+ form.method = 'POST';
130
+ document.body.appendChild(form);
131
+ form.submit();
132
+ } catch (ex) {
133
+ throw new CustomException(ex, 417);
134
+ }
135
+ };
136
+
137
+ /**
138
+ * consent continue login
139
+ * @param options
140
+ */
141
+ export function consentContinue(options: {
142
+ client_id: string;
143
+ consent_refs: string[];
144
+ sub: string;
145
+ scopes: string[];
146
+ matcher: any;
147
+ track_id: string;
148
+ }) {
149
+ try {
150
+ const url = window.webAuthSettings.authority + "/login-srv/precheck/continue/" + options.track_id;
151
+ let form = Helper.createForm(url, options)
152
+ document.body.appendChild(form);
153
+ form.submit();
154
+ } catch (ex) {
155
+ throw new CustomException(ex, 417);
156
+ }
157
+ };
158
+
159
+ /**
160
+ * mfa continue login
161
+ * @param options
162
+ */
163
+ export function mfaContinue(options: PhysicalVerificationLoginRequest & { track_id: string }) {
164
+ try {
165
+ const url = window.webAuthSettings.authority + "/login-srv/precheck/continue/" + options.track_id;
166
+ let form = Helper.createForm(url, options)
167
+ document.body.appendChild(form);
168
+ form.submit();
169
+ } catch (ex) {
170
+ throw new CustomException(ex, 417);
171
+ }
172
+ };
173
+
174
+ /**
175
+ * change password continue
176
+ * @param options
177
+ */
178
+ export function firstTimeChangePassword(options: IChangePasswordEntity) {
179
+ try {
180
+ const url = window.webAuthSettings.authority + "/login-srv/precheck/continue/" + options.loginSettingsId;;
181
+ let form = Helper.createForm(url, options)
182
+ document.body.appendChild(form);
183
+ form.submit();
184
+ } catch (ex) {
185
+ throw new CustomException(ex, 417);
186
+ }
187
+ };
188
+
189
+ /**
190
+ * progressiveRegistration
191
+ * @param options
192
+ * @param headers
193
+ * @returns
194
+ */
195
+ export function progressiveRegistration(options: IUserEntity, headers: {
196
+ requestId: string;
197
+ trackId: string;
198
+ acceptlanguage: string;
199
+ }) {
200
+ return new Promise((resolve, reject) => {
201
+ try {
202
+ var http = new XMLHttpRequest();
203
+ var _serviceURL = window.webAuthSettings.authority + "/login-srv/progressive/update/user";
204
+ http.onreadystatechange = function () {
205
+ if (http.readyState == 4) {
206
+ if (http.responseText) {
207
+ resolve(JSON.parse(http.responseText));
208
+ } else {
209
+ resolve(undefined);
210
+ }
211
+ }
212
+ };
213
+ http.open("POST", _serviceURL, true);
214
+ http.setRequestHeader("Content-type", "application/json");
215
+ http.setRequestHeader("requestId", headers.requestId);
216
+ http.setRequestHeader("trackId", headers.trackId);
217
+ if (headers.acceptlanguage) {
218
+ http.setRequestHeader("accept-language", headers.acceptlanguage);
219
+ } else if (window.localeSettings) {
220
+ http.setRequestHeader("accept-language", window.localeSettings);
221
+ }
222
+ http.send(JSON.stringify(options));
223
+ } catch (ex) {
224
+ reject(ex);
225
+ }
226
+ });
227
+ };
228
+
229
+ /**
230
+ * loginAfterRegister
231
+ * @param options
232
+ */
233
+ export function loginAfterRegister(options: {
234
+ device_id: string;
235
+ dc?: string;
236
+ rememberMe: boolean;
237
+ trackId: string;
238
+ }) {
239
+ try {
240
+ const url = window.webAuthSettings.authority + "/login-srv/login/handle/afterregister/" + options.trackId;
241
+ let form = Helper.createForm(url, options)
242
+ document.body.appendChild(form);
243
+ form.submit();
244
+ } catch (ex) {
245
+ throw new CustomException(ex, 417);
246
+ }
247
+ };
248
+ }
@@ -0,0 +1,196 @@
1
+ import { AccessTokenRequest, TokenIntrospectionEntity, ISuggestedMFAActionConfig } from "./Entities"
2
+ import { Helper, CustomException } from "./Helper";
3
+
4
+ export namespace TokenService {
5
+
6
+ /**
7
+ * renew token using refresh token
8
+ * @param options
9
+ * @returns
10
+ */
11
+ export function renewToken(options: AccessTokenRequest) {
12
+ return new Promise((resolve, reject) => {
13
+ try {
14
+ if (!options.refresh_token) {
15
+ throw new CustomException("refresh_token cannot be empty", 417);
16
+ }
17
+ options.client_id = window.webAuthSettings.client_id;
18
+ options.grant_type = 'refresh_token';
19
+ var http = new XMLHttpRequest();
20
+ var _serviceURL = window.webAuthSettings.authority + "/token-srv/token";
21
+ http.onreadystatechange = function () {
22
+ if (http.readyState == 4) {
23
+ resolve(JSON.parse(http.responseText));
24
+ }
25
+ };
26
+ http.open("POST", _serviceURL, true);
27
+ http.setRequestHeader("Content-type", "application/json");
28
+ if (window.localeSettings) {
29
+ http.setRequestHeader("accept-language", window.localeSettings);
30
+ }
31
+ http.send(JSON.stringify(options));
32
+ } catch (ex) {
33
+ reject(ex);
34
+ }
35
+ });
36
+ };
37
+
38
+ /**
39
+ * get access token from code
40
+ * @param options
41
+ * @returns
42
+ */
43
+ export function getAccessToken(options: AccessTokenRequest) {
44
+ return new Promise((resolve, reject) => {
45
+ try {
46
+ if (!options.code) {
47
+ throw new CustomException("code cannot be empty", 417);
48
+ }
49
+ options.client_id = window.webAuthSettings.client_id;
50
+ options.redirect_uri = window.webAuthSettings.redirect_uri;
51
+ options.code_verifier = this.code_verifier;
52
+ options.grant_type = "authorization_code";
53
+ var http = new XMLHttpRequest();
54
+ var _serviceURL = window.webAuthSettings.authority + "/token-srv/token";
55
+ http.onreadystatechange = function () {
56
+ if (http.readyState == 4) {
57
+ resolve(JSON.parse(http.responseText));
58
+ }
59
+ };
60
+ http.open("POST", _serviceURL, true);
61
+ http.setRequestHeader("Content-type", "application/json");
62
+ if (window.localeSettings) {
63
+ http.setRequestHeader("accept-language", window.localeSettings);
64
+ }
65
+ http.send(JSON.stringify(options));
66
+ } catch (ex) {
67
+ reject(ex);
68
+ }
69
+ });
70
+ };
71
+
72
+ /**
73
+ * validate access token
74
+ * @param options
75
+ * @returns
76
+ */
77
+ export function validateAccessToken(options: TokenIntrospectionEntity) {
78
+ return new Promise((resolve, reject) => {
79
+ try {
80
+ if (!options.token || !options.token_type_hint) {
81
+ throw new CustomException("token or token_type_hint cannot be empty", 417);
82
+ }
83
+ var http = new XMLHttpRequest();
84
+ var _serviceURL = window.webAuthSettings.authority + "/token-srv/introspect";
85
+ http.onreadystatechange = function () {
86
+ if (http.readyState == 4) {
87
+ resolve(JSON.parse(http.responseText));
88
+ }
89
+ };
90
+ http.open("POST", _serviceURL, true);
91
+ http.setRequestHeader("Content-type", "application/json");
92
+ if (window.localeSettings) {
93
+ http.setRequestHeader("accept-language", window.localeSettings);
94
+ }
95
+ http.send(JSON.stringify(options));
96
+ } catch (ex) {
97
+ reject(ex);
98
+ }
99
+ });
100
+ };
101
+
102
+ /**
103
+ * get scope consent details
104
+ * @param options
105
+ * @returns
106
+ */
107
+ export function getScopeConsentDetails(options: {
108
+ track_id: string;
109
+ locale: string;
110
+ }) {
111
+ return new Promise((resolve, reject) => {
112
+ try {
113
+ var http = new XMLHttpRequest();
114
+ var _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/metadata/" + options.track_id + "?acceptLanguage=" + options.locale;
115
+ http.onreadystatechange = function () {
116
+ if (http.readyState == 4) {
117
+ if (http.responseText) {
118
+ resolve(JSON.parse(http.responseText));
119
+ } else {
120
+ resolve(false);
121
+ }
122
+ }
123
+ };
124
+ http.open("GET", _serviceURL, true);
125
+ http.setRequestHeader("Content-type", "application/json");
126
+ if (window.localeSettings) {
127
+ http.setRequestHeader("accept-language", window.localeSettings);
128
+ }
129
+ http.send();
130
+ } catch (ex) {
131
+ reject(ex);
132
+ }
133
+ });
134
+ };
135
+
136
+ /**
137
+ * updateSuggestMFA
138
+ * @param track_id
139
+ * @param options
140
+ * @returns
141
+ */
142
+ export function updateSuggestMFA(track_id: string, options: ISuggestedMFAActionConfig) {
143
+ var _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/suggested/mfa/update/" + track_id;
144
+ return Helper.createPostPromise(options, _serviceURL, false);
145
+ };
146
+
147
+ /**
148
+ * getMissingFieldsLogin
149
+ * @param trackId
150
+ * @returns
151
+ */
152
+ export function getMissingFieldsLogin(trackId: string) {
153
+ return new Promise((resolve, reject) => {
154
+ try {
155
+ var http = new XMLHttpRequest();
156
+ var _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/metadata/" + trackId;
157
+ http.onreadystatechange = function () {
158
+ if (http.readyState == 4) {
159
+ if (http.responseText) {
160
+ resolve(JSON.parse(http.responseText));
161
+ } else {
162
+ resolve(undefined);
163
+ }
164
+ }
165
+ };
166
+ http.open("GET", _serviceURL, true);
167
+ http.setRequestHeader("Content-type", "application/json");
168
+ if (window.localeSettings) {
169
+ http.setRequestHeader("accept-language", window.localeSettings);
170
+ }
171
+ http.send();
172
+ } catch (ex) {
173
+ reject(ex);
174
+ }
175
+ });
176
+ };
177
+
178
+ /**
179
+ * device code flow - verify
180
+ * @param code
181
+ */
182
+ export function deviceCodeVerify(code: string) {
183
+ var params = `user_code=${encodeURI(code)}`;
184
+ var url = `${window.webAuthSettings.authority}/token-srv/device/verify?${params}`;
185
+ try {
186
+ const options = {
187
+ user_code: encodeURI(code)
188
+ }
189
+ let form = Helper.createForm(url, options, 'GET');
190
+ document.body.appendChild(form);
191
+ form.submit();
192
+ } catch (ex) {
193
+ throw new Error(ex);
194
+ }
195
+ }
196
+ }