@leapdev/auth-agent 2.2.13-beta.5 → 2.2.13-beta.7

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.
package/src/index.umd.js CHANGED
@@ -44,12 +44,7 @@
44
44
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
45
45
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
46
46
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
47
- }
48
-
49
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
- var e = new Error(message);
51
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
- };
47
+ }
53
48
 
54
49
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
55
50
 
@@ -3829,9 +3824,11 @@
3829
3824
  throw Error('Missing config parameter : ' + p);
3830
3825
  }
3831
3826
  });
3827
+
3832
3828
  if (!lodash.isArray(options.scopes)) {
3833
3829
  throw Error('Scopes must be an array with string values');
3834
3830
  }
3831
+
3835
3832
  const config = Object.assign(Object.assign({}, DEFAULT_CONFIG), options);
3836
3833
  return config;
3837
3834
  };
@@ -3841,7 +3838,9 @@
3841
3838
  class LeapAuthService {
3842
3839
  constructor(authHost, clientId) {
3843
3840
  _LeapAuthService_authHost.set(this, void 0);
3841
+
3844
3842
  _LeapAuthService_clientId.set(this, void 0);
3843
+
3845
3844
  this.getAccessTokenByJti = jti => {
3846
3845
  return new Promise((resolve, reject) => {
3847
3846
  __classPrivateFieldGet(this, _LeapAuthService_xhr, "f").call(this, {
@@ -3860,6 +3859,7 @@
3860
3859
  });
3861
3860
  });
3862
3861
  };
3862
+
3863
3863
  this.getRedirections = () => {
3864
3864
  return new Promise((resolve, reject) => {
3865
3865
  __classPrivateFieldGet(this, _LeapAuthService_xhr, "f").call(this, {
@@ -3872,6 +3872,7 @@
3872
3872
  });
3873
3873
  });
3874
3874
  };
3875
+
3875
3876
  this.exchangeAuthCodeForAccessToken = params => {
3876
3877
  return new Promise((resolve, reject) => {
3877
3878
  __classPrivateFieldGet(this, _LeapAuthService_xhr, "f").call(this, {
@@ -3892,6 +3893,7 @@
3892
3893
  });
3893
3894
  });
3894
3895
  };
3896
+
3895
3897
  this.renewAccessToken = params => {
3896
3898
  return new Promise((resolve, reject) => {
3897
3899
  __classPrivateFieldGet(this, _LeapAuthService_xhr, "f").call(this, {
@@ -3911,6 +3913,7 @@
3911
3913
  });
3912
3914
  });
3913
3915
  };
3916
+
3914
3917
  this.userInfo = token => {
3915
3918
  return new Promise((resolve, reject) => {
3916
3919
  __classPrivateFieldGet(this, _LeapAuthService_xhr, "f").call(this, {
@@ -3923,6 +3926,7 @@
3923
3926
  });
3924
3927
  });
3925
3928
  };
3929
+
3926
3930
  this.linkUser = params => {
3927
3931
  const {
3928
3932
  jti,
@@ -3931,12 +3935,14 @@
3931
3935
  } = params;
3932
3936
  const redirectUrl = newWindow ? __classPrivateFieldGet(this, _LeapAuthService_authHost, "f") + LEAP_AUTH_CLOSE_WINDOW_URL : params.redirectUrl;
3933
3937
  const requestUrl = `/cloudprovider/link?client_id=${__classPrivateFieldGet(this, _LeapAuthService_clientId, "f")}&prompt=none&jti=${jti}&callback=${redirectUrl}`;
3938
+
3934
3939
  __classPrivateFieldGet(this, _LeapAuthService_redirectUrl, "f").call(this, {
3935
3940
  requestUrl,
3936
3941
  newWindow,
3937
3942
  callback
3938
3943
  });
3939
3944
  };
3945
+
3940
3946
  this.unlinkUser = params => {
3941
3947
  const {
3942
3948
  jti,
@@ -3945,12 +3951,14 @@
3945
3951
  } = params;
3946
3952
  const redirectUrl = newWindow ? __classPrivateFieldGet(this, _LeapAuthService_authHost, "f") + LEAP_AUTH_CLOSE_WINDOW_URL : params.redirectUrl;
3947
3953
  const requestUrl = `/cloudprovider/unlink?client_id=${__classPrivateFieldGet(this, _LeapAuthService_clientId, "f")}&jti=${jti}&callback=${redirectUrl}`;
3954
+
3948
3955
  __classPrivateFieldGet(this, _LeapAuthService_redirectUrl, "f").call(this, {
3949
3956
  requestUrl,
3950
3957
  newWindow,
3951
3958
  callback
3952
3959
  });
3953
3960
  };
3961
+
3954
3962
  this.getCloudProviderToken = (token, jti) => {
3955
3963
  const url = `${__classPrivateFieldGet(this, _LeapAuthService_authHost, "f")}/cloudprovider/accesstoken` + (jti ? '/' + jti : '');
3956
3964
  return new Promise((resolve, reject) => {
@@ -3964,6 +3972,7 @@
3964
3972
  });
3965
3973
  });
3966
3974
  };
3975
+
3967
3976
  this.cloudProviderUserInfo = token => {
3968
3977
  return new Promise((resolve, reject) => {
3969
3978
  __classPrivateFieldGet(this, _LeapAuthService_xhr, "f").call(this, {
@@ -3976,6 +3985,7 @@
3976
3985
  });
3977
3986
  });
3978
3987
  };
3988
+
3979
3989
  this.cloudProviderReauthenticate = params => {
3980
3990
  const {
3981
3991
  nonce,
@@ -3984,12 +3994,14 @@
3984
3994
  } = params;
3985
3995
  const redirectUrl = newWindow ? __classPrivateFieldGet(this, _LeapAuthService_authHost, "f") + LEAP_AUTH_CLOSE_WINDOW_URL : params.redirectUrl;
3986
3996
  const requestUrl = `/cloudprovider/reauthenticate?nonce=${nonce}&redirectUrl=${redirectUrl}`;
3997
+
3987
3998
  __classPrivateFieldGet(this, _LeapAuthService_redirectUrl, "f").call(this, {
3988
3999
  requestUrl,
3989
4000
  newWindow,
3990
4001
  callback
3991
4002
  });
3992
4003
  };
4004
+
3993
4005
  this.cloudProviderReauthenticateLink = token => {
3994
4006
  return new Promise((resolve, reject) => {
3995
4007
  __classPrivateFieldGet(this, _LeapAuthService_xhr, "f").call(this, {
@@ -4002,6 +4014,7 @@
4002
4014
  });
4003
4015
  });
4004
4016
  };
4017
+
4005
4018
  this.cloudProviderUpdate = params => {
4006
4019
  const {
4007
4020
  firmId,
@@ -4024,6 +4037,7 @@
4024
4037
  });
4025
4038
  });
4026
4039
  };
4040
+
4027
4041
  this.statusAdminConsent = token => {
4028
4042
  return new Promise((resolve, reject) => {
4029
4043
  __classPrivateFieldGet(this, _LeapAuthService_xhr, "f").call(this, {
@@ -4036,6 +4050,7 @@
4036
4050
  });
4037
4051
  });
4038
4052
  };
4053
+
4039
4054
  this.getAdminConsent = params => {
4040
4055
  const {
4041
4056
  domain,
@@ -4044,12 +4059,14 @@
4044
4059
  } = params;
4045
4060
  const redirectUrl = newWindow ? __classPrivateFieldGet(this, _LeapAuthService_authHost, "f") + LEAP_AUTH_CLOSE_WINDOW_URL : params.redirectUrl;
4046
4061
  const requestUrl = `/cloudprovider/adminconsent?client_id=${__classPrivateFieldGet(this, _LeapAuthService_clientId, "f")}&redirectUrl=${redirectUrl}${domain ? '&domain=' + domain : ''}`;
4062
+
4047
4063
  __classPrivateFieldGet(this, _LeapAuthService_redirectUrl, "f").call(this, {
4048
4064
  requestUrl,
4049
4065
  newWindow,
4050
4066
  callback
4051
4067
  });
4052
4068
  };
4069
+
4053
4070
  this.revokeAdminConsent = token => {
4054
4071
  return new Promise((resolve, reject) => {
4055
4072
  __classPrivateFieldGet(this, _LeapAuthService_xhr, "f").call(this, {
@@ -4062,6 +4079,7 @@
4062
4079
  });
4063
4080
  });
4064
4081
  };
4082
+
4065
4083
  this.getLinkMap = (token, allUsers) => {
4066
4084
  return new Promise((resolve, reject) => {
4067
4085
  __classPrivateFieldGet(this, _LeapAuthService_xhr, "f").call(this, {
@@ -4074,6 +4092,7 @@
4074
4092
  });
4075
4093
  });
4076
4094
  };
4095
+
4077
4096
  this.setLinkMap = (token, linkMap) => {
4078
4097
  return new Promise((resolve, reject) => {
4079
4098
  __classPrivateFieldGet(this, _LeapAuthService_xhr, "f").call(this, {
@@ -4088,6 +4107,7 @@
4088
4107
  });
4089
4108
  });
4090
4109
  };
4110
+
4091
4111
  this.authoriseSupport = (token, params) => {
4092
4112
  const {
4093
4113
  code,
@@ -4110,6 +4130,7 @@
4110
4130
  });
4111
4131
  });
4112
4132
  };
