@ts-core/oauth 3.0.20 → 3.0.22

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.
@@ -7,9 +7,9 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
7
7
  popUpWidth: number;
8
8
  popUpHeight: number;
9
9
  popUpTarget: string;
10
- popUpIsCheckClose: boolean;
11
10
  popUpMessageParser: IOAuthPopUpParser;
12
11
  redirectUri: string;
12
+ isRejectWhenPopUpClosed: boolean;
13
13
  protected http: TransportHttp;
14
14
  protected subject: Subject<ObservableData<OAuthEvent, Window>>;
15
15
  protected popUp: Window;
@@ -35,6 +35,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
35
35
  getToken(): Promise<IOAuthDto>;
36
36
  close(): void;
37
37
  destroy(): void;
38
+ protected get isPopUpOpened(): boolean;
38
39
  protected get popUpCheckCloseTimer(): any;
39
40
  protected set popUpCheckCloseTimer(value: any);
40
41
  get urlParams(): Map<string, string>;
package/cjs/OAuthBase.js CHANGED
@@ -19,8 +19,12 @@ class OAuthBase extends common_1.LoggerWrapper {
19
19
  this.applicationId = applicationId;
20
20
  this.window = window;
21
21
  this.popUpCheckClose = () => {
22
- if (_.isNil(this.popUp) || this.popUp.closed) {
23
- this.close();
22
+ if (this.isPopUpOpened) {
23
+ return;
24
+ }
25
+ this.close();
26
+ if (this.isRejectWhenPopUpClosed && !_.isNil(this.promise)) {
27
+ this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
24
28
  }
25
29
  };
26
30
  this.messageHandler = (event) => this.parsePopUpResult(this.popUpMessageParser(event));
@@ -32,8 +36,8 @@ class OAuthBase extends common_1.LoggerWrapper {
32
36
  this.popUpWidth = 430;
33
37
  this.popUpHeight = 520;
34
38
  this.popUpTarget = '_blank';
35
- this.popUpIsCheckClose = true;
36
39
  this.popUpMessageParser = this.browserInternalMessageHandler;
40
+ this.isRejectWhenPopUpClosed = true;
37
41
  this._urlParams = new Map();
38
42
  this.urlParams.set('state', common_1.RandomUtil.randomString());
39
43
  this.urlParams.set('display', 'popup');
@@ -41,18 +45,13 @@ class OAuthBase extends common_1.LoggerWrapper {
41
45
  open() {
42
46
  return __awaiter(this, void 0, void 0, function* () {
43
47
  if (!_.isNil(this.promise)) {
44
- if (!_.isNil(this.popUp) && !this.popUp.closed) {
45
- this.popUp.focus();
46
- }
48
+ this.popUpFocus();
47
49
  return this.promise.promise;
48
50
  }
49
51
  this.promise = common_1.PromiseHandler.create();
50
52
  this.popUp = this.popUpOpen();
51
- this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_OPENED, this.popUp));
52
53
  this.popUpFocus();
53
- if (this.popUpIsCheckClose) {
54
- this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, common_1.DateUtil.MILLISECONDS_SECOND / 10);
55
- }
54
+ this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, common_1.DateUtil.MILLISECONDS_SECOND / 10);
56
55
  this.window.addEventListener('message', this.messageHandler, false);
57
56
  return this.promise.promise;
58
57
  });
@@ -62,10 +61,11 @@ class OAuthBase extends common_1.LoggerWrapper {
62
61
  let top = (window.screen.height - this.popUpHeight) / 2;
63
62
  let left = (window.screen.width - this.popUpWidth) / 2;
64
63
  let item = window.open(this.getUrl(), this.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
64
+ this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_OPENED, item));
65
65
  return item;
66
66
  }
