cidaas-javascript-sdk 3.1.0 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,89 +0,0 @@
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, method, 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(method, 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;
@@ -1,103 +0,0 @@
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
- * 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
- device_fp?: string;
102
- }): void;
103
- }
@@ -1,248 +0,0 @@
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
- * 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 = {}));
@@ -1,48 +0,0 @@
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
- }
@@ -1,114 +0,0 @@
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
- if (!options.refresh_token) {
14
- throw new Helper_1.CustomException("refresh_token cannot be empty", 417);
15
- }
16
- options.client_id = window.webAuthSettings.client_id;
17
- options.grant_type = 'refresh_token';
18
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/token";
19
- return Helper_1.Helper.createPostPromise(options, _serviceURL, undefined, "POST");
20
- }
21
- TokenService.renewToken = renewToken;
22
- ;
23
- /**
24
- * get access token from code
25
- * @param options
26
- * @returns
27
- */
28
- function getAccessToken(options) {
29
- if (!options.code) {
30
- throw new Helper_1.CustomException("code cannot be empty", 417);
31
- }
32
- options.client_id = window.webAuthSettings.client_id;
33
- options.redirect_uri = window.webAuthSettings.redirect_uri;
34
- options.grant_type = "authorization_code";
35
- if (!window.webAuthSettings.disablePKCE) {
36
- window.usermanager._client.createSigninRequest(window.webAuthSettings).then(function (signInRequest) {
37
- var _a;
38
- options.code_verifier = (_a = signInRequest.state) === null || _a === void 0 ? void 0 : _a.code_verifier;
39
- });
40
- }
41
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/token";
42
- return Helper_1.Helper.createPostPromise(options, _serviceURL, undefined, "POST");
43
- }
44
- TokenService.getAccessToken = getAccessToken;
45
- ;
46
- /**
47
- * validate access token
48
- * @param options
49
- * @returns
50
- */
51
- function validateAccessToken(options) {
52
- if (!options.token || !options.token_type_hint) {
53
- throw new Helper_1.CustomException("token or token_type_hint cannot be empty", 417);
54
- }
55
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/introspect";
56
- return Helper_1.Helper.createPostPromise(options, _serviceURL, false, "POST");
57
- }
58
- TokenService.validateAccessToken = validateAccessToken;
59
- ;
60
- /**
61
- * get scope consent details
62
- * @param options
63
- * @returns
64
- */
65
- function getScopeConsentDetails(options) {
66
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/metadata/" + options.track_id + "?acceptLanguage=" + options.locale;
67
- return Helper_1.Helper.createPostPromise(undefined, _serviceURL, false, "GET");
68
- }
69
- TokenService.getScopeConsentDetails = getScopeConsentDetails;
70
- ;
71
- /**
72
- * updateSuggestMFA
73
- * @param track_id
74
- * @param options
75
- * @returns
76
- */
77
- function updateSuggestMFA(track_id, options) {
78
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/suggested/mfa/update/" + track_id;
79
- return Helper_1.Helper.createPostPromise(options, _serviceURL, false, "POST");
80
- }
81
- TokenService.updateSuggestMFA = updateSuggestMFA;
82
- ;
83
- /**
84
- * getMissingFieldsLogin
85
- * @param trackId
86
- * @returns
87
- */
88
- function getMissingFieldsLogin(trackId) {
89
- var _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/metadata/" + trackId;
90
- return Helper_1.Helper.createPostPromise(undefined, _serviceURL, false, "GET");
91
- }
92
- TokenService.getMissingFieldsLogin = getMissingFieldsLogin;
93
- ;
94
- /**
95
- * device code flow - verify
96
- * @param code
97
- */
98
- function deviceCodeVerify(code) {
99
- var params = "user_code=".concat(encodeURI(code));
100
- var url = "".concat(window.webAuthSettings.authority, "/token-srv/device/verify?").concat(params);
101
- try {
102
- var options = {
103
- user_code: encodeURI(code)
104
- };
105
- var form = Helper_1.Helper.createForm(url, options, 'GET');
106
- document.body.appendChild(form);
107
- form.submit();
108
- }
109
- catch (ex) {
110
- throw new Error(ex);
111
- }
112
- }
113
- TokenService.deviceCodeVerify = deviceCodeVerify;
114
- })(TokenService = exports.TokenService || (exports.TokenService = {}));