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