4133
+
4113
4134
  this.changePassword = params => {
4114
4135
  const {
4115
4136
  newWindow,
@@ -4119,6 +4140,7 @@
4119
4140
  let changePasswordUrl = `/oauth/changepassword?client_id=${__classPrivateFieldGet(this, _LeapAuthService_clientId, "f")}`;
4120
4141
  let redirect_uri = '';
4121
4142
  let noListener = false;
4143
+
4122
4144
  if (newWindow) {
4123
4145
  if (!!callback && typeof callback === 'function') {
4124
4146
  redirect_uri = __classPrivateFieldGet(this, _LeapAuthService_authHost, "f") + LEAP_AUTH_CLOSE_WINDOW_URL;
@@ -4129,9 +4151,11 @@
4129
4151
  } else {
4130
4152
  redirect_uri = __classPrivateFieldGet(this, _LeapAuthService_authHost, "f") + '/oauth/logout?force=true' + '&redirect_uri=' + (redirectUrl || window.location.href);
4131
4153
  }
4154
+
4132
4155
  if (redirect_uri) {
4133
4156
  changePasswordUrl += `&redirect_uri=${encodeURIComponent(redirect_uri)}`;
4134
4157
  }
4158
+
4135
4159
  __classPrivateFieldGet(this, _LeapAuthService_redirectUrl, "f").call(this, {
4136
4160
  requestUrl: changePasswordUrl,
4137
4161
  newWindow,
@@ -4139,6 +4163,7 @@
4139
4163
  noListener
4140
4164
  });
4141
4165
  };
4166
+
4142
4167
  _LeapAuthService_xhr.set(this, (params, onload) => {
4143
4168
  const {
4144
4169
  method,
@@ -4158,6 +4183,7 @@
4158
4183
  xhr.setRequestHeader('Content-type', options.contentType);
4159
4184
  xhr.setRequestHeader('Access-Control-Allow-Origin', options.accessControlAllowOrigin);
4160
4185
  if (accessToken) xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken);
4186
+
4161
4187
  xhr.onload = () => {
4162
4188
  try {
4163
4189
  let resp;
@@ -4167,9 +4193,11 @@
4167
4193
  onload(xhr.response, xhr.status);
4168
4194
  }
4169
4195
  };
4196
+
4170
4197
  if (options.body) options.body = JSON.stringify(options.body);
4171
4198
  xhr.send(options.body);
4172
4199
  });
4200
+
4173
4201
  _LeapAuthService_redirectUrl.set(this, params => {
4174
4202
  const {
4175
4203
  requestUrl,
@@ -4178,17 +4206,21 @@
4178
4206
  noListener
4179
4207
  } = params;
4180
4208
  const fullUrl = __classPrivateFieldGet(this, _LeapAuthService_authHost, "f") + requestUrl;
4209
+
4181
4210
  if (newWindow) {
4182
4211
  const childWindow = window.open(fullUrl, '_blank');
4212
+
4183
4213
  const eventHandler = event => {
4184
4214
  if (event && event.data === 'closeMe' && childWindow) {
4185
4215
  childWindow.close();
4216
+
4186
4217
  if (lodash.isFunction(callback)) {
4187
4218
  callback();
4188
4219
  window.removeEventListener('message', eventHandler, false);
4189
4220
  }
4190
4221
  }
4191
4222
  };
4223
+
4192
4224
  if (!noListener) {
4193
4225
  window.addEventListener('message', eventHandler, false);
4194
4226
  }
@@ -4196,13 +4228,17 @@
4196
4228
  window.location.href = fullUrl;
4197
4229
  }
4198
4230
  });
4231
+
4199
4232
  __classPrivateFieldSet(this, _LeapAuthService_authHost, authHost, "f");
4233
+
4200
4234
  __classPrivateFieldSet(this, _LeapAuthService_clientId, clientId, "f");
4201
4235
  }
4236
+
4202
4237
  }
4203
4238
  _LeapAuthService_authHost = new WeakMap(), _LeapAuthService_clientId = new WeakMap(), _LeapAuthService_xhr = new WeakMap(), _LeapAuthService_redirectUrl = new WeakMap();
4204
4239
 
4205
4240
  var HookName;
