cidaas-javascript-sdk 4.1.0 → 4.2.1

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,6 +1,32 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
26
+ };
2
27
  exports.__esModule = true;
3
28
  exports.Authentication = void 0;
29
+ __exportStar(require("./authentication.model"), exports);
4
30
  var Authentication = /** @class */ (function () {
5
31
  function Authentication(webAuthSettings, userManager) {
6
32
  this.webAuthSettings = webAuthSettings;
@@ -21,35 +47,18 @@ var Authentication = /** @class */ (function () {
21
47
  * ```
22
48
  *
23
49
  * @param view_type: either 'login' or 'register'
50
+ * @param {LoginRedirectOptions} options optional login options to override the webauth configuration
24
51
  */
25
- Authentication.prototype.loginOrRegisterWithBrowser = function (view_type) {
26
- try {
27
- if (this.userManager) {
28
- if (this.webAuthSettings) {
29
- if (!this.webAuthSettings.extraQueryParams) {
30
- this.webAuthSettings.extraQueryParams = {};
31
- }
32
- this.webAuthSettings.extraQueryParams.view_type = view_type;
33
- if (this.webAuthSettings.scope) {
34
- if (this.webAuthSettings.response_type.indexOf("id_token") == -1 && this.webAuthSettings.scope.indexOf("openid") != -1 && !this.webAuthSettings.extraQueryParams.nonce) {
35
- this.webAuthSettings.extraQueryParams.nonce = new Date().getTime().toString();
36
- }
37
- }
38
- }
39
- this.userManager.signinRedirect({
40
- extraQueryParams: this.webAuthSettings.extraQueryParams,
41
- redirect_uri: this.webAuthSettings.redirect_uri
42
- }).then(function () {
43
- console.log("Redirect logged in using cidaas sdk");
44
- });
45
- }
46
- else {
47
- throw "user manager is null";
48
- }
52
+ Authentication.prototype.loginOrRegisterWithBrowser = function (view_type, options) {
53
+ var _a;
54
+ if (!this.webAuthSettings.extraQueryParams) {
55
+ this.webAuthSettings.extraQueryParams = {};
49
56
  }
50
- catch (ex) {
51
- console.log("user manager instance is empty : " + ex);
57
+ this.webAuthSettings.extraQueryParams.view_type = view_type;
58
+ if (this.webAuthSettings.response_type.indexOf("id_token") == -1 && ((_a = this.webAuthSettings.scope) === null || _a === void 0 ? void 0 : _a.indexOf("openid")) != -1 && !this.webAuthSettings.extraQueryParams.nonce) {
59
+ this.webAuthSettings.extraQueryParams.nonce = new Date().getTime().toString();
52
60
  }
61
+ return this.userManager.signinRedirect(__assign({ extraQueryParams: this.webAuthSettings.extraQueryParams, redirect_uri: this.webAuthSettings.redirect_uri }, (options && { options: options } || {})));
53
62
  };
54
63
  ;
55
64
  /**
@@ -63,67 +72,22 @@ var Authentication = /** @class */ (function () {
63
72
  * // your failure code here
64
73
  * });
65
74
  * ```
75
+ * @param {string} url optional url to read sign in state from
66
76
  */
67
- Authentication.prototype.loginCallback = function () {
68
- var _this = this;
69
- return new Promise(function (resolve, reject) {
70
- try {
71
- if (_this.userManager) {
72
- _this.userManager.signinRedirectCallback()
73
- .then(function (user) {
74
- if (user) {
75
- resolve(user);
76
- return;
77
- }
78
- resolve(undefined);
79
- })["catch"](function (ex) {
80
- reject(ex);
81
- });
82
- }
83
- else {
84
- throw "user manager is null";
85
- }
86
- }
87
- catch (ex) {
88
- reject(ex);
89
- }
90
- });
77
+ Authentication.prototype.loginCallback = function (url) {
78
+ return this.userManager.signinRedirectCallback(url);
91
79
  };
92
80
  /**
93
81
  * To use the **logout()** method, you need set the redirect url, if not it will automatically redirect to the login page
94
82
  * @example
95
83
  * ```js
96
- * cidaas.logout().then(function () {
97
- * // your logout success code here
98
- * }).catch(function(ex) {
99
- * // your failure code here
100
- * });
84
+ * cidaas.logout();
101
85
  * ```
86
+ * @param {LogoutRedirectOptions} options optional logout options to override webauth configurations
102
87
  */
103
- Authentication.prototype.logout = function () {
104
- var _this = this;
105
- return new Promise(function (resolve, reject) {
106
- try {
107
- if (_this.userManager && _this.webAuthSettings) {
108
- _this.userManager.signoutRedirect({
109
- state: _this.webAuthSettings
110
- }).then(function (resp) {
111
- console.log('signed out', resp);
112
- window.authentication.logoutCallback().then(function (resp) {
113
- resolve(resp);
114
- });
115
- });
116
- }
117
- else {
118
- throw "user manager or settings is null";
119
- }
120
- }
121
- catch (ex) {
122
- reject(ex);
123
- }
124
- });
88
+ Authentication.prototype.logout = function (options) {
89
+ return this.userManager.signoutRedirect(options);
125
90
  };
126
- ;
127
91
  /**
128
92
  * **logoutCallback()** will parses the details of userState after logout.
129
93
  * @example
@@ -134,49 +98,26 @@ var Authentication = /** @class */ (function () {
134
98
  * // your failure code here
135
99
  * });
136
100
  * ```
101
+ * @param {string} url optional url to read signout state from,
137
102
  */
138
- Authentication.prototype.logoutCallback = function () {
139
- var _this = this;
140
- return new Promise(function (resolve, reject) {
141
- try {
142
- if (_this.userManager) {
143
- _this.userManager.signoutRedirectCallback().then(function (resp) {
144
- console.log("Signed out");
145
- resolve(resp);
146
- });
147
- }
148
- else {
149
- resolve(undefined);
150
- throw "user manager is null";
151
- }
152
- }
153
- catch (ex) {
154
- reject(ex);
155
- }
156
- });
103
+ Authentication.prototype.logoutCallback = function (url) {
104
+ return this.userManager.signoutRedirectCallback(url);
157
105
  };
158
106
  ;
159
107
  /**
160
108
  * **popupSignIn()** will open the hosted login page in pop up window.
161
109
  * @example
162
110
  * ```js
163
- * cidaas.popupSignIn();
111
+ * cidaas.popupSignIn().then(function (response) {
112
+ * // the response will give you user details after finishing popupSignInCallback().
113
+ * }).catch(function(ex) {
114
+ * // your failure code here
115
+ * });
164
116
  * ```
117
+ * @param {LogoutRedirectOptions} options optional popup sign-in options to override webauth configurations
165
118
  */
166
- Authentication.prototype.popupSignIn = function () {
167
- try {
168
- if (this.userManager && this.webAuthSettings) {
169
- this.userManager.signinPopup().then(function () {
170
- console.log("signed in");
171
- });
172
- }
173
- else {
174
- throw "user manager or settings is null";
175
- }
176
- }
177
- catch (ex) {
178
- console.error(ex);
179
- }
119
+ Authentication.prototype.popupSignIn = function (options) {
120
+ return this.userManager.signinPopup(options);
180
121
  };
181
122
  ;
182
123
  /**
@@ -184,47 +125,30 @@ var Authentication = /** @class */ (function () {
184
125
  * Popup window will be closed after doing callback
185
126
  * @example
186
127
  * ```js
187
- * cidaas.popupSignInCallback().then(function (response) {
188
- * // the response will give you login details.
189
- * }).catch(function(ex) {
190
- * // your failure code here
191
- * });
128
+ * cidaas.popupSignInCallback();
192
129
  * ```
130
+ * @param {string} url optional url to read sign-in callback state from
131
+ * @param {boolean} keepOpen true to keep the popup open even after sign in, else false
193
132
  */
194
- Authentication.prototype.popupSignInCallback = function () {
195
- try {
196
- if (this.userManager) {
197
- this.userManager.signinPopupCallback();
198
- }
199
- }
200
- catch (ex) {
201
- console.error(ex);
202
- }
133
+ Authentication.prototype.popupSignInCallback = function (url, keepOpen) {
134
+ return this.userManager.signinPopupCallback(url, keepOpen);
203
135
  };
204
136
  ;
205
137
  /**
206
138
  * **popupSignOut()** will open the hosted logout page in pop up window.
207
139
  * @example
208
140
  * ```js
209
- * cidaas.popupSignOut()
141
+ * cidaas.popupSignOut().then(function() {
142
+ * // success callback in main application window after finishing popupSignOutCallback().
143
+ * }).catch(function(ex) {
144
+ * // your failure code here
145
+ * });
210
146
  * ```
147
+ *
148
+ * @param {PopupSignOutOptions} options optional options to over-ride logout options using popup window
211
149
  */
212
- Authentication.prototype.popupSignOut = function () {
213
- try {
214
- if (this.userManager && this.webAuthSettings) {
215
- this.userManager.signoutPopup({
216
- state: this.webAuthSettings
217
- }).then(function (resp) {
218
- console.log('signed out', resp);
219
- });
220
- }
221
- else {
222
- throw "user manager or settings is null";
223
- }
224
- }
225
- catch (ex) {
226
- console.error(ex);
227
- }
150
+ Authentication.prototype.popupSignOut = function (options) {
151
+ return this.userManager.signoutPopup(options);
228
152
  };
229
153
  ;
230
154
  /**
@@ -232,21 +156,19 @@ var Authentication = /** @class */ (function () {
232
156
  * Popup window won't be closed after doing callback
233
157
  * @example
234
158
  * ```js
235
- * cidaas.popupSignOutCallback();
159
+ * cidaas.popupSignOutCallback().then(function() {
160
+ * // success callback in popup window after finishing popupSignOutCallback().
161
+ * }).catch(function(ex) {
162
+ * // your failure code here
163
+ * });
236
164
  * ```
165
+ *
166
+ * @param {string} url optional url to override to check for sign out state
167
+ * @param {boolean} keepOpen true to keep the popup open even after sign out, else false
237
168
  */
238
- Authentication.prototype.popupSignOutCallback = function () {
239
- try {
240
- if (this.userManager) {
241
- this.userManager.signoutPopupCallback(this.webAuthSettings.post_logout_redirect_uri, true);
242
- }
243
- else {
244
- throw "user manager is null";
245
- }
246
- }
247
- catch (ex) {
248
- console.error(ex);
249
- }
169
+ Authentication.prototype.popupSignOutCallback = function (url, keepOpen) {
170
+ if (keepOpen === void 0) { keepOpen = true; }
171
+ return this.userManager.signoutPopupCallback(url, keepOpen);
250
172
  };
251
173
  ;
252
174
  /**
@@ -260,31 +182,10 @@ var Authentication = /** @class */ (function () {
260
182
  * // your failure code here
261
183
  * });
262
184
  * ```
185
+ * @param {SilentSignInOptions} options options to over-ride the client config for silent sign in
263
186
  */
264
- Authentication.prototype.silentSignIn = function () {
265
- var _this = this;
266
- return new Promise(function (resolve, reject) {
267
- try {
268
- if (_this.userManager && _this.webAuthSettings) {
269
- _this.userManager.signinSilent({
270
- state: _this.webAuthSettings,
271
- silentRequestTimeoutInSeconds: 60
272
- }).then(function (user) {
273
- if (user) {
274
- resolve(user);
275
- return;
276
- }
277
- resolve(undefined);
278
- });
279
- }
280
- else {
281
- throw "user manager or web auth settings is null";
282
- }
283
- }
284
- catch (ex) {
285
- reject(ex);
286
- }
287
- });
187
+ Authentication.prototype.silentSignIn = function (options) {
188
+ return this.userManager.signinSilent(__assign({ silentRequestTimeoutInSeconds: 60 }, (options && { options: options } || {})));
288
189
  };
289
190
  ;
290
191
  /**
@@ -292,32 +193,12 @@ var Authentication = /** @class */ (function () {
292
193
  * @example
293
194
  * ```js
294
195
  * cidaas.silentSignInCallback();
196
+ *
295
197
  * ```
198
+ * @param {string} url optional url to read sign in state from
296
199
  */
297
- Authentication.prototype.silentSignInCallback = function (callbackurl) {
298
- var _this = this;
299
- return new Promise(function (resolve, reject) {
300
- try {
301
- if (_this.userManager) {
302
- _this.userManager.signinSilentCallback(callbackurl)
303
- .then(function (user) {
304
- if (user) {
305
- resolve(user);
306
- return;
307
- }
308
- resolve(undefined);
309
- })["catch"](function (e) {
310
- reject(e);
311
- });
312
- }
313
- else {
314
- throw "user manager is null";
315
- }
316
- }
317
- catch (ex) {
318
- reject(ex);
319
- }
320
- });
200
+ Authentication.prototype.silentSignInCallback = function (url) {
201
+ return this.userManager.signinSilentCallback(url);
321
202
  };
322
203
  ;
323
204
  return Authentication;
@@ -178,7 +178,6 @@ var LoginService;
178
178
  function firstTimeChangePassword(options) {
179
179
  try {
180
180
  var url = window.webAuthSettings.authority + "/login-srv/precheck/continue/" + options.loginSettingsId;
181
- ;
182
181
  var form = Helper_1.Helper.createForm(url, options);
183
182
  document.body.appendChild(form);
184
183
  form.submit();
@@ -102,7 +102,7 @@ var TokenService;
102
102
  options.redirect_uri = window.webAuthSettings.redirect_uri;
103
103
  options.grant_type = "authorization_code";
104
104
  if (!!window.webAuthSettings.disablePKCE) return [3 /*break*/, 2];
105
- return [4 /*yield*/, window.usermanager._client.createSigninRequest(window.webAuthSettings)];
105
+ return [4 /*yield*/, window.usermanager.getClient().createSigninRequest(window.webAuthSettings)];
106
106
  case 1:
107
107
  signInRequest = _b.sent();
108
108
  options.code_verifier = (_a = signInRequest.state) === null || _a === void 0 ? void 0 : _a.code_verifier;
@@ -1,38 +1,58 @@
1
- import { SigninState, UserManagerSettings } from "oidc-client-ts";
1
+ import { OidcSettings, LoginRedirectOptions, LogoutRedirectOptions, PopupSignInOptions, PopupSignOutOptions, SilentSignInOptions, LoginRequestOptions, User, LogoutResponse } from '../authentication';
2
2
  import { AccessTokenRequest, TokenIntrospectionEntity, UserEntity, ResetPasswordEntity, IConfiguredListRequestEntity, IInitVerificationAuthenticationRequestEntity, FindUserEntity, IUserEntity, IEnrollVerificationSetupRequestEntity, IUserLinkEntity, ChangePasswordEntity, IConsentAcceptEntity, IAuthVerificationAuthenticationRequestEntity, LoginFormRequestEntity, AccountVerificationRequestEntity, ValidateResetPasswordEntity, AcceptResetPasswordEntity, PhysicalVerificationLoginRequest, IChangePasswordEntity, IUserActivityPayloadEntity } from "./Entities";
3
+ export declare const createPreloginWebauth: (authority: string) => WebAuth;
3
4
  export declare class WebAuth {
4
- constructor(settings: UserManagerSettings);
5
+ constructor(settings: OidcSettings);
5
6
  /**
6
- * login
7
+ * Generate and redirect to authz url in same window for logging in.
8
+ * @param {LoginRedirectOptions} options options options to over-ride the client config for redirect login
7
9
  */
8
- loginWithBrowser(): void;
10
+ loginWithBrowser(options?: LoginRedirectOptions): Promise<void>;
9
11
  /**
10
- * popupSignIn
12
+ * Generate and open authz url in a popup window.
13
+ * On successful sign in, authenticated user is returned.
14
+ *
15
+ * @param {PopupSignInOptions} options options to over-ride the client config for popup sign in
16
+ * @returns {Promise<User>} Authenticated user
17
+ * @throws error if unable to get the parse and get user
11
18
  */
12
- popupSignIn(): void;
19
+ popupSignIn(options?: PopupSignInOptions): Promise<User>;
13
20
  /**
14
- * silentSignIn
21
+ * Generate and navigate to authz url in an iFrame.
22
+ * On successful sign in, authenticated user is returned
23
+ *
24
+ * @param {SilentSignInOptions} options options to over-ride the client config for silent sign in
25
+ * @returns {Promise<User>} Authenticated user
26
+ * @throws error if unable to get the parse and get user
15
27
  */
16
- silentSignIn(): Promise<unknown>;
28
+ silentSignIn(options?: SilentSignInOptions): Promise<User>;
17
29
  /**
18
- * register
30
+ * Generate and redirect to authz url in same window for register view.
31
+ * @param {LoginRedirectOptions} options options options to over-ride the client config for redirect login
19
32
  */
20
- registerWithBrowser(): void;
33
+ registerWithBrowser(options?: LoginRedirectOptions): Promise<void>;
21
34
  /**
22
- * login callback
23
- * @returns
35
+ * Once login successful, it will automatically redirects you to the redirect url whatever you mentioned in the options.
36
+ * To complete the login process, call **loginCallback()**. This will parses the access_token, id_token and whatever in hash in the redirect url.
37
+ *
38
+ * @param {string} url optional url from where to process the login state
39
+ * @returns {Promise<User>} Authenticated user
40
+ * @throws error if unable to get the parse and get user
24
41
  */
25
- loginCallback(): Promise<unknown>;
42
+ loginCallback(url?: string): Promise<User>;
26
43
  /**
27
- * popup signin callback
28
- * @returns
44
+ * To complete the popup login process, call **popupSignInCallback()** from the popup login window.
45
+ * Popup window will be closed after doing callback
46
+ *
47
+ * @param {string} url optional url to read sign-in callback state from
48
+ * @param {boolean} keepOpen true to keep the popup open even after sign in, else false
29
49
  */
30
- popupSignInCallback(): Promise<unknown>;
50
+ popupSignInCallback(url?: string, keepOpen?: boolean): Promise<void>;
31
51
  /**
32
- * silent signin callback
33
- * @returns
52
+ * Returns a promise to notify the parent window of response from authz service
53
+ * @param {string} url optional url to check authz response, if none window.location is used
34
54
  */
35
- silentSignInCallback(): Promise<unknown>;
55
+ silentSignInCallback(url?: string): Promise<void>;
36
56
  /**
37
57
  * To get the user profile information by using oidc-client-ts library, call **getUserInfo()**. This will return the basic user profile details along with groups, roles and whatever scopes you mentioned in the options.
38
58
  * @example
@@ -41,30 +61,32 @@ export declare class WebAuth {
41
61
  * // the response will give you profile details.
42
62
  * }).catch(function(ex) {
43
63
  * // your failure code here
44
- * });;
64
+ * });
45
65
  * ```
66
+ * @return {Promise<User|null>} returns authenticated user if present, else null
46
67
  */
47
- getUserInfo(): Promise<any>;
68
+ getUserInfo(): Promise<User | null>;
48
69
  /**
49
70
  * logout by using oidc-client-ts library
50
- * @returns
71
+ * @param {LogoutRedirectOptions} options optional options to over-ride logout options on redirect
51
72
  */
52
- logout(): Promise<unknown>;
73
+ logout(options?: LogoutRedirectOptions): Promise<void>;
53
74
  /**
54
- * popup signout
55
- * @returns
75
+ * logout by using oidc-client-ts library
76
+ * @param {PopupSignOutOptions} options optional options to over-ride logout options using popup window
56
77
  */
57
- popupSignOut(): Promise<unknown>;
78
+ popupSignOut(options?: PopupSignOutOptions): Promise<void>;
58
79
  /**
59
- * logout callback
60
- * @returns
80
+ * get the logout call state from the url provided, if none is provided current window url is used
81
+ * @returns {Promise<LogoutResponse>} logout response from auth service
61
82
  */
62
- logoutCallback(): Promise<unknown>;
83
+ logoutCallback(url?: string): Promise<LogoutResponse>;
63
84
  /**
64
- * popup signout callback
65
- * @returns
85
+ * listen to popup sign out event
86
+ * @param {string} url optional url to override to check for sign out state
87
+ * @param {boolean} keepOpen true to keep the popup open even after sign out, else false
66
88
  */
67
- popupSignOutCallback(): Promise<unknown>;
89
+ popupSignOutCallback(url?: string, keepOpen?: boolean): Promise<void>;
68
90
  /**
69
91
  * To get the generated login url, call **getLoginURL()**. This will call authz service and generate login url to be used.
70
92
  * @example
@@ -73,10 +95,12 @@ export declare class WebAuth {
73
95
  * // the response will give you login url.
74
96
  * }).catch(function(ex) {
75
97
  * // your failure code here
76
- * });;
98
+ * });
77
99
  * ```
100
+ * @param {LoginRequestOptions} options login options to override {@link window.webAuthSettings} provided
101
+ * @return {Promise<string>} authz url for login
78
102
  */
79
- getLoginURL(state?: SigninState): Promise<unknown>;
103
+ getLoginURL(options?: LoginRequestOptions): Promise<string>;
80
104
  /**
81
105
  * Each and every proccesses starts with requestId, it is an entry point to login or register. For getting the requestId, call **getRequestId()**.
82
106
  * @example
@@ -85,7 +109,7 @@ export declare class WebAuth {
85
109
  * // the response will give you request id.
86
110
  * }).catch(function(ex) {
87
111
  * // your failure code here
88
- * });;
112
+ * });
89
113
  * ```
90
114
  */
91
115
  getRequestId(): Promise<unknown>;
@@ -97,7 +121,7 @@ export declare class WebAuth {
97
121
  * // the response will give you tenant details
98
122
  * }).catch(function(ex) {
99
123
  * // your failure code here
100
- * });;
124
+ * });
101
125
  * ```
102
126
  */
103
127
  getTenantInfo(): Promise<unknown>;
@@ -590,10 +614,26 @@ export declare class WebAuth {
590
614
  }): Promise<unknown>;
591
615
  /**
592
616
  * getMissingFields
593
- * @param trackId
594
- * @returns
617
+ * @param trackId - required. If only trackId is given, it will get missing fields from cidaas after succesfull registration using default provider
618
+ * @param useSocialProvider - optional. If given, it will get missing fields from social provider after successful registration using social provider
619
+ *
620
+ * @example
621
+ * ```js
622
+ * const trackId = 'your track id'
623
+ * const useSocialProvider = {
624
+ * requestId: 'request id from cidaas'
625
+ * };
626
+ * cidaas.getMissingFields(trackId, useSocialProvider).then(function (resp) {
627
+ * // your success code
628
+ * }).catch(function(ex) {
629
+ * // your failure code
630
+ * });
631
+ * ```
632
+ *
595
633
  */
596
- getMissingFields(trackId: string): Promise<unknown>;
634
+ getMissingFields(trackId: string, useSocialProvider?: {
635
+ requestId: string;
636
+ }): Promise<unknown>;
597
637
  /**
598
638
  * progressiveRegistration
599
639
  * @param options