@ts-core/oauth 3.0.25 → 3.0.26

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/cjs/OAuthBase.js CHANGED
@@ -52,7 +52,7 @@ class OAuthBase extends common_1.LoggerWrapper {
52
52
  });
53
53
  }
54
54
  popUpFocus() {
55
- if (this.isPopUpOpened) {
55
+ if (this.isPopUpOpened && _.isFunction(this.popUp.focus)) {
56
56
  this.popUp.focus();
57
57
  }
58
58
  }
@@ -1,3 +1,3 @@
1
1
  import { IOAuthPopUpDto, OAuthBase } from '../OAuthBase';
2
- export declare const OAuthCordovaInAppBrowserPluginPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod, timeout?: number) => void;
2
+ export declare const OAuthCordovaInAppBrowserPluginPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod) => void;
3
3
  export type IOAuthBackendMethod = (state: string) => Promise<IOAuthPopUpDto>;
@@ -11,25 +11,45 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.OAuthCordovaInAppBrowserPluginPropertiesSet = void 0;
13
13
  const OAuthBase_1 = require("../OAuthBase");
14
- const common_1 = require("@ts-core/common");
15
14
  const rxjs_1 = require("rxjs");
16
15
  const _ = require("lodash");
17
- const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method, timeout = common_1.DateUtil.MILLISECONDS_SECOND) => {
18
- item.popUpOpener = popUpOpener;
16
+ const common_1 = require("@ts-core/common");
17
+ const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method) => {
19
18
  item.redirectUri = redirectUri;
20
- item.isRejectWhenPopUpClosed = false;
21
- item.popUpClosed.pipe((0, rxjs_1.delay)(timeout), (0, rxjs_1.takeUntil)(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () {
22
- let data = yield method(item.state);
23
- if (_.isEmpty(data)) {
24
- data = { oAuthError: OAuthBase_1.OAuthBase.ERROR_WINDOW_CLOSED, oAuthCodeOrToken: null };
25
- }
26
- item.parseResponse(data);
19
+ item.popUpOpener = popUpOpener;
20
+ item.popUpOpened.pipe((0, rxjs_1.takeUntil)(item.destroyed)).subscribe((popUp) => __awaiter(void 0, void 0, void 0, function* () {
21
+ let popUpClosedHandler = () => {
22
+ popUp.removeEventListener('exit', popUpClosedHandler);
23
+ popUp.removeEventListener('loadstop', popUpLoadedHandler);
24
+ item.close();
25
+ };
26
+ let popUpLoadedHandler = (event) => __awaiter(void 0, void 0, void 0, function* () {
27
+ if (!event.url.includes(item.redirectUri)) {
28
+ return;
29
+ }
30
+ let data = null;
31
+ try {
32
+ data = yield method(item.state);
33
+ if (_.isEmpty(data)) {
34
+ data = { oAuthError: OAuthBase_1.OAuthBase.ERROR_WINDOW_CLOSED, oAuthCodeOrToken: null };
35
+ }
36
+ }
37
+ catch (error) {
38
+ data = { oAuthError: error.toString(), oAuthCodeOrToken: null };
39
+ }
40
+ item.parseResponse(data);
41
+ });
42
+ popUp.addEventListener('exit', popUpClosedHandler, false);
43
+ popUp.addEventListener('loadstop', popUpLoadedHandler, false);
27
44
  }));
28
45
  };
29
46
  exports.OAuthCordovaInAppBrowserPluginPropertiesSet = OAuthCordovaInAppBrowserPluginPropertiesSet;
30
47
  function popUpOpener(item, window) {
31
48
  let top = (window.screen.height - item.popUpHeight) / 2;
32
49
  let left = (window.screen.width - item.popUpWidth) / 2;
33
- let popUp = window.open(this.getUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
34
- return popUp;
50
+ let cordova = window['cordova'];
51
+ if (_.isNil(cordova) || _.isNil(cordova.InAppBrowser)) {
52
+ throw new common_1.ExtendedError(`Cordova InAppBrowser undefined, please check installed plugins`);
53
+ }
54
+ return cordova.InAppBrowser.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
35
55
  }
@@ -14,11 +14,11 @@ exports.OAuthCordovaOAuthPluginPropertiesSet = OAuthCordovaOAuthPluginProperties
14
14
  function popUpOpener(item, window) {
15
15
  let top = (window.screen.height - item.popUpHeight) / 2;
16
16
  let left = (window.screen.width - item.popUpWidth) / 2;
17
- let popUp = window.open(this.getUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
17
+ let popUp = window.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
18
18
  if (!_.isNil(popUp)) {
19
19
  return popUp;
20
20
  }
21
- let fake = { focus: () => { }, close: () => { fake.closed = true; }, closed: false };
21
+ let fake = { close: () => { fake.closed = true; }, closed: false };
22
22
  return fake;
23
23
  }
24
24
  function popUpMessageParser(item, event) {
package/esm/OAuthBase.js CHANGED
@@ -49,7 +49,7 @@ export class OAuthBase extends LoggerWrapper {
49
49
  });
50
50
  }
51
51
  popUpFocus() {
52
- if (this.isPopUpOpened) {
52
+ if (this.isPopUpOpened && _.isFunction(this.popUp.focus)) {
53
53
  this.popUp.focus();
54
54
  }
55
55
  }
@@ -1,3 +1,3 @@
1
1
  import { IOAuthPopUpDto, OAuthBase } from '../OAuthBase';
2
- export declare const OAuthCordovaInAppBrowserPluginPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod, timeout?: number) => void;
2
+ export declare const OAuthCordovaInAppBrowserPluginPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod) => void;
3
3
  export type IOAuthBackendMethod = (state: string) => Promise<IOAuthPopUpDto>;
@@ -8,24 +8,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { OAuthBase } from '../OAuthBase';
11
- import { DateUtil } from '@ts-core/common';
12
- import { delay, takeUntil } from 'rxjs';
11
+ import { takeUntil } from 'rxjs';
13
12
  import * as _ from 'lodash';
14
- export const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method, timeout = DateUtil.MILLISECONDS_SECOND) => {
15
- item.popUpOpener = popUpOpener;
13
+ import { ExtendedError } from '@ts-core/common';
14
+ export const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method) => {
16
15
  item.redirectUri = redirectUri;
17
- item.isRejectWhenPopUpClosed = false;
18
- item.popUpClosed.pipe(delay(timeout), takeUntil(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () {
19
- let data = yield method(item.state);
20
- if (_.isEmpty(data)) {
21
- data = { oAuthError: OAuthBase.ERROR_WINDOW_CLOSED, oAuthCodeOrToken: null };
22
- }
23
- item.parseResponse(data);
16
+ item.popUpOpener = popUpOpener;
17
+ item.popUpOpened.pipe(takeUntil(item.destroyed)).subscribe((popUp) => __awaiter(void 0, void 0, void 0, function* () {
18
+ let popUpClosedHandler = () => {
19
+ popUp.removeEventListener('exit', popUpClosedHandler);
20
+ popUp.removeEventListener('loadstop', popUpLoadedHandler);
21
+ item.close();
22
+ };
23
+ let popUpLoadedHandler = (event) => __awaiter(void 0, void 0, void 0, function* () {
24
+ if (!event.url.includes(item.redirectUri)) {
25
+ return;
26
+ }
27
+ let data = null;
28
+ try {
29
+ data = yield method(item.state);
30
+ if (_.isEmpty(data)) {
31
+ data = { oAuthError: OAuthBase.ERROR_WINDOW_CLOSED, oAuthCodeOrToken: null };
32
+ }
33
+ }
34
+ catch (error) {
35
+ data = { oAuthError: error.toString(), oAuthCodeOrToken: null };
36
+ }
37
+ item.parseResponse(data);
38
+ });
39
+ popUp.addEventListener('exit', popUpClosedHandler, false);
40
+ popUp.addEventListener('loadstop', popUpLoadedHandler, false);
24
41
  }));
25
42
  };
26
43
  function popUpOpener(item, window) {
27
44
  let top = (window.screen.height - item.popUpHeight) / 2;
28
45
  let left = (window.screen.width - item.popUpWidth) / 2;
29
- let popUp = window.open(this.getUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
30
- return popUp;
46
+ let cordova = window['cordova'];
47
+ if (_.isNil(cordova) || _.isNil(cordova.InAppBrowser)) {
48
+ throw new ExtendedError(`Cordova InAppBrowser undefined, please check installed plugins`);
49
+ }
50
+ return cordova.InAppBrowser.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
31
51
  }
@@ -10,11 +10,11 @@ export const OAuthCordovaOAuthPluginPropertiesSet = (item, packageName) => {
10
10
  function popUpOpener(item, window) {
11
11
  let top = (window.screen.height - item.popUpHeight) / 2;
12
12
  let left = (window.screen.width - item.popUpWidth) / 2;
13
- let popUp = window.open(this.getUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
13
+ let popUp = window.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
14
14
  if (!_.isNil(popUp)) {
15
15
  return popUp;
16
16
  }
17
- let fake = { focus: () => { }, close: () => { fake.closed = true; }, closed: false };
17
+ let fake = { close: () => { fake.closed = true; }, closed: false };
18
18
  return fake;
19
19
  }
20
20
  function popUpMessageParser(item, event) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-core/oauth",
3
- "version": "3.0.25",
3
+ "version": "3.0.26",
4
4
  "description": "Classes and utils for oauth",
5
5
  "main": "./cjs/public-api.js",
6
6
  "module": "./esm/public-api.js",