4241
+
4206
4242
  (function (HookName) {
4207
4243
  HookName["afterLogin"] = "afterLogin";
4208
4244
  HookName["beforeLogout"] = "beforeLogout";
@@ -4220,9 +4256,13 @@
4220
4256
  class Notification {
4221
4257
  constructor() {
4222
4258
  _Notification_pubnubKeys.set(this, void 0);
4259
+
4223
4260
  _Notification_pubnub.set(this, void 0);
4261
+
4224
4262
  _Notification_eventListeners.set(this, []);
4263
+
4225
4264
  _Notification_uniqueSessionTriggerHook.set(this, undefined);
4265
+
4226
4266
  this.init = params => __awaiter(this, void 0, void 0, function* () {
4227
4267
  const {
4228
4268
  authHost,
@@ -4232,11 +4272,15 @@
4232
4272
  uniqueSession,
4233
4273
  hooks
4234
4274
  } = params;
4275
+
4235
4276
  if (!!hooks && hooks.uniqueSessionTrigger) {
4236
4277
  __classPrivateFieldSet(this, _Notification_uniqueSessionTriggerHook, hooks.uniqueSessionTrigger, "f");
4237
4278
  }
4279
+
4238
4280
  __classPrivateFieldGet(this, _Notification_initFirmChannel, "f").call(this, firmId, userId);
4281
+
4239
4282
  __classPrivateFieldGet(this, _Notification_initUserChannel, "f").call(this, userId);
4283
+
4240
4284
  if (uniqueSession) {
4241
4285
  yield __classPrivateFieldGet(this, _Notification_initUniqueSessionChannel, "f").call(this, {
4242
4286
  authHost,
@@ -4244,30 +4288,37 @@
4244
4288
  });
4245
4289
  }
4246
4290
  });
4291
+
4247
4292
  this.destroy = () => {
4248
4293
  if (__classPrivateFieldGet(this, _Notification_pubnub, "f")) {
4249
4294
  __classPrivateFieldGet(this, _Notification_pubnub, "f").unsubscribeAll();
4295
+
4250
4296
  __classPrivateFieldSet(this, _Notification_eventListeners, [], "f");
4251
4297
  }
4252
4298
  };
4299
+
4253
4300
  this.registerEventListenerForUserChannel = params => {
4254
4301
  const {
4255
4302
  topic,
4256
4303
  messageType,
4257
4304
  callback
4258
4305
  } = params;
4306
+
4259
4307
  if (!lodash.isFunction(callback)) {
4260
4308
  throw Error(`Registering Event Listener ${topic} ${messageType}: callback needs to be a function`);
4261
4309
  }
4310
+
4262
4311
  __classPrivateFieldGet(this, _Notification_eventListeners, "f").push({
4263
4312
  topic,
4264
4313
  messageType,
4265
4314
  callback
4266
4315
  });
4267
4316
  };
4317
+
4268
4318
  this.setUniqueSessionTriggerHook = hook => {
4269
4319
  __classPrivateFieldSet(this, _Notification_uniqueSessionTriggerHook, hook, "f");
4270
4320
  };
4321
+
4271
4322
  _Notification_initFirmChannel.set(this, (firmId, userId) => {
4272
4323
  __classPrivateFieldGet(this, _Notification_pubnub, "f").addListener({
4273
4324
  presence: presenceEvent => {
@@ -4275,32 +4326,38 @@
4275
4326
  action,
4276
4327
  uuid
4277
4328
  } = presenceEvent;
4329
+
4278
4330
  if (uuid === __classPrivateFieldGet(this, _Notification_pubnubKeys, "f").uuid) {
4279
4331
  return;
4280
4332
  }
4333
+
4281
4334
  if (action === 'leave' || action === 'timeout') {
4282
4335
  const valuesUUID = uuid.split('~');
4283
4336
  const userIdFromPresence = valuesUUID[0] || '';
4284
4337
  const instanceGuidFromPresence = valuesUUID[1] || '';
4285
4338
  const userActionFromPresence = valuesUUID[2] || '';
4286
4339
  const isUserActionRequiredLogout = userActionFromPresence === USER_ACTION.USERNAME_CHANGED || userActionFromPresence === USER_ACTION.PASSWORD_CHANGED || userActionFromPresence === USER_ACTION.USER_DISABLED;
4340
+
4287
4341
  if (userIdFromPresence === userId && instanceGuidFromPresence === EMPTY_GUID && isUserActionRequiredLogout) {
4288
4342
  AuthAgent.logout(true);
4289
4343
  }
4290
4344
  }
4291
4345
  }
4292
4346
  });
4347
+
4293
4348
  __classPrivateFieldGet(this, _Notification_pubnub, "f").subscribe({
4294
4349
  channels: [firmId],
4295
4350
  withPresence: true
4296
4351
  });
4297
4352
  });
4353
+
4298
4354
  _Notification_initUserChannel.set(this, userId => {
4299
4355
  __classPrivateFieldGet(this, _Notification_pubnub, "f").addListener({
4300
4356
  message: data => {
4301
4357
  const {
4302
4358
  content
4303
4359
  } = data.message;
4360
+
4304
4361
  if (content && content.topic && content.messageType && content.data) {
4305
4362
  for (const eventListener of __classPrivateFieldGet(this, _Notification_eventListeners, "f")) {
4306
4363
  if (eventListener.topic === content.topic && eventListener.messageType === content.messageType && eventListener.callback && lodash.isFunction(eventListener.callback)) {
@@ -4310,11 +4367,13 @@
4310
4367
  }
4311
4368
  }
4312
4369
  });
4370
+
4313
4371
  __classPrivateFieldGet(this, _Notification_pubnub, "f").subscribe({
4314
4372
  channels: [`user_${userId}`],
4315
4373
  withPresence: false
4316
4374
  });
4317
4375
  });
4376
+
4318
4377
  _Notification_initUniqueSessionChannel.set(this, params => __awaiter(this, void 0, void 0, function* () {
4319
4378
  const decodedToken = yield AuthAgent.getDecodedAccessToken();
4320
4379
  const {
@@ -4326,29 +4385,36 @@
4326
4385
  sessionId: mySessionId,
4327
4386
  impersonatorId: myImpersonatorId
4328
4387
  } = decodedToken;
4388
+
4329
4389
  if (!decodedToken) {
4330
4390
  return;
4331
4391
  }
4392
+
4332
4393
  const channel = `auth-session-${myUserId}`;
4394
+
4333
4395
  __classPrivateFieldGet(this, _Notification_pubnub, "f").addListener({
4334
4396
  message: data => __awaiter(this, void 0, void 0, function* () {
4335
4397
  const decodedToken = yield AuthAgent.getDecodedAccessToken();
4398
+
4336
4399
  if (!decodedToken) {
4337
4400
  AuthAgent.logout(true);
4338
4401
  }
4402
+
4339
4403
  const {
4340
4404
  sessionId: mySessionId,
4341
4405
  impersonatorId: myImpersonatorId,
4342
4406
  userId: myUserId
4343
4407
  } = decodedToken;
4344
4408
  const myAgentId = localStorage.getItem('leap-auth-agent-id');
4409
+
4345
4410
  if (myAgentId && data && data.message) {
4346
4411
  const sessionId = data.message.sessionId,
4347
- authHost = data.message.authHost,
4348
- clientId = data.message.clientId,
4349
- logout = data.message.logout;
4350
- data.message.agentId;
4351
- const impersonatorId = myImpersonatorId ? myImpersonatorId : data.message.impersonatorId;
4412
+ authHost = data.message.authHost,
4413
+ clientId = data.message.clientId,
4414
+ logout = data.message.logout;
4415
+ data.message.agentId;
4416
+ const impersonatorId = myImpersonatorId ? myImpersonatorId : data.message.impersonatorId;
4417
+
4352
4418
  if (authHost === myAuthHost) {
4353
4419
  if (clientId === myClientId && sessionId !== mySessionId || clientId !== myClientId && sessionId === mySessionId && logout) {
4354
4420
  if (impersonatorId !== undefined && impersonatorId !== '') {
@@ -4365,15 +4431,19 @@
4365
4431
  }
4366
4432
  })
4367
4433
  });
4434
+
4368
4435
  __classPrivateFieldGet(this, _Notification_pubnub, "f").subscribe({
4369
4436
  channels: [channel],
4370
4437
  withPresence: true
4371
4438
  });
4439
+
4372
4440
  let agentId = localStorage.getItem('leap-auth-agent-id');
4441
+
4373
4442
  if (!agentId) {
4374
4443
  agentId = uuid.v4();
4375
4444
  localStorage.setItem('leap-auth-agent-id', agentId);
4376
4445
  }
4446
+
4377
4447
  __classPrivateFieldGet(this, _Notification_pubnub, "f").publish({
4378
4448
  message: {
4379
4449
  authHost: myAuthHost,
@@ -4389,13 +4459,16 @@
4389
4459
  }
4390
4460
  });
4391
4461
  }));
4462
+
4392
4463
  __classPrivateFieldSet(this, _Notification_pubnubKeys, {
4393
4464
  publishKey: 'pub-13f5288e-cd88-4ef9-9e68-0c11cd03ddb8',
4394
4465
  subscribeKey: 'sub-a456f002-0095-11e2-9638-9581afc33ebf',
4395
4466
  uuid: uuid.v4()
4396
4467
  }, "f");
4468
+
4397
4469
  __classPrivateFieldSet(this, _Notification_pubnub, new Pubnub__default["default"](__classPrivateFieldGet(this, _Notification_pubnubKeys, "f")), "f");
4398
4470
  }
4471
+
4399
4472
  }
4400
4473
  _Notification_pubnubKeys = new WeakMap(), _Notification_pubnub = new WeakMap(), _Notification_eventListeners = new WeakMap(), _Notification_uniqueSessionTriggerHook = new WeakMap(), _Notification_initFirmChannel = new WeakMap(), _Notification_initUserChannel = new WeakMap(), _Notification_initUniqueSessionChannel = new WeakMap();
4401
4474
 
@@ -5835,6 +5908,7 @@
5835
5908
  const deleteQueryParameter = (windowLocation, name, value) => {
5836
5909
  const nameValue = name + '=' + value;
5837
5910
  let toReplace = nameValue;
5911
+
5838
5912
  if (windowLocation.indexOf('?' + nameValue) >= 0) {
5839
5913
  if (windowLocation.indexOf('?' + nameValue + '&') >= 0) {
5840
5914
  toReplace += '&';
@@ -5844,13 +5918,16 @@
5844
5918
  } else if (windowLocation.indexOf('&' + nameValue) >= 0) {
5845
5919
  toReplace = '&' + toReplace;
5846
5920
  }
5921
+
5847
5922
  return windowLocation.replace(toReplace, '');
5848
5923
  };
5849
5924
  const getQueryParameter = name => {
5850
5925
  const paramsForSearch = parseParams(window.location.search.substring(1));
5926
+
5851
5927
  if (paramsForSearch[name]) {
5852
5928
  return paramsForSearch[name];
5853
5929
  }
5930
+
5854
5931
  return undefined;
5855
5932
  };
5856
5933
  const createCodeChallenge = verifier => __awaiter(void 0, void 0, void 0, function* () {
@@ -5878,33 +5955,41 @@
5878
5955
  randomValues.forEach(v => random += charset[v % charset.length]);
5879
5956
  return random;
5880
5957
  };
5958
+
5881
5959
  const sha256 = s => __awaiter(void 0, void 0, void 0, function* () {
5882
5960
  const digestOp = getCryptoSubtle().digest({
5883
5961
  name: 'SHA-256'
5884
5962
  }, new TextEncoder().encode(s));
5963
+
5885
5964
  if (window.msCrypto) {
5886
5965
  return new Promise((res, rej) => {
5887
5966
  digestOp.oncomplete = e => {
5888
5967
  res(e.target.result);
5889
5968
  };
5969
+
5890
5970
  digestOp.onerror = e => {
5891
5971
  rej(e.error);
5892
5972
  };
5973
+
5893
5974
  digestOp.onabort = () => {
5894
5975
  rej('The digest operation was aborted');
5895
5976
  };
5896
5977
  });
5897
5978
  }
5979
+
5898
5980
  return yield digestOp;
5899
5981
  });
5982
+
5900
5983
  const getCryptoSubtle = () => {
5901
5984
  const crypto = getCrypto();
5902
5985
  return crypto.subtle || crypto.webkitSubtle;
5903
5986
  };
5987
+
5904
5988
  const bufferToBase64UrlEncoded = input => {
5905
5989
  const ie11SafeInput = new Uint8Array(input);
5906
5990
  return urlEncodeB64(window.btoa(String.fromCharCode(...Array.from(ie11SafeInput))));
5907
5991
  };
5992
+
5908
5993
  const urlEncodeB64 = input => {
5909
5994
  const b64Chars = {
5910
5995
  '+': '-',
@@ -5913,14 +5998,17 @@
5913
5998
  };
5914
5999
  return input.replace(/[+/=]/g, m => b64Chars[m]);
5915
6000
  };
6001
+
5916
6002
  const parseParams = url => {
5917
6003
  const result = {};
5918
6004
  const params = url.split('&');
6005
+
5919
6006
  for (let i = 0; i < params.length; i++) {
5920
6007
  const param = params[i].split('=', 2);
5921
6008
  if (param.length !== 2) continue;
5922
6009
  result[param[0]] = decodeURIComponent(param[1].replace(/\+/g, " "));
5923
6010
  }
6011
+
5924
6012
  return result;
5925
6013
  };
5926
6014
 
@@ -6031,33 +6119,42 @@
6031
6119
  const redirections = redirectionConfig.environments;
6032
6120
  const suffix = topLevelDomains.find(suffix => origin.endsWith(suffix));
6033
6121
  const environmentVariables = redirectionConfig.environmentVariables;
6122
+
6034
6123
  if (suffix) {
6035
6124
  for (let i = 0; i < redirections.length; i++) {
6036
6125
  redirection = redirections[i];
6037
6126
  const tokenCriteriaMatched = containsKeys(decodedToken, redirection.criteria);
6127
+
6038
6128
  if (tokenCriteriaMatched && !!containsApplication(redirection.applications, origin)) {
6039
6129
  if (redirection.topLevelDomain !== suffix) {
6040
6130
  redirectUrl = origin.replace(suffix, redirection.topLevelDomain);
6041
6131
  }
6132
+
6042
6133
  const envVariables = environmentVariables[redirection.criteria.environment];
6134
+
6043
6135
  if (envVariables) {
6044
6136
  const prefixMappings = envVariables['prefixMappings'];
6045
6137
  const keys = Object.keys(prefixMappings);
6046
6138
  const needToUpdatePrefixKey = containsApplication(keys, origin);
6139
+
6047
6140
  if (needToUpdatePrefixKey) {
6048
6141
  const prefixValue = prefixMappings[needToUpdatePrefixKey];
6049
6142
  redirectUrl = redirectUrl ? redirectUrl.replace(needToUpdatePrefixKey, prefixValue) : origin.replace(needToUpdatePrefixKey, prefixValue);
6050
6143
  }
6051
6144
  }
6145
+
6052
6146
  break;
6053
6147
  }
6054
6148
  }
6149
+
6055
6150
  if (!!redirection && !!redirectUrl) {
6056
6151
  result = `${redirection.authHost}/oauth/passthrough?jti=${decodedToken.jti}&redirect=${encodeURIComponent(redirectUrl)}`;
6057
6152
  }
6058
6153
  }
6154
+
6059
6155
  return result;
6060
6156
  };
6157
+
6061
6158
  const containsKeys = (obj1, obj2) => {
6062
6159
  let result = true;
6063
6160
  Object.keys(obj2).forEach(key => {
@@ -6067,11 +6164,12 @@
6067
6164
  });
6068
6165
  return result;
6069
6166
  };
6167
+
6070
6168
  const containsApplication = (list, app) => {
6071
6169
  return list.find(appName => app.startsWith(`http://${appName}`) || app.startsWith(`https://${appName}`));
6072
6170
  };
6073
6171
 
6074
- var _Authentication_accessToken, _Authentication_config, _Authentication_leapAuthService, _Authentication_notification, _Authentication_popupLogin, _Authentication_refreshInfo, _Authentication_exchangeAuthCodeForAccessToken, _Authentication_verifyAndPerformRedirections, _Authentication_startRefreshAccessTokenProcess, _Authentication_destroyRefreshAccessTokenProcess, _Authentication_decodeAccessToken, _Authentication_handlePopupLogin;
6172
+ var _Authentication_accessToken, _Authentication_config, _Authentication_leapAuthService, _Authentication_notification, _Authentication_popupLogin, _Authentication_officeDialog, _Authentication_refreshInfo, _Authentication_exchangeAuthCodeForAccessToken, _Authentication_verifyAndPerformRedirections, _Authentication_startRefreshAccessTokenProcess, _Authentication_destroyRefreshAccessTokenProcess, _Authentication_decodeAccessToken, _Authentication_handlePopupLogin;
6075
6173
  const SECONDS_BEFORE_EXPIRE = 30;
6076
6174
  const MAX_SETTIME_OUT = 2147483647;
6077
6175
  const DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS = 60;
@@ -6080,25 +6178,36 @@
6080
6178
  class Authentication {
6081
6179
  constructor(options) {
6082
6180
  _Authentication_accessToken.set(this, void 0);
6181
+
6083
6182
  _Authentication_config.set(this, void 0);
6183
+
6084
6184
  _Authentication_leapAuthService.set(this, void 0);
6185
+
6085
6186
  _Authentication_notification.set(this, void 0);
6187
+
6086
6188
  _Authentication_popupLogin.set(this, void 0);
6189
+
6190
+ _Authentication_officeDialog.set(this, void 0);
6191
+
6087
6192
  _Authentication_refreshInfo.set(this, void 0);
6193
+
6088
6194
  this.registerEventListenerForUserChannel = params => {
6089
6195
  const {
6090
6196
  topic,
6091
6197
  messageType,
6092
6198
  callback
6093
6199
  } = params;
6200
+
6094
6201
  __classPrivateFieldGet(this, _Authentication_notification, "f").registerEventListenerForUserChannel({
6095
6202
  topic,
6096
6203
  messageType,
6097
6204
  callback
6098
6205
  });
6099
6206
  };
6207
+
6100
6208
  this.initNotification = () => __awaiter(this, void 0, void 0, function* () {
6101
6209
  const decodedToken = yield this.getDecodedRefreshedAccessToken();
6210
+
6102
6211
  if (decodedToken) {
6103
6212
  yield __classPrivateFieldGet(this, _Authentication_notification, "f").init({
6104
6213
  authHost: __classPrivateFieldGet(this, _Authentication_config, "f").authHost,
@@ -6110,11 +6219,14 @@
6110
6219
  });
6111
6220
  }
6112
6221
  });
6222
+
6113
6223
  this.destroyNotification = () => {
6114
6224
  __classPrivateFieldGet(this, _Authentication_notification, "f").destroy();
6115
6225
  };
6226
+
6116
6227
  this.login = params => __awaiter(this, void 0, void 0, function* () {
6117
6228
  const done = yield this.checkAuthCode();
6229
+
6118
6230
  if (done && !!__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
6119
6231
  return __classPrivateFieldGet(this, _Authentication_accessToken, "f");
6120
6232
  } else {
@@ -6131,9 +6243,12 @@
6131
6243
  code_challenge,
6132
6244
  code_challenge_method
6133
6245
  } = yield createCodeChallenge(code_verifier);
6246
+
6134
6247
  const scope = __classPrivateFieldGet(this, _Authentication_config, "f").scopes.join(',');
6248
+
6135
6249
  const prompt = noPrompt ? 'none' : '';
6136
6250
  const url = `${__classPrivateFieldGet(this, _Authentication_config, "f").authHost}/oauth/authorize?response_type=code&scope=${scope}&client_id=${__classPrivateFieldGet(this, _Authentication_config, "f").clientId}&redirect_uri=${encodeURIComponent(window.location.href)}&code_challenge=${encodeURIComponent(code_challenge)}&code_challenge_method=${code_challenge_method}&force_2fa=${force_2fa}&nonce=${nonce}&state=${state}&prompt=${prompt}&remember_me=${__classPrivateFieldGet(this, _Authentication_config, "f").rememberMe}`;
6251
+
6137
6252
  if (popup) {
6138
6253
  return __classPrivateFieldGet(this, _Authentication_handlePopupLogin, "f").call(this, url);
6139
6254
  } else {
@@ -6142,12 +6257,16 @@
6142
6257
  }
6143
6258
  }
6144
6259
  });
6260
+
6145
6261
  this.logout = (force = false, redirectUrl) => {
6146
6262
  __classPrivateFieldSet(this, _Authentication_accessToken, undefined, "f");
6263
+
6147
6264
  const redirectUri = encodeURIComponent(redirectUrl || window.location.href);
6148
6265
  window.location.href = `${__classPrivateFieldGet(this, _Authentication_config, "f").authHost}/oauth/logout?force=${force}&redirect_uri=${redirectUri}`;
6266
+
6149
6267
  __classPrivateFieldGet(this, _Authentication_destroyRefreshAccessTokenProcess, "f").call(this);
6150
6268
  };
6269
+
6151
6270
  this.getAccessToken = () => {
6152
6271
  if (__classPrivateFieldGet(this, _Authentication_accessToken, "f") === undefined || !__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
6153
6272
  return '';
@@ -6155,17 +6274,20 @@
6155
6274
  return __classPrivateFieldGet(this, _Authentication_accessToken, "f");
6156
6275
  }
6157
6276
  };
6277
+
6158
6278
  this.getRefreshedAccessToken = force => __awaiter(this, void 0, void 0, function* () {
6159
6279
  if (__classPrivateFieldGet(this, _Authentication_accessToken, "f") === undefined || !__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
6160
6280
  return '';
6161
6281
  } else {
6162
6282
  if (__classPrivateFieldGet(this, _Authentication_refreshInfo, "f") && __classPrivateFieldGet(this, _Authentication_refreshInfo, "f").accessTokenExpireIn) {
6163
6283
  const decoded = __classPrivateFieldGet(this, _Authentication_decodeAccessToken, "f").call(this, __classPrivateFieldGet(this, _Authentication_accessToken, "f"));
6284
+
6164
6285
  if (force || !!decoded && (decoded.exp - SECONDS_BEFORE_EXPIRE) * 1000 < Date.now()) {
6165
6286
  const data = yield __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").renewAccessToken({
6166
6287
  refreshToken: __classPrivateFieldGet(this, _Authentication_refreshInfo, "f").refreshToken,
6167
6288
  verifier: __classPrivateFieldGet(this, _Authentication_refreshInfo, "f").verifier
6168
6289
  });
6290
+
6169
6291
  if (data) {
6170
6292
  if (data.refresh_token && data.expires_in) {
6171
6293
  __classPrivateFieldSet(this, _Authentication_refreshInfo, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Authentication_refreshInfo, "f")), {
@@ -6173,28 +6295,37 @@
6173
6295
  accessTokenExpireIn: data.expires_in
6174
6296
  }), "f");
6175
6297
  }
6298
+
6176
6299
  __classPrivateFieldSet(this, _Authentication_accessToken, data.access_token, "f");
6300
+
6177
6301
  yield this.triggerHooks(HookName.afterRefreshToken);
6178
6302
  return __classPrivateFieldGet(this, _Authentication_accessToken, "f");
6179
6303
  }
6180
6304
  }
6181
6305
  }
6306
+
6182
6307
  return __classPrivateFieldGet(this, _Authentication_accessToken, "f");
6183
6308
  }
6184
6309
  });
6310
+
6185
6311
  this.getDecodedAccessToken = () => {
6186
6312
  if (!__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
6187
6313
  return undefined;
6188
6314
  }
6315
+
6189
6316
  return __classPrivateFieldGet(this, _Authentication_decodeAccessToken, "f").call(this, __classPrivateFieldGet(this, _Authentication_accessToken, "f"));
6190
6317
  };
6318
+
6191
6319
  this.getDecodedRefreshedAccessToken = force => __awaiter(this, void 0, void 0, function* () {
6192
6320
  const token = yield this.getRefreshedAccessToken(force);
6321
+
6193
6322
  if (!token) {
6194
6323
  return undefined;
6195
6324
  }
6325
+
6196
6326
  return __classPrivateFieldGet(this, _Authentication_decodeAccessToken, "f").call(this, token);
6197
6327
  });
6328
+
6198
6329
  this.getHooks = () => {
6199
6330
  if (__classPrivateFieldGet(this, _Authentication_config, "f")) {
6200
6331
  return __classPrivateFieldGet(this, _Authentication_config, "f").hooks;
@@ -6202,44 +6333,56 @@
6202
6333
  return undefined;
6203
6334
  }
6204
6335
  };
6336
+
6205
6337
  this.setHook = params => {
6206
6338
  const {
6207
6339
  name,
6208
6340
  callback
6209
6341
  } = params;
6342
+
6210
6343
  if (!Object.values(HookName).find(h => h === name)) {
6211
6344
  throw Error('Unsupported hook: ' + name);
6212
6345
  }
6346
+
6213
6347
  if (!lodash.isFunction(callback)) {
6214
6348
  throw Error('hook must be a function: ' + name);
6215
6349
  }
6350
+
6216
6351
  __classPrivateFieldSet(this, _Authentication_config, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Authentication_config, "f")), {
6217
6352
  hooks: Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Authentication_config, "f").hooks), {
6218
6353
  [name]: callback
6219
6354
  })
6220
6355
  }), "f");