67
67
  popUpFocus() {
68
- if (!_.isNil(this.popUp) && !this.popUp.closed) {
68
+ if (this.isPopUpOpened) {
69
69
  this.popUp.focus();
70
70
  }
71
71
  }
@@ -119,10 +119,6 @@ class OAuthBase extends common_1.LoggerWrapper {
119
119
  this.popUp.close();
120
120
  this.popUp = null;
121
121
  }
122
- if (!_.isNil(this.promise)) {
123
- this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
124
- this.promise = null;
125
- }
126
122
  }
127
123
  destroy() {
128
124
  if (this.isDestroyed) {
@@ -130,6 +126,10 @@ class OAuthBase extends common_1.LoggerWrapper {
130
126
  }
131
127
  super.destroy();
132
128
  this.close();
129
+ if (!_.isNil(this.promise)) {
130
+ this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
131
+ this.promise = null;
132
+ }
133
133
  if (!_.isNil(this.urlParams)) {
134
134
  this.urlParams.clear();
135
135
  this._urlParams = null;
@@ -143,6 +143,9 @@ class OAuthBase extends common_1.LoggerWrapper {
143
143
  this.subject = null;
144
144
  }
145
145
  }
146
+ get isPopUpOpened() {
147
+ return !_.isNil(this.popUp) && !this.popUp.closed;
148
+ }
146
149
  get popUpCheckCloseTimer() {
147
150
  return this._popUpCheckCloseTimer;
148
151
  }
@@ -1,3 +1,3 @@
1
1
  import { IOAuthPopUpDto, OAuthBase } from '../OAuthBase';
2
- export declare const backendPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod, timeout?: number) => void;
2
+ export declare const OAuthBackendPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod, timeout?: number) => void;
3
3
  export type IOAuthBackendMethod = (state: string) => Promise<IOAuthPopUpDto>;
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.backendPropertiesSet = void 0;
12
+ exports.OAuthBackendPropertiesSet = void 0;
13
13
  const common_1 = require("@ts-core/common");
14
14
  const rxjs_1 = require("rxjs");
