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.
@@ -47,8 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  }
48
48
  };
49
49
  exports.__esModule = true;
50
- exports.WebAuth = void 0;
51
- var oidc_client_ts_1 = require("oidc-client-ts");
50
+ exports.WebAuth = exports.createPreloginWebauth = void 0;
52
51
  var authentication_1 = require("../authentication");
53
52
  var Helper_1 = require("./Helper");
54
53
  var LoginService_1 = require("./LoginService");
@@ -56,6 +55,10 @@ var UserService_1 = require("./UserService");
56
55
  var TokenService_1 = require("./TokenService");
57
56
  var VerificationService_1 = require("./VerificationService");
58
57
  var ConsentService_1 = require("./ConsentService");
58
+ var createPreloginWebauth = function (authority) {
59
+ return new WebAuth({ 'authority': authority });
60
+ };
61
+ exports.createPreloginWebauth = createPreloginWebauth;
59
62
  var WebAuth = /** @class */ (function () {
60
63
  function WebAuth(settings) {
61
64
  try {
@@ -68,12 +71,12 @@ var WebAuth = /** @class */ (function () {
68
71
  if (settings.authority && settings.authority.charAt(settings.authority.length - 1) === '/') {
69
72
  settings.authority = settings.authority.slice(0, settings.authority.length - 1);
70
73
  }
71
- var usermanager = new oidc_client_ts_1.UserManager(settings);
74
+ var usermanager = new authentication_1.OidcManager(settings);
72
75
  window.webAuthSettings = settings;
73
76
  window.usermanager = usermanager;
74
77
  window.localeSettings = null;
75
78
  window.authentication = new authentication_1.Authentication(window.webAuthSettings, window.usermanager);
76
- window.usermanager.events.addSilentRenewError(function (error) {
79
+ window.usermanager.events.addSilentRenewError(function () {
77
80
  throw new Helper_1.CustomException("Error while renewing silent login", 500);
78
81
  });
79
82
  }
@@ -83,126 +86,95 @@ var WebAuth = /** @class */ (function () {
83
86
  }
84
87
  // prototype methods
85
88
  /**
86
- * login
89
+ * Generate and redirect to authz url in same window for logging in.
90
+ * @param {LoginRedirectOptions} options options options to over-ride the client config for redirect login
87
91
  */
88
- WebAuth.prototype.loginWithBrowser = function () {
89
- try {
90
- if (!window.webAuthSettings && !window.authentication) {
91
- throw new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417);
92
- }
93
- window.authentication.loginOrRegisterWithBrowser('login');
94
- }
95
- catch (ex) {
96
- console.log(ex);
92
+ WebAuth.prototype.loginWithBrowser = function (options) {
93
+ if (!window.webAuthSettings || !window.authentication) {
94
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
97
95
  }
96
+ return window.authentication.loginOrRegisterWithBrowser('login', options);
98
97
  };
99
98
  ;
100
99
  /**
101
- * popupSignIn
100
+ * Generate and open authz url in a popup window.
101
+ * On successful sign in, authenticated user is returned.
102
+ *
103
+ * @param {PopupSignInOptions} options options to over-ride the client config for popup sign in
104
+ * @returns {Promise<User>} Authenticated user
105
+ * @throws error if unable to get the parse and get user
102
106
  */
103
- WebAuth.prototype.popupSignIn = function () {
104
- try {
105
- if (!window.webAuthSettings && !window.authentication) {
106
- throw new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417);
107
- }
108
- window.authentication.popupSignIn();
109
- }
110
- catch (ex) {
111
- console.log(ex);
107
+ WebAuth.prototype.popupSignIn = function (options) {
108
+ if (!window.webAuthSettings || !window.authentication) {
109
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
112
110
  }
111
+ return window.authentication.popupSignIn(options);
113
112
  };
114
113
  ;
115
114
  /**
116
- * silentSignIn
115
+ * Generate and navigate to authz url in an iFrame.
116
+ * On successful sign in, authenticated user is returned
117
+ *
118
+ * @param {SilentSignInOptions} options options to over-ride the client config for silent sign in
119
+ * @returns {Promise<User>} Authenticated user
120
+ * @throws error if unable to get the parse and get user
117
121
  */
118
- WebAuth.prototype.silentSignIn = function () {
119
- return new Promise(function (resolve, reject) {
120
- try {
121
- if (!window.webAuthSettings && !window.authentication) {
122
- throw new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417);
123
- }
124
- window.authentication.silentSignIn().then(function (user) {
125
- resolve(user);
126
- })["catch"](function (ex) {
127
- reject(ex);
128
- });
129
- }
130
- catch (ex) {
131
- console.log(ex);
132
- }
133
- });
122
+ WebAuth.prototype.silentSignIn = function (options) {
123
+ if (!window.webAuthSettings || !window.authentication) {
124
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
125
+ }
126
+ return window.authentication.silentSignIn(options);
134
127
  };
135
128
  ;
136
129
  /**
137
- * register
130
+ * Generate and redirect to authz url in same window for register view.
131
+ * @param {LoginRedirectOptions} options options options to over-ride the client config for redirect login
138
132
  */
139
- WebAuth.prototype.registerWithBrowser = function () {
140
- try {
141
- if (!window.webAuthSettings && !window.authentication) {
142
- throw new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417);
143
- }
144
- window.authentication.loginOrRegisterWithBrowser('register');
145
- }
146
- catch (ex) {
147
- console.log(ex);
133
+ WebAuth.prototype.registerWithBrowser = function (options) {
134
+ if (!window.webAuthSettings || !window.authentication) {
135
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
148
136
  }
137
+ return window.authentication.loginOrRegisterWithBrowser('register', options);
149
138
  };
150
139
  ;
151
140
  /**
152
- * login callback
153
- * @returns
141
+ * Once login successful, it will automatically redirects you to the redirect url whatever you mentioned in the options.
142
+ * To complete the login process, call **loginCallback()**. This will parses the access_token, id_token and whatever in hash in the redirect url.
143
+ *
144
+ * @param {string} url optional url from where to process the login state
145
+ * @returns {Promise<User>} Authenticated user
146
+ * @throws error if unable to get the parse and get user
154
147
  */
155
- WebAuth.prototype.loginCallback = function () {
156
- return new Promise(function (resolve, reject) {
157
- if (!window.webAuthSettings && !window.authentication) {
158
- throw new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417);
159
- }
160
- window.authentication.loginCallback().then(function (user) {
161
- resolve(user);
162
- })["catch"](function (ex) {
163
- reject(ex);
164
- });
165
- });
148
+ WebAuth.prototype.loginCallback = function (url) {
149
+ if (!window.webAuthSettings || !window.authentication) {
150
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
151
+ }
152
+ return window.authentication.loginCallback(url);
166
153
  };
167
154
  ;
168
155
  /**
169
- * popup signin callback
170
- * @returns
156
+ * To complete the popup login process, call **popupSignInCallback()** from the popup login window.
157
+ * Popup window will be closed after doing callback
158
+ *
159
+ * @param {string} url optional url to read sign-in callback state from
160
+ * @param {boolean} keepOpen true to keep the popup open even after sign in, else false
171
161
  */
172
- WebAuth.prototype.popupSignInCallback = function () {
173
- return new Promise(function (resolve, reject) {
174
- try {
175
- if (!window.webAuthSettings && !window.authentication) {
176
- throw new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417);
177
- }
178
- window.authentication.popupSignInCallback();
179
- }
180
- catch (ex) {
181
- console.log(ex);
182
- }
183
- });
162
+ WebAuth.prototype.popupSignInCallback = function (url, keepOpen) {
163
+ if (!window.webAuthSettings || !window.authentication) {
164
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
165
+ }
166
+ return window.authentication.popupSignInCallback(url, keepOpen);
184
167
  };
185
168
  ;
186
169
  /**
187
- * silent signin callback
188
- * @returns
170
+ * Returns a promise to notify the parent window of response from authz service
171
+ * @param {string} url optional url to check authz response, if none window.location is used
189
172
  */
190
- WebAuth.prototype.silentSignInCallback = function () {
191
- return new Promise(function (resolve, reject) {
192
- try {
193
- if (!window.webAuthSettings && !window.authentication) {
194
- throw new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417);
195
- }
196
- window.authentication.silentSignInCallback().then(function (data) {
197
- resolve(data);
198
- })["catch"](function (error) {
199
- reject(error);
200
- });
201
- }
202
- catch (ex) {
203
- console.log(ex);
204
- }
205
- });
173
+ WebAuth.prototype.silentSignInCallback = function (url) {
174
+ if (!window.webAuthSettings || !window.authentication) {
175
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
176
+ }
177
+ return window.authentication.silentSignInCallback(url);
206
178
  };
207
179
  ;
208
180
  /**
@@ -213,25 +185,20 @@ var WebAuth = /** @class */ (function () {
213
185
  * // the response will give you profile details.
214
186
  * }).catch(function(ex) {
215
187
  * // your failure code here
216
- * });;
188
+ * });
217
189
  * ```
190
+ * @return {Promise<User|null>} returns authenticated user if present, else null
218
191
  */
219
192
  WebAuth.prototype.getUserInfo = function () {
220
193
  return __awaiter(this, void 0, void 0, function () {
221
- var e_1;
222
194
  return __generator(this, function (_a) {
223
195
  switch (_a.label) {
224
196
  case 0:
225
- _a.trys.push([0, 4, , 5]);
226
- if (!window.usermanager) return [3 /*break*/, 2];
197
+ if (!window.usermanager) {
198
+ return [2 /*return*/, Promise.reject(new Helper_1.CustomException("UserManager cannot be empty", 417))];
199
+ }
227
200
  return [4 /*yield*/, window.usermanager.getUser()];
228
201
  case 1: return [2 /*return*/, _a.sent()];
229
- case 2: throw new Helper_1.CustomException("UserManager cannot be empty", 417);
230
- case 3: return [3 /*break*/, 5];
231
- case 4:
232
- e_1 = _a.sent();
233
- throw e_1;
234
- case 5: return [2 /*return*/];
235
202
  }
236
203
  });
237
204
  });
@@ -239,79 +206,47 @@ var WebAuth = /** @class */ (function () {
239
206
  ;
240
207
  /**
241
208
  * logout by using oidc-client-ts library
242
- * @returns
209
+ * @param {LogoutRedirectOptions} options optional options to over-ride logout options on redirect
243
210
  */
244
- WebAuth.prototype.logout = function () {
245
- return new Promise(function (resolve, reject) {
246
- try {
247
- if (!window.webAuthSettings && !window.authentication) {
248
- throw new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417);
249
- }
250
- window.authentication.logout().then(function (result) {
251
- resolve(result);
252
- return;
253
- });
254
- }
255
- catch (ex) {
256
- reject(ex);
257
- }
258
- });
211
+ WebAuth.prototype.logout = function (options) {
212
+ if (!window.webAuthSettings || !window.authentication) {
213
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
214
+ }
215
+ return window.authentication.logout(options);
259
216
  };
260
217
  ;
261
218
  /**
262
- * popup signout
263
- * @returns
219
+ * logout by using oidc-client-ts library
220
+ * @param {PopupSignOutOptions} options optional options to over-ride logout options using popup window
264
221
  */
265
- WebAuth.prototype.popupSignOut = function () {
266
- return new Promise(function (resolve, reject) {
267
- try {
268
- if (!window.webAuthSettings && !window.authentication) {
269
- throw new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417);
270
- }
271
- window.authentication.popupSignOut();
272
- }
273
- catch (ex) {
274
- reject(ex);
275
- }
276
- });
222
+ WebAuth.prototype.popupSignOut = function (options) {
223
+ if (!window.webAuthSettings || !window.authentication) {
224
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
225
+ }
226
+ return window.authentication.popupSignOut(options);
277
227
  };
278
228
  ;
279
229
  /**
280
- * logout callback
281
- * @returns
230
+ * get the logout call state from the url provided, if none is provided current window url is used
231
+ * @returns {Promise<LogoutResponse>} logout response from auth service
282
232
  */
283
- WebAuth.prototype.logoutCallback = function () {
284
- return new Promise(function (resolve, reject) {
285
- try {
286
- if (!window.webAuthSettings && !window.authentication) {
287
- throw new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417);
288
- }
289
- window.authentication.logoutCallback().then(function (resp) {
290
- resolve(resp);
291
- });
292
- }
293
- catch (ex) {
294
- reject(ex);
295
- }
296
- });
233
+ WebAuth.prototype.logoutCallback = function (url) {
234
+ if (!window.webAuthSettings || !window.authentication) {
235
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
236
+ }
237
+ return window.authentication.logoutCallback(url);
297
238
  };
298
239
  ;
299
240
  /**
300
- * popup signout callback
301
- * @returns
241
+ * listen to popup sign out event
242
+ * @param {string} url optional url to override to check for sign out state
243
+ * @param {boolean} keepOpen true to keep the popup open even after sign out, else false
302
244
  */
303
- WebAuth.prototype.popupSignOutCallback = function () {
304
- return new Promise(function (resolve, reject) {
305
- try {
306
- if (!window.webAuthSettings && !window.authentication) {
307
- throw new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417);
308
- }
309
- window.authentication.popupSignOutCallback();
310
- }
311
- catch (ex) {
312
- reject(ex);
313
- }
314
- });
245
+ WebAuth.prototype.popupSignOutCallback = function (url, keepOpen) {
246
+ if (!window.webAuthSettings || !window.authentication) {
247
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
248
+ }
249
+ return window.authentication.popupSignOutCallback(url, keepOpen);
315
250
  };
316
251
  ;
317
252
  /**
@@ -322,15 +257,19 @@ var WebAuth = /** @class */ (function () {
322
257
  * // the response will give you login url.
323
258
  * }).catch(function(ex) {
324
259
  * // your failure code here
325
- * });;
260
+ * });
326
261
  * ```
262
+ * @param {LoginRequestOptions} options login options to override {@link window.webAuthSettings} provided
263
+ * @return {Promise<string>} authz url for login
327
264
  */
328
- WebAuth.prototype.getLoginURL = function (state) {
265
+ WebAuth.prototype.getLoginURL = function (options) {
266
+ if (!window.webAuthSettings || !window.authentication) {
267
+ return Promise.reject(new Helper_1.CustomException("Settings or Authentication instance in OIDC cannot be empty", 417));
268
+ }
329
269
  return new Promise(function (resolve, reject) {
330
270
  try {
331
- window.usermanager._client.createSigninRequest({ state: state }).then(function (signinRequest) {
271
+ window.usermanager.getClient().createSigninRequest(__assign(__assign({}, window.webAuthSettings), (options && { options: options } || {}))).then(function (signinRequest) {
332
272
  resolve(signinRequest.url);
333
- return;
334
273
  });
335
274
  }
336
275
  catch (e) {
@@ -347,7 +286,7 @@ var WebAuth = /** @class */ (function () {
347
286
  * // the response will give you request id.
348
287
  * }).catch(function(ex) {
349
288
  * // your failure code here
350
- * });;
289
+ * });
351
290
  * ```
352
291
  */
353
292
  WebAuth.prototype.getRequestId = function () {
@@ -366,7 +305,7 @@ var WebAuth = /** @class */ (function () {
366
305
  * // the response will give you tenant details
367
306
  * }).catch(function(ex) {
368
307
  * // your failure code here
369
- * });;
308
+ * });
370
309
  * ```
371
310
  */
372
311
  WebAuth.prototype.getTenantInfo = function () {
@@ -385,12 +324,7 @@ var WebAuth = /** @class */ (function () {
385
324
  * ```
386
325
  */
387
326
  WebAuth.prototype.logoutUser = function (options) {
388
- try {
389
- window.location.href = window.webAuthSettings.authority + "/session/end_session?access_token_hint=" + options.access_token + "&post_logout_redirect_uri=" + window.webAuthSettings.post_logout_redirect_uri;
390
- }
391
- catch (ex) {
392
- throw new Helper_1.CustomException(ex, 417);
393
- }
327
+ window.location.href = window.webAuthSettings.authority + "/session/end_session?access_token_hint=" + options.access_token + "&post_logout_redirect_uri=" + window.webAuthSettings.post_logout_redirect_uri;
394
328
  };
395
329
  ;
396
330
  /**
@@ -953,11 +887,31 @@ var WebAuth = /** @class */ (function () {
953
887
  ;
954
888
  /**
955
889
  * getMissingFields
956
- * @param trackId
957
- * @returns
890
+ * @param trackId - required. If only trackId is given, it will get missing fields from cidaas after succesfull registration using default provider
891
+ * @param useSocialProvider - optional. If given, it will get missing fields from social provider after successful registration using social provider
892
+ *
893
+ * @example
894
+ * ```js
895
+ * const trackId = 'your track id'
896
+ * const useSocialProvider = {
897
+ * requestId: 'request id from cidaas'
898
+ * };
899
+ * cidaas.getMissingFields(trackId, useSocialProvider).then(function (resp) {
900
+ * // your success code
901
+ * }).catch(function(ex) {
902
+ * // your failure code
903
+ * });
904
+ * ```
905
+ *
958
906
  */
959
- WebAuth.prototype.getMissingFields = function (trackId) {
960
- return TokenService_1.TokenService.getMissingFields(trackId);
907
+ WebAuth.prototype.getMissingFields = function (trackId, useSocialProvider) {
908
+ if (useSocialProvider) {
909
+ var _serviceURL = window.webAuthSettings.authority + "/public-srv/public/trackinfo/" + useSocialProvider.requestId + "/" + trackId;
910
+ return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET");
911
+ }
912
+ else {
913
+ return TokenService_1.TokenService.getMissingFields(trackId);
914
+ }
961
915
  };
962
916
  ;
963
917
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cidaas-javascript-sdk",
3
- "version": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "author": "cidaas by Widas ID GmbH",
5
5
  "description": "Cidaas native javascript sdk",
6
6
  "license": "MIT",