6356
+
6221
6357
  if (name === HookName.uniqueSessionTrigger) {
6222
6358
  __classPrivateFieldGet(this, _Authentication_notification, "f").setUniqueSessionTriggerHook(callback);
6223
6359
  }
6360
+
6224
6361
  return;
6225
6362
  };
6363
+
6226
6364
  this.autoLogin = () => {
6227
6365
  return __classPrivateFieldGet(this, _Authentication_config, "f") ? __classPrivateFieldGet(this, _Authentication_config, "f").autoLogin || false : false;
6228
6366
  };
6367
+
6229
6368
  this.autoLogout = () => {
6230
6369
  return __classPrivateFieldGet(this, _Authentication_config, "f") ? __classPrivateFieldGet(this, _Authentication_config, "f").autoLogout || false : false;
6231
6370
  };
6371
+
6232
6372
  this.idleTimeoutInMinutes = () => {
6233
6373
  return __classPrivateFieldGet(this, _Authentication_config, "f") ? __classPrivateFieldGet(this, _Authentication_config, "f").idleTimeoutInMinutes || 30 : 30;
6234
6374
  };
6375
+
6235
6376
  this.checkTokenInUrl = () => {
6236
6377
  const accessTokenQuery = getQueryParameter('access_token') || getQueryParameter('auth') || getQueryParameter('authToken') || getQueryParameter('token') || getQueryParameter('jwt');
6378
+
6237
6379
  if (accessTokenQuery) {
6238
6380
  const {
6239
6381
  aud,
6240
6382
  firmId,
6241
6383
  userId
6242
6384
  } = __classPrivateFieldGet(this, _Authentication_decodeAccessToken, "f").call(this, accessTokenQuery);
6385
+
6243
6386
  if (!!firmId && !!userId && aud === '8MBJWOFS4RRRSZQC') {
6244
6387
  const queryParameterValue = accessTokenQuery;
6245
6388
  let myselfWithoutToken = deleteQueryParameter(window.location.href, 'access_token', queryParameterValue);
@@ -6251,30 +6394,38 @@
6251
6394
  window.location.href = __classPrivateFieldGet(this, _Authentication_config, "f").authHost + '/oauth/passthrough?token=' + queryParameterValue + '&redirect=' + myselfEncoded;
6252
6395
  return true;
6253
6396
  }
6397
+
6254
6398
  return false;
6255
6399
  }
6400
+
6256
6401
  return false;
6257
6402
  };