15
- const backendPropertiesSet = (item, redirectUri, method, timeout = common_1.DateUtil.MILLISECONDS_SECOND) => {
15
+ const OAuthBackendPropertiesSet = (item, redirectUri, method, timeout = common_1.DateUtil.MILLISECONDS_SECOND) => {
16
16
  item.redirectUri = redirectUri;
17
- item.popUpIsCheckClose = false;
18
- item.popUpOpened.pipe((0, rxjs_1.delay)(timeout), (0, rxjs_1.takeUntil)(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () { return item.parsePopUpResult(yield method(item.state)); }));
17
+ item.isRejectWhenPopUpClosed = false;
18
+ item.popUpClosed.pipe((0, rxjs_1.delay)(timeout), (0, rxjs_1.takeUntil)(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () { return item.parsePopUpResult(yield method(item.state)); }));
19
19
  };
20
- exports.backendPropertiesSet = backendPropertiesSet;
20
+ exports.OAuthBackendPropertiesSet = OAuthBackendPropertiesSet;
@@ -1,2 +1,2 @@
1
1
  import { OAuthBase } from '../OAuthBase';
2
- export declare const cordovaPropertiesSet: (item: OAuthBase, packageName: string) => void;
2
+ export declare const OAuthCordovaPropertiesSet: (item: OAuthBase, packageName: string) => void;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cordovaPropertiesSet = void 0;
3
+ exports.OAuthCordovaPropertiesSet = void 0;
4
4
  const OAuthParser_1 = require("../OAuthParser");
5
5
  const _ = require("lodash");
6
- const cordovaPropertiesSet = (item, packageName) => {
7
- item.popUpTarget = 'oauth:cordova';
6
+ const OAuthCordovaPropertiesSet = (item, packageName) => {
8
7
  item.redirectUri = `${packageName}://oauth_callback`;
9
- item.popUpIsCheckClose = false;
8
+ item.isRejectWhenPopUpClosed = false;
9
+ item.popUpTarget = 'oauth:cordova';
10
10
  item.popUpMessageParser = cordovaPopUpMessageParser;
11
11
  };
12
- exports.cordovaPropertiesSet = cordovaPropertiesSet;
12
+ exports.OAuthCordovaPropertiesSet = OAuthCordovaPropertiesSet;
13
13
  function cordovaPopUpMessageParser(event) {
14
14
  let data = event.data;
15
15
  let prefix = 'oauth::';
@@ -7,9 +7,9 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
7
7
  popUpWidth: number;
8
8
  popUpHeight: number;
9
9
  popUpTarget: string;
10
- popUpIsCheckClose: boolean;
11
10
  popUpMessageParser: IOAuthPopUpParser;
12
11
  redirectUri: string;
12
+ isRejectWhenPopUpClosed: boolean;
13
13
  protected http: TransportHttp;
14
14
  protected subject: Subject<ObservableData<OAuthEvent, Window>>;
15
15
  protected popUp: Window;
@@ -35,6 +35,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
35
35
  getToken(): Promise<IOAuthDto>;
36
36
  close(): void;
37
37
  destroy(): void;
38
+ protected get isPopUpOpened(): boolean;
38
39
  protected get popUpCheckCloseTimer(): any;
39
40
  protected set popUpCheckCloseTimer(value: any);
40
41
  get urlParams(): Map<string, string>;
package/esm/OAuthBase.js CHANGED
@@ -16,8 +16,12 @@ export class OAuthBase extends LoggerWrapper {
16
16
  this.applicationId = applicationId;
17
17
  this.window = window;
18
18
  this.popUpCheckClose = () => {
19
- if (_.isNil(this.popUp) || this.popUp.closed) {
20
- this.close();
19
+ if (this.isPopUpOpened) {
20
+ return;
21
+ }
22
+ this.close();
23
+ if (this.isRejectWhenPopUpClosed && !_.isNil(this.promise)) {
24
+ this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
21
25
  }
22
26
  };
23
27
  this.messageHandler = (event) => this.parsePopUpResult(this.popUpMessageParser(event));
@@ -29,8 +33,8 @@ export class OAuthBase extends LoggerWrapper {
29
33
  this.popUpWidth = 430;
30
34
  this.popUpHeight = 520;
31
35
  this.popUpTarget = '_blank';
32
- this.popUpIsCheckClose = true;
33
36
  this.popUpMessageParser = this.browserInternalMessageHandler;
37
+ this.isRejectWhenPopUpClosed = true;
34
38
  this._urlParams = new Map();
35
39
  this.urlParams.set('state', RandomUtil.randomString());
36
40
  this.urlParams.set('display', 'popup');
@@ -38,18 +42,13 @@ export class OAuthBase extends LoggerWrapper {
38
42
  open() {
39
43
  return __awaiter(this, void 0, void 0, function* () {
40
44
  if (!_.isNil(this.promise)) {
41
- if (!_.isNil(this.popUp) && !this.popUp.closed) {
42
- this.popUp.focus();
43
- }
45
+ this.popUpFocus();
44
46
  return this.promise.promise;
45
47
  }
46
48
  this.promise = PromiseHandler.create();
47
49
  this.popUp = this.popUpOpen();
48
- this.subject.next(new ObservableData(OAuthEvent.POPUP_OPENED, this.popUp));
49
50
  this.popUpFocus();
50
- if (this.popUpIsCheckClose) {
51
- this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, DateUtil.MILLISECONDS_SECOND / 10);
52
- }
51
+ this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, DateUtil.MILLISECONDS_SECOND / 10);
53
52
  this.window.addEventListener('message', this.messageHandler, false);
54
53
  return this.promise.promise;
55
54
  });
@@ -59,10 +58,11 @@ export class OAuthBase extends LoggerWrapper {
59
58
  let top = (window.screen.height - this.popUpHeight) / 2;
60
59
  let left = (window.screen.width - this.popUpWidth) / 2;
61
60
  let item = window.open(this.getUrl(), this.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
61
+ this.subject.next(new ObservableData(OAuthEvent.POPUP_OPENED, item));
62
62
  return item;
63
63
  }
64
64
  popUpFocus() {
65
- if (!_.isNil(this.popUp) && !this.popUp.closed) {
65
+ if (this.isPopUpOpened) {
66
66
  this.popUp.focus();
67
67
  }
68
68
  }
@@ -116,10 +116,6 @@ export class OAuthBase extends LoggerWrapper {
116
116
  this.popUp.close();
117
117
  this.popUp = null;
118
118
  }
119
- if (!_.isNil(this.promise)) {
120
- this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
121
- this.promise = null;
122
- }
123
119
  }
124
120
  destroy() {
125
121
  if (this.isDestroyed) {
@@ -127,6 +123,10 @@ export class OAuthBase extends LoggerWrapper {
127
123
  }
128
124
  super.destroy();
129
125
  this.close();
126
+ if (!_.isNil(this.promise)) {
127
+ this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
128
+ this.promise = null;
129
+ }
130
130
  if (!_.isNil(this.urlParams)) {
131
131
  this.urlParams.clear();
132
132
  this._urlParams = null;
@@ -140,6 +140,9 @@ export class OAuthBase extends LoggerWrapper {
140
140
  this.subject = null;
141
141
  }
142
142
  }
143
+ get isPopUpOpened() {
144
+ return !_.isNil(this.popUp) && !this.popUp.closed;
145
+ }
143
146
  get popUpCheckCloseTimer() {
144
147
  return this._popUpCheckCloseTimer;
145
148
  }
@@ -1,3 +1,3 @@
1
1
  import { IOAuthPopUpDto, OAuthBase } from '../OAuthBase';
2
- export declare const backendPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod, timeout?: number) => void;
2
+ export declare const OAuthBackendPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod, timeout?: number) => void;
3
3
  export type IOAuthBackendMethod = (state: string) => Promise<IOAuthPopUpDto>;
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { DateUtil } from '@ts-core/common';
11
11
  import { delay, takeUntil } from 'rxjs';
12
- export const backendPropertiesSet = (item, redirectUri, method, timeout = DateUtil.MILLISECONDS_SECOND) => {
12
+ export const OAuthBackendPropertiesSet = (item, redirectUri, method, timeout = DateUtil.MILLISECONDS_SECOND) => {
13
13
  item.redirectUri = redirectUri;
14
- item.popUpIsCheckClose = false;
15
- item.popUpOpened.pipe(delay(timeout), takeUntil(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () { return item.parsePopUpResult(yield method(item.state)); }));
14
+ item.isRejectWhenPopUpClosed = false;
15
+ item.popUpClosed.pipe(delay(timeout), takeUntil(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () { return item.parsePopUpResult(yield method(item.state)); }));
16
16
  };
@@ -1,2 +1,2 @@
1
1
  import { OAuthBase } from '../OAuthBase';
2
- export declare const cordovaPropertiesSet: (item: OAuthBase, packageName: string) => void;
2
+ export declare const OAuthCordovaPropertiesSet: (item: OAuthBase, packageName: string) => void;
@@ -1,9 +1,9 @@
1
1
  import { OAuthParser } from '../OAuthParser';
2
2
  import * as _ from 'lodash';
3
- export const cordovaPropertiesSet = (item, packageName) => {
4
- item.popUpTarget = 'oauth:cordova';
3
+ export const OAuthCordovaPropertiesSet = (item, packageName) => {
5
4
  item.redirectUri = `${packageName}://oauth_callback`;
6
- item.popUpIsCheckClose = false;
5
+ item.isRejectWhenPopUpClosed = false;
6
+ item.popUpTarget = 'oauth:cordova';
7
7
  item.popUpMessageParser = cordovaPopUpMessageParser;
8
8
  };
9
9
  function cordovaPopUpMessageParser(event) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-core/oauth",
3
- "version": "3.0.20",
3
+ "version": "3.0.22",
4
4
  "description": "Classes and utils for oauth",
5
5
  "main": "./cjs/public-api.js",
6
6
  "module": "./esm/public-api.js",