6403
+
6258
6404
  this.checkTokenInInit = () => {
6259
6405
  if (__classPrivateFieldGet(this, _Authentication_config, "f") && __classPrivateFieldGet(this, _Authentication_config, "f").initToken) {
6260
6406
  const {
6261
6407
  jti
6262
6408
  } = __classPrivateFieldGet(this, _Authentication_decodeAccessToken, "f").call(this, __classPrivateFieldGet(this, _Authentication_config, "f").initToken);
6409
+
6263
6410
  if (jti) {
6264
6411
  const windowPassthroughSession = window.sessionStorage.getItem(PASSTHROUGH_SESSION_KEY);
6412
+
6265
6413
  if (windowPassthroughSession) {
6266
6414
  window.sessionStorage.removeItem(PASSTHROUGH_SESSION_KEY);
6267
6415
  return false;
6268
6416
  }
6417
+
6269
6418
  window.sessionStorage.setItem(PASSTHROUGH_SESSION_KEY, jti);
6270
6419
  const myselfEncoded = encodeURIComponent(window.location.href);
6271
6420
  window.location.href = __classPrivateFieldGet(this, _Authentication_config, "f").authHost + '/oauth/passthrough?jti=' + jti + '&redirect=' + myselfEncoded;
6272
6421
  return true;
6273
6422
  }
6274
6423
  }
6424
+
6275
6425
  window.sessionStorage.removeItem(PASSTHROUGH_SESSION_KEY);
6276
6426
  return false;
6277
6427
  };
6428
+
6278
6429
  this.verifySession = () => __awaiter(this, void 0, void 0, function* () {
6279
6430
  const code_verifier = createRandomString(64);
6280
6431
  const state = createRandomString(6);
@@ -6283,13 +6434,17 @@
6283
6434
  code_challenge,
6284
6435
  code_challenge_method
6285
6436
  } = yield createCodeChallenge(code_verifier);
6437
+
6286
6438
  const scope = __classPrivateFieldGet(this, _Authentication_config, "f").scopes.join(',');
6439
+
6287
6440
  const redirectUri = `${window.location.protocol}//${window.location.host}${window.location.pathname}`;
6288
6441
  const url = `${__classPrivateFieldGet(this, _Authentication_config, "f").authHost}/oauth/authorize?response_type=code&response_mode=web_message&scope=${scope}&client_id=${__classPrivateFieldGet(this, _Authentication_config, "f").clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&code_challenge=${encodeURIComponent(code_challenge)}&code_challenge_method=${code_challenge_method}&state=${state}&prompt=none`;
6289
6442
  const resp = yield this.runIframe(url, state);
6443
+
6290
6444
  if (resp && resp.state) {
6291
6445
  const verifier = window.sessionStorage.getItem(resp.state);
6292
6446
  window.sessionStorage.removeItem(resp.state);
6447
+
6293
6448
  if (resp.code && verifier) {
6294
6449
  return __classPrivateFieldGet(this, _Authentication_exchangeAuthCodeForAccessToken, "f").call(this, {
6295
6450
  code: resp.code,
@@ -6303,21 +6458,23 @@
6303
6458
  return false;
6304
6459
  }
6305
6460
  });
6461
+
6306
6462
  this.checkAuthCode = () => __awaiter(this, void 0, void 0, function* () {
6307
6463
  const search = window.location.search;
6308
6464
  const queryParams = new URLSearchParams(search);
6309
6465
  const code = queryParams.get('code');
6310
6466
  const state = queryParams.get('state');
6467
+
6311
6468
  if (!!code && !!state) {
6312
- const isPopupLogin = window.localStorage.getItem('leap-auth-popup-login');
6313
- if (isPopupLogin === 'true' && window.opener) {
6314
- window.localStorage.removeItem('leap-auth-popup-login');
6315
- window.opener.postMessage({
6316
- source: 'leap-auth-popup-login',
6469
+ window.localStorage.getItem('leap-auth-popup-login');
6470
+
6471
+ if (Office) {
6472
+ const msg = {
6317
6473
  code,
6318
- state
6319
- }, '*');
6320
- window.close();
6474
+ state,
6475
+ type: 'login-code-message'
6476
+ };
6477
+ Office.context.ui.messageParent(JSON.stringify(msg));
6321
6478
  return false;
6322
6479
  } else {
6323
6480
  window.localStorage.removeItem('leap-auth-popup-login');
@@ -6337,16 +6494,21 @@
6337
6494
  return false;
6338
6495
  }
6339
6496
  });
6497
+
6340
6498
  this.getUserInfo = () => __awaiter(this, void 0, void 0, function* () {
6341
6499
  const token = yield this.getRefreshedAccessToken();
6342
6500
  return __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").userInfo(token);
6343
6501
  });
6502
+
6344
6503
  this.linkUser = params => __awaiter(this, void 0, void 0, function* () {
6345
6504
  const decodeToken = yield this.getDecodedRefreshedAccessToken();
6505
+
6346
6506
  if (!decodeToken) {
6347
6507
  return;
6348
6508
  }
6509
+
6349
6510
  const redirectUrl = params.redirectUrl || window.location.href;
6511
+
6350
6512
  __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").linkUser({
6351
6513
  redirectUrl,
6352
6514
  jti: decodeToken.jti,
@@ -6354,12 +6516,16 @@
6354
6516
  callback: params.callback
6355
6517
  });
6356
6518
  });
6519
+
6357
6520
  this.unlinkUser = params => __awaiter(this, void 0, void 0, function* () {
6358
6521
  const decodeToken = yield this.getDecodedRefreshedAccessToken();
6522
+
6359
6523
  if (!decodeToken) {
6360
6524
  return;
6361
6525
  }
6526
+
6362
6527
  const redirectUrl = params.redirectUrl || window.location.href;
6528
+
6363
6529
  __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").unlinkUser({
6364
6530
  redirectUrl,
6365
6531
  jti: decodeToken.jti,
@@ -6367,25 +6533,34 @@
6367
6533
  callback: params.callback
6368
6534
  });
6369
6535
  });
6536
+
6370
6537
  this.getCloudProviderToken = jti => __awaiter(this, void 0, void 0, function* () {
6371
6538
  const token = yield this.getRefreshedAccessToken();
6539
+
6372
6540
  if (!token) {
6373
6541
  throw Error('Not authenticated yet');
6374
6542
  }
6543
+
6375
6544
  return __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").getCloudProviderToken(token, jti);
6376
6545
  });
6546
+
6377
6547
  this.cloudProviderUserInfo = () => __awaiter(this, void 0, void 0, function* () {
6378
6548
  const token = yield this.getRefreshedAccessToken();
6549
+
6379
6550
  if (!token) {
6380
6551
  throw Error('Not authenticated yet');
6381
6552
  }
6553
+
6382
6554
  return __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").cloudProviderUserInfo(token);
6383
6555
  });
6556
+
6384
6557
  this.cloudProviderReauthenticate = params => __awaiter(this, void 0, void 0, function* () {
6385
6558
  const token = yield this.getRefreshedAccessToken();
6559
+
6386
6560
  if (!token) {
6387
6561
  throw Error('Not authenticated yet');
6388
6562
  }
6563
+
6389
6564
  let {
6390
6565
  nonce,
6391
6566
  redirectUrl
@@ -6395,10 +6570,12 @@
6395
6570
  callback
6396
6571
  } = params;
6397
6572
  redirectUrl = redirectUrl || window.location.href;
6573
+
6398
6574
  if (!nonce) {
6399
6575
  const reauthticateLink = yield __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").cloudProviderReauthenticateLink(token);
6400
6576
  nonce = reauthticateLink.nonce;
6401
6577
  }
6578
+
6402
6579
  return __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").cloudProviderReauthenticate({
6403
6580
  redirectUrl,
6404
6581
  nonce,
@@ -6406,12 +6583,16 @@
6406
6583
  callback
6407
6584
  });
6408
6585
  });
6586
+
6409
6587
  this.cloudProviderUpdate = cloudProviderId => __awaiter(this, void 0, void 0, function* () {
6410
6588
  const token = yield this.getRefreshedAccessToken();
6589
+
6411
6590
  if (!token) {
6412
6591
  throw Error('Not authenticated yet');
6413
6592
  }
6593
+
6414
6594
  const decodedToken = __classPrivateFieldGet(this, _Authentication_decodeAccessToken, "f").call(this, token);
6595
+
6415
6596
  const {
6416
6597
  firmId
6417
6598
  } = decodedToken;
@@ -6421,65 +6602,89 @@
6421
6602
  token: token
6422
6603
  });
6423
6604
  });
6605
+
6424
6606
  this.statusAdminConsent = () => __awaiter(this, void 0, void 0, function* () {
6425
6607
  const token = yield this.getRefreshedAccessToken();
6608
+
6426
6609
  if (!token) {
6427
6610
  throw Error('Not authenticated yet');
6428
6611
  }
6612
+
6429
6613
  return __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").statusAdminConsent(token);
6430
6614
  });
6615
+
6431
6616
  this.getAdminConsent = params => {
6432
6617
  const redirectUrl = params.redirectUrl || window.location.href;
6618
+
6433
6619
  __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").getAdminConsent(Object.assign(Object.assign({}, params), {
6434
6620
  redirectUrl
6435
6621
  }));
6436
6622
  };
6623
+
6437
6624
  this.revokeAdminConsent = () => __awaiter(this, void 0, void 0, function* () {
6438
6625
  const token = yield this.getRefreshedAccessToken();
6626
+
6439
6627
  if (!token) {
6440
6628
  throw Error('Not authenticated yet');
6441
6629
  }
6630
+
6442
6631
  return __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").revokeAdminConsent(token);
6443
6632
  });
6633
+
6444
6634
  this.getLinkMap = (allUsers = false) => __awaiter(this, void 0, void 0, function* () {
6445
6635
  const token = yield this.getRefreshedAccessToken();
6636
+
6446
6637
  if (!token) {
6447
6638
  throw Error('Not authenticated yet');
6448
6639
  }
6640
+
6449
6641
  return __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").getLinkMap(token, allUsers);
6450
6642
  });
6643
+
6451
6644
  this.setLinkMap = linkMap => __awaiter(this, void 0, void 0, function* () {
6452
6645
  const token = yield this.getRefreshedAccessToken();
6646
+
6453
6647
  if (!token) {
6454
6648
  throw Error('Not authenticated yet');
6455
6649
  }
6650
+
6456
6651
  const verifyFormat = () => {
6457
6652
  if (Array.isArray(linkMap)) {
6458
6653
  for (const link of linkMap) {
6459
6654
  if (!(link.internalUser && link.externalUser && link.externalUser.id)) return false;
6460
6655
  }
6656
+
6461
6657
  return true;
6462
6658
  }
6659
+
6463
6660
  return false;
6464
6661
  };
6662
+
6465
6663
  if (!verifyFormat()) throw Error('linkmap in wrong format');
6466
6664
  return __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").setLinkMap(token, linkMap);
6467
6665
  });
6666
+
6468
6667
  this.authoriseSupport = params => __awaiter(this, void 0, void 0, function* () {
6469
6668
  const token = yield this.getRefreshedAccessToken();
6669
+
6470
6670
  if (!token) {
6471
6671
  throw Error('Not authenticated yet');
6472
6672
  }
6673
+
6473
6674
  return __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").authoriseSupport(token, params);
6474
6675
  });
6676
+
6475
6677
  this.changePassword = params => {
6476
6678
  const redirectUrl = params.redirectUrl || window.location.href;
6679
+
6477
6680
  __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").changePassword(Object.assign(Object.assign({}, params), {
6478
6681
  redirectUrl
6479
6682
  }));
6480
6683
  };
6684
+
6481
6685
  this.passthrough = params => __awaiter(this, void 0, void 0, function* () {
6482
6686
  const decodedToken = yield this.getDecodedRefreshedAccessToken();
6687
+
6483
6688
  if (decodedToken && decodedToken.jti) {
6484
6689
  const {
6485
6690
  url,
@@ -6488,26 +6693,31 @@
6488
6693
  } = params;
6489
6694
  const encodedRedirectUrl = encodeURIComponent(url);
6490
6695
  const passthroughUrl = `${authHost || __classPrivateFieldGet(this, _Authentication_config, "f").authHost}/oauth/passthrough?jti=${decodedToken.jti}&redirect=${encodedRedirectUrl}&output=embed`;
6696
+
6491
6697
  if (newWindow) {
6492
6698
  window.open(passthroughUrl, '_blank');
6493
6699
  } else {
6494
6700
  window.location.assign(passthroughUrl);
6495
6701
  }
6496
6702
  }
6703
+
6497
6704
  return;
6498
6705
  });
6706
+
6499
6707
  this.triggerHooks = hookName => __awaiter(this, void 0, void 0, function* () {
6500
6708
  const hooks = this.getHooks();
6501
6709
  const token = yield this.getRefreshedAccessToken();
6502
6710
  const hookFn = hooks && !!hooks[hookName] && lodash.isFunction(hooks[hookName]) ? hooks[hookName](token) : false;
6503
6711
  return Promise.resolve(hookFn);
6504
6712
  });
6713
+
6505
6714
  this.afterAuthenticated = () => {
6506
6715
  return this.triggerHooks(HookName.afterLogin).then(() => __awaiter(this, void 0, void 0, function* () {
6507
6716
  yield this.initNotification();
6508
6717
  return __classPrivateFieldGet(this, _Authentication_accessToken, "f");
6509
6718
  }));
6510
6719
  };
6720
+
6511
6721
  this.runIframe = (authorizeUrl, state, timeoutInSeconds = DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS) => {
6512
6722
  return new Promise((res, rej) => {
6513
6723
  const iframe = window.document.createElement('iframe');
@@ -6515,17 +6725,20 @@
6515
6725
  iframe.setAttribute('height', '0');
6516
6726
  iframe.setAttribute('id', 'agent-iframe');
6517
6727
  iframe.style.display = 'none';
6728
+
6518
6729
  const removeIframe = () => {
6519
6730
  if (window.document.body.contains(iframe)) {
6520
6731
  window.document.body.removeChild(iframe);
6521
6732
  window.removeEventListener('message', iframeEventHandler, false);
6522
6733
  }
6523
6734
  };
6735
+
6524
6736
  const timeoutSetTimeoutId = setTimeout(() => {
6525
6737
  rej('agent-iframe timeout');
6526
6738
  removeIframe();
6527
6739
  window.sessionStorage.removeItem(state);
6528
6740
  }, timeoutInSeconds * 1000);
6741
+
6529
6742
  const iframeEventHandler = e => {
6530
6743
  const {
6531
6744
  data,
@@ -6534,25 +6747,30 @@
6534
6747
  } = e;
6535
6748
  if (origin !== __classPrivateFieldGet(this, _Authentication_config, "f").authHost) return;
6536
6749
  if (!data || data.type !== 'authorization_response') return;
6750
+
6537
6751
  if (source) {
6538
6752
  source.close();
6539
6753
  }
6754
+
6540
6755
  res(data.response);
6541
6756
  clearTimeout(timeoutSetTimeoutId);
6542
6757
  window.removeEventListener('message', iframeEventHandler, false);
6543
6758
  setTimeout(removeIframe, CLEANUP_IFRAME_TIMEOUT_IN_SECONDS * 1000);
6544
6759
  };
6760
+
6545
6761
  window.addEventListener('message', iframeEventHandler, false);
6546
6762
  window.document.body.appendChild(iframe);
6547
6763
  iframe.setAttribute('src', authorizeUrl);
6548
6764
  });
6549
6765
  };
6766
+
6550
6767
  _Authentication_exchangeAuthCodeForAccessToken.set(this, params => __awaiter(this, void 0, void 0, function* () {
6551
6768
  const {
6552
6769
  verifier,
6553
6770
  code,
6554
6771
  redirectUri
6555
6772
  } = params;
6773
+
6556
6774
  if (verifier) {
6557
6775
  const data = yield __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").exchangeAuthCodeForAccessToken({
6558
6776
  code,
@@ -6560,9 +6778,11 @@
6560
6778
  redirectUri
6561
6779
  });
6562
6780
  const redirectTriggered = yield __classPrivateFieldGet(this, _Authentication_verifyAndPerformRedirections, "f").call(this, data.access_token);
6781
+
6563
6782
  if (redirectTriggered) {
6564
6783
  return true;
6565
6784
  }
6785
+
6566
6786
  if (data.refresh_token && data.expires_in) {
6567
6787
  __classPrivateFieldSet(this, _Authentication_refreshInfo, {
6568
6788
  refreshToken: data.refresh_token,
@@ -6570,79 +6790,105 @@
6570
6790
  verifier: verifier,
6571
6791
  timer: undefined
6572
6792
  }, "f");
6793
+
6573
6794
  if (__classPrivateFieldGet(this, _Authentication_config, "f").autoRefreshToken) {
6574
6795
  __classPrivateFieldGet(this, _Authentication_startRefreshAccessTokenProcess, "f").call(this);
6575
6796
  }
6576
6797
  }
6798
+
6577
6799
  __classPrivateFieldSet(this, _Authentication_accessToken, data.access_token, "f");
6800
+
6578
6801
  return true;
6579
6802
  } else {
6580
6803
  return false;
6581
6804
  }
6582
6805
  }));
6806
+
6583
6807
  _Authentication_verifyAndPerformRedirections.set(this, accessToken => __awaiter(this, void 0, void 0, function* () {
6584
6808
  const redirectionConfig = yield __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").getRedirections();
6585
6809
  const origin = window.location.origin;
6810
+
6586
6811
  const decodedToken = __classPrivateFieldGet(this, _Authentication_decodeAccessToken, "f").call(this, accessToken);
6812
+
6587
6813
  const redirectUri = getRedirectUri(origin, decodedToken, redirectionConfig);
6814
+
6588
6815
  if (redirectUri) {
6589
6816
  this.logout(false, redirectUri);
6590
6817
  return true;
6591
6818
  }
6819
+
6592
6820
  return false;
6593
6821
  }));
6822
+
6594
6823
  _Authentication_startRefreshAccessTokenProcess.set(this, () => {
6595
6824
  if (!__classPrivateFieldGet(this, _Authentication_refreshInfo, "f")) {
6596
6825
  return;
6597
6826
  }
6827
+
6598
6828
  if (__classPrivateFieldGet(this, _Authentication_refreshInfo, "f").timer) {
6599
6829
  clearTimeout(__classPrivateFieldGet(this, _Authentication_refreshInfo, "f").timer);
6830
+
6600
6831
  __classPrivateFieldSet(this, _Authentication_refreshInfo, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Authentication_refreshInfo, "f")), {
6601
6832
  timer: undefined
6602
6833
  }), "f");
6603
6834
  }
6835
+
6604
6836
  const waitBeforeExecuting = (__classPrivateFieldGet(this, _Authentication_refreshInfo, "f").accessTokenExpireIn - SECONDS_BEFORE_EXPIRE) * 1000;
6837
+
6605
6838
  if (waitBeforeExecuting > MAX_SETTIME_OUT) {
6606
6839
  return;
6607
6840
  }
6841
+
6608
6842
  const timer = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
6609
6843
  if (!__classPrivateFieldGet(this, _Authentication_refreshInfo, "f")) {
6610
6844
  return;
6611
6845
  }
6846
+
6612
6847
  const data = yield __classPrivateFieldGet(this, _Authentication_leapAuthService, "f").renewAccessToken({
6613
6848
  refreshToken: __classPrivateFieldGet(this, _Authentication_refreshInfo, "f").refreshToken,
6614
6849
  verifier: __classPrivateFieldGet(this, _Authentication_refreshInfo, "f").verifier
6615
6850
  });
6851
+
6616
6852
  if (data) {
6617
6853
  if (data.refresh_token && data.expires_in) {
6618
6854
  __classPrivateFieldSet(this, _Authentication_refreshInfo, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Authentication_refreshInfo, "f")), {
6619
6855
  refreshToken: data.refresh_token,
6620
6856
  accessTokenExpireIn: data.expires_in
6621
6857
  }), "f");
6858
+
6622
6859
  __classPrivateFieldGet(this, _Authentication_startRefreshAccessTokenProcess, "f").call(this);
6623
6860
  }
6861
+
6624
6862
  __classPrivateFieldSet(this, _Authentication_accessToken, data.access_token, "f");
6863
+
6625
6864
  yield this.triggerHooks(HookName.afterRefreshToken);
6626
6865
  }
6627
6866
  }), waitBeforeExecuting);
6867
+
6628
6868
  __classPrivateFieldSet(this, _Authentication_refreshInfo, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Authentication_refreshInfo, "f")), {
6629
6869
  timer
6630
6870
  }), "f");
6631
6871
  });
6872
+
6632
6873
  _Authentication_destroyRefreshAccessTokenProcess.set(this, () => {
6633
6874
  if (!__classPrivateFieldGet(this, _Authentication_refreshInfo, "f")) {
6634
6875
  return;
6635
6876
  }
6877
+
6636
6878
  if (__classPrivateFieldGet(this, _Authentication_refreshInfo, "f").timer) {
6637
6879
  clearTimeout(__classPrivateFieldGet(this, _Authentication_refreshInfo, "f").timer);
6638
6880
  }
6881
+
6639
6882
  __classPrivateFieldSet(this, _Authentication_refreshInfo, undefined, "f");
6640
6883
  });
6884
+
6641
6885
  _Authentication_decodeAccessToken.set(this, accessToken => {
6642
6886
  if (!accessToken) {
6643
6887
  return undefined;
6644
6888
  }
6889
+
6645
6890
  const payload = accessToken.split('.')[1];
6891
+
6646
6892
  if (payload) {
6647
6893
  try {
6648
6894
  const result = window.atob(payload);
@@ -6651,52 +6897,55 @@
6651
6897
  throw Error('Fail to decode access token.');
6652
6898
  }
6653
6899
  }
6900
+
6654
6901
  return undefined;
6655
6902
  });
6903
+
6656
6904
  _Authentication_handlePopupLogin.set(this, url => {
6657
6905
  return new Promise(resolve => {
6658
6906
  __classPrivateFieldSet(this, _Authentication_popupLogin, true, "f");
6907
+
6659
6908
  window.localStorage.setItem('leap-auth-popup-login', 'true');
6660
- window.open(url, '_blank', 'menubar=0,top=500,right=0,width=600,height=600');
6661
- window.addEventListener('message', event => __awaiter(this, void 0, void 0, function* () {
6662
- if (event.data && event.data.source && event.data.source === 'leap-auth-popup-login') {
6663
- const code = event.data.code;
6664
- const state = event.data.state;
6665
- const verifier = window.sessionStorage.getItem(state);
6666
- window.sessionStorage.removeItem(state);
6667
- let newUrl = window.location.href;
6668
- newUrl = deleteQueryParameter(newUrl, 'code', code);
6669
- newUrl = deleteQueryParameter(newUrl, 'state', state);
6670
- window.history.pushState(null, '', newUrl);
6671
- const done = yield __classPrivateFieldGet(this, _Authentication_exchangeAuthCodeForAccessToken, "f").call(this, {
6672
- code,
6673
- verifier,
6674
- redirectUri: newUrl
6675
- });
6676
- if (done) {
6677
- resolve(__classPrivateFieldGet(this, _Authentication_accessToken, "f"));
6678
- } else {
6679
- resolve(undefined);
6909
+
6910
+ if (Office) {
6911
+ Office.context.ui.displayDialogAsync(url, asyncResult => {
6912
+ __classPrivateFieldSet(this, _Authentication_officeDialog, asyncResult.value, "f");
6913
+
6914
+ if (__classPrivateFieldGet(this, _Authentication_officeDialog, "f")) {
6915
+ __classPrivateFieldGet(this, _Authentication_officeDialog, "f").addEventHandler(Office.EventType.DialogMessageReceived, arg => {
6916
+ if (!!arg && arg.message) {
6917
+ console.log('---------good----------', arg.message);
6918
+ }
6919
+ });
6680
6920
  }
6681
- }
6682
- }));
6921
+ });
6922
+ }
6683
6923
  });
6684
6924
  });
6925
+
6685
6926
  __classPrivateFieldSet(this, _Authentication_accessToken, undefined, "f");
6927
+
6686
6928
  __classPrivateFieldSet(this, _Authentication_config, init$1(options), "f");
6929
+
6687
6930
  __classPrivateFieldSet(this, _Authentication_leapAuthService, new LeapAuthService(__classPrivateFieldGet(this, _Authentication_config, "f").authHost, __classPrivateFieldGet(this, _Authentication_config, "f").clientId), "f");
6931
+
6688
6932
  __classPrivateFieldSet(this, _Authentication_notification, new Notification(), "f");
6933
+
6689
6934
  __classPrivateFieldSet(this, _Authentication_popupLogin, false, "f");
6690
6935
  }
6936
+
6691
6937
  }
6692
- _Authentication_accessToken = new WeakMap(), _Authentication_config = new WeakMap(), _Authentication_leapAuthService = new WeakMap(), _Authentication_notification = new WeakMap(), _Authentication_popupLogin = new WeakMap(), _Authentication_refreshInfo = new WeakMap(), _Authentication_exchangeAuthCodeForAccessToken = new WeakMap(), _Authentication_verifyAndPerformRedirections = new WeakMap(), _Authentication_startRefreshAccessTokenProcess = new WeakMap(), _Authentication_destroyRefreshAccessTokenProcess = new WeakMap(), _Authentication_decodeAccessToken = new WeakMap(), _Authentication_handlePopupLogin = new WeakMap();
6938
+ _Authentication_accessToken = new WeakMap(), _Authentication_config = new WeakMap(), _Authentication_leapAuthService = new WeakMap(), _Authentication_notification = new WeakMap(), _Authentication_popupLogin = new WeakMap(), _Authentication_officeDialog = new WeakMap(), _Authentication_refreshInfo = new WeakMap(), _Authentication_exchangeAuthCodeForAccessToken = new WeakMap(), _Authentication_verifyAndPerformRedirections = new WeakMap(), _Authentication_startRefreshAccessTokenProcess = new WeakMap(), _Authentication_destroyRefreshAccessTokenProcess = new WeakMap(), _Authentication_decodeAccessToken = new WeakMap(), _Authentication_handlePopupLogin = new WeakMap();
6693
6939
 
6694
6940
  var _IdleTimer_timeoutInMinutes, _IdleTimer_timer, _IdleTimer_onTimeout, _IdleTimer_cleanUpTracker, _IdleTimer_clearTimeout, _IdleTimer_resetTimer;
6695
6941
  class IdleTimer {
6696
6942
  constructor(params) {
6697
6943
  _IdleTimer_timeoutInMinutes.set(this, void 0);
6944
+
6698
6945
  _IdleTimer_timer.set(this, void 0);
6946
+
6699
6947
  _IdleTimer_onTimeout.set(this, void 0);
6948
+
6700
6949
  this.tracker = () => {
6701
6950
  window.addEventListener('onload', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
6702
6951
  window.addEventListener('mousemove', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
@@ -6704,6 +6953,7 @@
6704
6953
  window.addEventListener('onscroll', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
6705
6954
  window.addEventListener('onkeypress', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
6706
6955
  };
6956
+
6707
6957
  _IdleTimer_cleanUpTracker.set(this, () => {
6708
6958
  window.removeEventListener('onload', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
6709
6959
  window.removeEventListener('mousemove', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
@@ -6711,36 +6961,49 @@
6711
6961
  window.removeEventListener('onscroll', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
6712
6962
  window.removeEventListener('onkeypress', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
6713
6963
  });
6964
+
6714
6965
  _IdleTimer_clearTimeout.set(this, () => {
6715
6966
  if (__classPrivateFieldGet(this, _IdleTimer_timer, "f")) {
6716
6967
  clearTimeout(__classPrivateFieldGet(this, _IdleTimer_timer, "f"));
6717
6968
  }
6718
6969
  });
6970
+
6719
6971
  _IdleTimer_resetTimer.set(this, () => {
6720
6972
  __classPrivateFieldGet(this, _IdleTimer_clearTimeout, "f").call(this);
6973
+
6721
6974
  __classPrivateFieldSet(this, _IdleTimer_timer, setTimeout(() => {
6722
6975
  __classPrivateFieldGet(this, _IdleTimer_clearTimeout, "f").call(this);
6976
+
6723
6977
  __classPrivateFieldGet(this, _IdleTimer_cleanUpTracker, "f").call(this);
6978
+
6724
6979
  __classPrivateFieldGet(this, _IdleTimer_onTimeout, "f").call(this);
6725
6980
  }, __classPrivateFieldGet(this, _IdleTimer_timeoutInMinutes, "f") * 60 * 1000), "f");
6726
6981
  });
6982
+
6727
6983
  const {
6728
6984
  timeoutInMinutes,
6729
6985
  onTimeout: onTimeout
6730
6986
  } = params;
6987
+
6731
6988
  __classPrivateFieldSet(this, _IdleTimer_timeoutInMinutes, timeoutInMinutes, "f");
6989
+
6732
6990
  __classPrivateFieldSet(this, _IdleTimer_onTimeout, onTimeout, "f");
6733
6991
  }
6992
+
6734
6993
  }
6735
6994
  _IdleTimer_timeoutInMinutes = new WeakMap(), _IdleTimer_timer = new WeakMap(), _IdleTimer_onTimeout = new WeakMap(), _IdleTimer_cleanUpTracker = new WeakMap(), _IdleTimer_clearTimeout = new WeakMap(), _IdleTimer_resetTimer = new WeakMap();
6736
6995
 
6737
6996
  let auth;
6997
+
6738
6998
  const init = options => __awaiter(void 0, void 0, void 0, function* () {
6739
6999
  auth = new Authentication(options);
7000
+
6740
7001
  if (!auth) {
6741
7002
  return false;
6742
7003
  }
7004
+
6743
7005
  const autoLogout = auth.autoLogout();
7006
+
6744
7007
  if (autoLogout) {
6745
7008
  const timeoutInMinutes = auth.idleTimeoutInMinutes();
6746
7009
  const idleTimer = new IdleTimer({
@@ -6749,40 +7012,55 @@
6749
7012
  });
6750
7013
  idleTimer.tracker();
6751
7014
  }
7015
+
6752
7016
  const done = yield auth.checkAuthCode();
7017
+
6753
7018
  if (done) {
6754
7019
  return auth.afterAuthenticated();
6755
7020
  }
7021
+
6756
7022
  const hasAuthSession = yield verifySession();
7023
+
6757
7024
  if (hasAuthSession) {
6758
7025
  return auth.afterAuthenticated();
6759
7026
  }
7027
+
6760
7028
  const passthrough = auth.checkTokenInUrl() || auth.checkTokenInInit();
7029
+
6761
7030
  if (passthrough) {
6762
7031
  return false;
6763
7032
  }
7033
+
6764
7034
  const autoLogin = auth.autoLogin();
7035
+
6765
7036
  if (autoLogin) {
6766
7037
  yield login();
6767
7038
  }
7039
+
6768
7040
  return true;
6769
7041
  });
7042
+
6770
7043
  const verifySession = () => __awaiter(void 0, void 0, void 0, function* () {
6771
7044
  if (!auth) {
6772
7045
  throw Error('Not init yet');
6773
7046
  }
7047
+
6774
7048
  return yield auth.verifySession();
6775
7049
  });
7050
+
6776
7051
  const getAccessToken = () => {
6777
7052
  return !auth ? '' : auth.getAccessToken();
6778
7053
  };
7054
+
6779
7055
  const getRefreshedAccessToken = force => __awaiter(void 0, void 0, void 0, function* () {
6780
7056
  return !auth ? '' : yield auth.getRefreshedAccessToken(force);
6781
7057
  });
7058
+
6782
7059
  const login = (params = {}) => __awaiter(void 0, void 0, void 0, function* () {
6783
7060
  if (!auth) {
6784
7061
  throw Error('Not init yet');
6785
7062
  }
7063
+
6786
7064
  const {
6787
7065
  force_2fa,
6788
7066
  popup
@@ -6795,87 +7073,109 @@
6795
7073
  return token && auth ? auth.afterAuthenticated() : undefined;
6796
7074
  });
6797
7075
  });
7076
+
6798
7077
  const logout = (force = false, redirectUrl) => __awaiter(void 0, void 0, void 0, function* () {
6799
7078
  if (!auth) {
6800
7079
  throw Error('Not init yet');
6801
7080
  }
7081
+
6802
7082
  return auth.triggerHooks(HookName.beforeLogout).then(() => {
6803
7083
  if (auth) {
6804
7084
  auth.destroyNotification();
6805
7085
  auth.logout(force, redirectUrl);
6806
7086
  }
7087
+
6807
7088
  return;
6808
7089
  }).catch(function (err) {
6809
7090
  console.error('Error while logging out : ', err);
6810
7091
  throw Error(err);
6811
7092
  });
6812
7093
  });
7094
+
6813
7095
  const registerHook = (hookName, callback) => {
6814
7096
  if (!auth) {
6815
7097
  throw Error('Not init yet');
6816
7098
  }
7099
+
6817
7100
  if (auth) {
6818
7101
  auth.setHook({
6819
7102
  name: hookName,
6820
7103
  callback
6821
7104
  });
6822
7105
  }
7106
+
6823
7107
  return;
6824
7108
  };
7109
+
6825
7110
  const getDecodedAccessToken = () => {
6826
7111
  if (!auth) {
6827
7112
  throw Error('Not init yet');
6828
7113
  }
7114
+
6829
7115
  return auth.getDecodedAccessToken();
6830
7116
  };
7117
+
6831
7118
  const getDecodedRefreshedAccessToken = force => __awaiter(void 0, void 0, void 0, function* () {
6832
7119
  if (!auth) {
6833
7120
  throw Error('Not init yet');
6834
7121
  }
7122
+
6835
7123
  return yield auth.getDecodedRefreshedAccessToken(force);
6836
7124
  });
7125
+
6837
7126
  const userInfo = () => {
6838
7127
  if (!auth) {
6839
7128
  throw Error('Not init yet');
6840
7129
  }
7130
+
6841
7131
  return auth.getUserInfo();
6842
7132
  };
7133
+
6843
7134
  const linkUser = (redirectUrl, newWindow, callback) => __awaiter(void 0, void 0, void 0, function* () {
6844
7135
  if (!auth) {
6845
7136
  throw Error('Not init yet');
6846
7137
  }
7138
+
6847
7139
  yield auth.linkUser({
6848
7140
  redirectUrl,
6849
7141
  newWindow,
6850
7142
  callback
6851
7143
  });
6852
7144
  });
7145
+
6853
7146
  const unlinkUser = (redirectUrl, newWindow, callback) => __awaiter(void 0, void 0, void 0, function* () {
6854
7147
  if (!auth) {
6855
7148
  throw Error('Not init yet');
6856
7149
  }
7150
+
6857
7151
  yield auth.unlinkUser({
6858
7152
  redirectUrl,
6859
7153
  newWindow,
6860
7154
  callback
6861
7155
  });
6862
7156
  });
7157
+
6863
7158
  const getCloudProviderToken = jti => {
6864
7159
  if (!auth) {
6865
7160
  throw Error('Not init yet');
6866
7161
  }
7162
+
6867
7163
  return auth.getCloudProviderToken(jti);
6868
7164
  };
7165
+
6869
7166
  const cloudProviderUserInfo = () => {
6870
7167
  if (!auth) {
6871
7168
  throw Error('Not init yet');
6872
7169
  }
7170
+
6873
7171
  return auth.cloudProviderUserInfo();
6874
7172
  };
7173
+
6875
7174
  const cloudProviderReauthenticate = (nonce, redirectUrl, newWindow, callback) => {
6876
7175
  if (!auth) {
6877
7176
  throw Error('Not init yet');
6878
7177
  }
7178
+
6879
7179
  return auth.cloudProviderReauthenticate({
6880
7180
  redirectUrl,
6881
7181
  nonce,
@@ -6883,25 +7183,32 @@
6883
7183
  callback
6884
7184
  });
6885
7185
  };
7186
+
6886
7187
  const cloudProviderUpdate = cloudProviderId => {
6887
7188
  if (!auth) {
6888
7189
  throw Error('Not init yet');
6889
7190
  }
7191
+
6890
7192
  if (!cloudProviderId) {
6891
7193
  throw Error('cloudProviderId is required');
6892
7194
  }
7195
+
6893
7196
  return auth.cloudProviderUpdate(cloudProviderId);
6894
7197
  };
7198
+
6895
7199
  const statusAdminConsent = () => {
6896
7200
  if (!auth) {
6897
7201
  throw Error('Not init yet');
6898
7202
  }
7203
+
6899
7204
  return auth.statusAdminConsent();
6900
7205
  };
7206
+
6901
7207
  const getAdminConsent = (domain, redirectUrl, newWindow, callback) => {
6902
7208
  if (!auth) {
6903
7209
  throw Error('Not init yet');
6904
7210
  }
7211
+
6905
7212
  auth.getAdminConsent({
6906
7213
  domain,
6907
7214
  redirectUrl,
@@ -6909,63 +7216,78 @@
6909
7216
  callback
6910
7217
  });
6911
7218
  };
7219
+
6912
7220
  const revokeAdminConsent = () => {
6913
7221
  if (!auth) {
6914
7222
  throw Error('Not init yet');
6915
7223
  }
7224
+
6916
7225
  return auth.revokeAdminConsent();
6917
7226
  };
7227
+
6918
7228
  const getLinkMap = allUsers => {
6919
7229
  if (!auth) {
6920
7230
  throw Error('Not init yet');
6921
7231
  }
7232
+
6922
7233
  return auth.getLinkMap(allUsers);
6923
7234
  };
7235
+
6924
7236
  const setLinkMap = linkMap => {
6925
7237
  if (!auth) {
6926
7238
  throw Error('Not init yet');
6927
7239
  }
7240
+
6928
7241
  return auth.setLinkMap(linkMap);
6929
7242
  };
7243
+
6930
7244
  const authoriseSupport = (code, duration) => {
6931
7245
  if (!auth) {
6932
7246
  throw Error('Not init yet');
6933
7247
  }
7248
+
6934
7249
  return auth.authoriseSupport({
6935
7250
  code,
6936
7251
  duration
6937
7252
  });
6938
7253
  };
7254
+
6939
7255
  const changePassword = (redirectUrl, newWindow, callback) => {
6940
7256
  if (!auth) {
6941
7257
  throw Error('Not init yet');
6942
7258
  }
7259
+
6943
7260
  auth.changePassword({
6944
7261
  redirectUrl,
6945
7262
  newWindow,
6946
7263
  callback
6947
7264
  });
6948
7265
  };
7266
+
6949
7267
  const registerEventListener = (topic, messageType, callback) => {
6950
7268
  if (!auth) {
6951
7269
  throw Error('Not init yet');
6952
7270
  }
7271
+
6953
7272
  auth.registerEventListenerForUserChannel({
6954
7273
  topic,
6955
7274
  messageType,
6956
7275
  callback
6957
7276
  });
6958
7277
  };
7278
+
6959
7279
  const passthrough = (url, newWindow = false, authHost) => __awaiter(void 0, void 0, void 0, function* () {
6960
7280
  if (!auth) {
6961
7281
  throw Error('Not init yet');
6962
7282
  }
7283
+
6963
7284
  yield auth.passthrough({
6964
7285
  url,
6965
7286
  newWindow,
6966
7287
  authHost
6967
7288
  });
6968
7289
  });
7290
+
6969
7291
  const AuthAgent = {
6970
7292
  init,
6971
7293
  registerHook,