@ts-core/oauth 3.0.22 → 3.0.24

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.
@@ -49,8 +49,8 @@ export interface IOAuthDto {
49
49
  redirectUri: string;
50
50
  }
51
51
  export interface IOAuthPopUpDto {
52
- oAuthCodeOrToken: string;
53
52
  oAuthError: string;
53
+ oAuthCodeOrToken: string;
54
54
  }
55
55
  export interface IOAuthToken {
56
56
  state?: string;
package/cjs/OAuthBase.js CHANGED
@@ -19,17 +19,23 @@ class OAuthBase extends common_1.LoggerWrapper {
19
19
  this.applicationId = applicationId;
20
20
  this.window = window;
21
21
  this.popUpCheckClose = () => {
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);
22
+ if (!this.isPopUpOpened) {
23
+ this.close();
28
24
  }
29
25
  };
30
26
  this.messageHandler = (event) => this.parsePopUpResult(this.popUpMessageParser(event));
31
27
  this.browserInternalMessageHandler = (event) => {
32
- return event.origin === this.getOriginUrl() && _.isObject(event.data) ? event.data : null;
28
+ if (event.origin !== this.getOriginUrl()) {
29
+ return null;
30
+ }
31
+ let data = event.data;
32
+ if (!_.isObject(data)) {
33
+ return null;
34
+ }
35
+ if (!common_1.ObjectUtil.hasOwnProperty(data, 'oAuthCodeOrToken') && !common_1.ObjectUtil.hasOwnProperty(data, 'oAuthError')) {
36
+ return null;
37
+ }
38
+ return data;
33
39
  };
34
40
  this.http = new common_1.TransportHttp(logger, { method: 'get' });
35
41
  this.subject = new rxjs_1.Subject();
@@ -51,8 +57,9 @@ class OAuthBase extends common_1.LoggerWrapper {
51
57
  this.promise = common_1.PromiseHandler.create();
52
58
  this.popUp = this.popUpOpen();
53
59
  this.popUpFocus();
54
- this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, common_1.DateUtil.MILLISECONDS_SECOND / 10);
55
60
  this.window.addEventListener('message', this.messageHandler, false);
61
+ this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_OPENED, this.popUp));
62
+ this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, common_1.DateUtil.MILLISECONDS_SECOND / 5);
56
63
  return this.promise.promise;
57
64
  });
58
65
  }
@@ -61,7 +68,6 @@ class OAuthBase extends common_1.LoggerWrapper {
61
68
  let top = (window.screen.height - this.popUpHeight) / 2;
62
69
  let left = (window.screen.width - this.popUpWidth) / 2;
63
70
  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
71
  return item;
66
72
  }
67
73
  popUpFocus() {
@@ -89,13 +95,13 @@ class OAuthBase extends common_1.LoggerWrapper {
89
95
  }
90
96
  if (!_.isEmpty(data.oAuthCodeOrToken)) {
91
97
  this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
98
+ this.promise = null;
92
99
  }
93
100
  if (!_.isEmpty(data.oAuthError)) {
94
101
  this.promise.reject(data.oAuthError);
102
+ this.promise = null;
95
103
  }
96
- if (!this.promise.isPending) {
97
- this.close();
98
- }
104
+ this.close();
99
105
  }
100
106
  getCode() {
101
107
  return __awaiter(this, void 0, void 0, function* () {
@@ -112,12 +118,15 @@ class OAuthBase extends common_1.LoggerWrapper {
112
118
  close() {
113
119
  this.window.removeEventListener('message', this.messageHandler, false);
114
120
  this.popUpCheckCloseTimer = null;
115
- if (!_.isNil(this.subject)) {
116
- this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_CLOSED, this.popUp));
121
+ if (_.isNil(this.popUp)) {
122
+ return;
117
123
  }
118
- if (!_.isNil(this.popUp)) {
119
- this.popUp.close();
120
- this.popUp = null;
124
+ this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_CLOSED, this.popUp));
125
+ this.popUp.close();
126
+ this.popUp = null;
127
+ if (this.isRejectWhenPopUpClosed && !_.isNil(this.promise)) {
128
+ this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
129
+ this.promise = null;
121
130
  }
122
131
  }
123
132
  destroy() {
@@ -10,11 +10,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.OAuthBackendPropertiesSet = void 0;
13
+ const OAuthBase_1 = require("../OAuthBase");
13
14
  const common_1 = require("@ts-core/common");
14
15
  const rxjs_1 = require("rxjs");
16
+ const _ = require("lodash");
15
17
  const OAuthBackendPropertiesSet = (item, redirectUri, method, timeout = common_1.DateUtil.MILLISECONDS_SECOND) => {
16
18
  item.redirectUri = redirectUri;
17
19
  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)); }));
20
+ item.popUpClosed.pipe((0, rxjs_1.delay)(timeout), (0, rxjs_1.takeUntil)(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () {
21
+ let data = yield method(item.state);
22
+ if (_.isEmpty(data)) {
23
+ data = { oAuthError: OAuthBase_1.OAuthBase.ERROR_WINDOW_CLOSED, oAuthCodeOrToken: null };
24
+ }
25
+ item.parsePopUpResult(data);
26
+ }));
19
27
  };
20
28
  exports.OAuthBackendPropertiesSet = OAuthBackendPropertiesSet;
@@ -49,8 +49,8 @@ export interface IOAuthDto {
49
49
  redirectUri: string;
50
50
  }
51
51
  export interface IOAuthPopUpDto {
52
- oAuthCodeOrToken: string;
53
52
  oAuthError: string;
53
+ oAuthCodeOrToken: string;
54
54
  }
55
55
  export interface IOAuthToken {
56
56
  state?: string;
package/esm/OAuthBase.js CHANGED
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { PromiseHandler, DateUtil, ObservableData, LoggerWrapper, TransportHttp, RandomUtil } from "@ts-core/common";
10
+ import { PromiseHandler, DateUtil, ObservableData, LoggerWrapper, TransportHttp, RandomUtil, ObjectUtil } from "@ts-core/common";
11
11
  import * as _ from 'lodash';
12
12
  import { filter, map, Subject } from "rxjs";
13
13
  export class OAuthBase extends LoggerWrapper {
@@ -16,17 +16,23 @@ export class OAuthBase extends LoggerWrapper {
16
16
  this.applicationId = applicationId;
17
17
  this.window = window;
18
18
  this.popUpCheckClose = () => {
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);
19
+ if (!this.isPopUpOpened) {
20
+ this.close();
25
21
  }
26
22
  };
27
23
  this.messageHandler = (event) => this.parsePopUpResult(this.popUpMessageParser(event));
28
24
  this.browserInternalMessageHandler = (event) => {
29
- return event.origin === this.getOriginUrl() && _.isObject(event.data) ? event.data : null;
25
+ if (event.origin !== this.getOriginUrl()) {
26
+ return null;
27
+ }
28
+ let data = event.data;
29
+ if (!_.isObject(data)) {
30
+ return null;
31
+ }
32
+ if (!ObjectUtil.hasOwnProperty(data, 'oAuthCodeOrToken') && !ObjectUtil.hasOwnProperty(data, 'oAuthError')) {
33
+ return null;
34
+ }
35
+ return data;
30
36
  };
31
37
  this.http = new TransportHttp(logger, { method: 'get' });
32
38
  this.subject = new Subject();
@@ -48,8 +54,9 @@ export class OAuthBase extends LoggerWrapper {
48
54
  this.promise = PromiseHandler.create();
49
55
  this.popUp = this.popUpOpen();
50
56
  this.popUpFocus();
51
- this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, DateUtil.MILLISECONDS_SECOND / 10);
52
57
  this.window.addEventListener('message', this.messageHandler, false);
58
+ this.subject.next(new ObservableData(OAuthEvent.POPUP_OPENED, this.popUp));
59
+ this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, DateUtil.MILLISECONDS_SECOND / 5);
53
60
  return this.promise.promise;
54
61
  });
55
62
  }
@@ -58,7 +65,6 @@ export class OAuthBase extends LoggerWrapper {
58
65
  let top = (window.screen.height - this.popUpHeight) / 2;
59
66
  let left = (window.screen.width - this.popUpWidth) / 2;
60
67
  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
68
  return item;
63
69
  }
64
70
  popUpFocus() {
@@ -86,13 +92,13 @@ export class OAuthBase extends LoggerWrapper {
86
92
  }
87
93
  if (!_.isEmpty(data.oAuthCodeOrToken)) {
88
94
  this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
95
+ this.promise = null;
89
96
  }
90
97
  if (!_.isEmpty(data.oAuthError)) {
91
98
  this.promise.reject(data.oAuthError);
99
+ this.promise = null;
92
100
  }
93
- if (!this.promise.isPending) {
94
- this.close();
95
- }
101
+ this.close();
96
102
  }
97
103
  getCode() {
98
104
  return __awaiter(this, void 0, void 0, function* () {
@@ -109,12 +115,15 @@ export class OAuthBase extends LoggerWrapper {
109
115
  close() {
110
116
  this.window.removeEventListener('message', this.messageHandler, false);
111
117
  this.popUpCheckCloseTimer = null;
112
- if (!_.isNil(this.subject)) {
113
- this.subject.next(new ObservableData(OAuthEvent.POPUP_CLOSED, this.popUp));
118
+ if (_.isNil(this.popUp)) {
119
+ return;
114
120
  }
115
- if (!_.isNil(this.popUp)) {
116
- this.popUp.close();
117
- this.popUp = null;
121
+ this.subject.next(new ObservableData(OAuthEvent.POPUP_CLOSED, this.popUp));
122
+ this.popUp.close();
123
+ this.popUp = null;
124
+ if (this.isRejectWhenPopUpClosed && !_.isNil(this.promise)) {
125
+ this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
126
+ this.promise = null;
118
127
  }
119
128
  }
120
129
  destroy() {
@@ -7,10 +7,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { OAuthBase } from '../OAuthBase';
10
11
  import { DateUtil } from '@ts-core/common';
11
12
  import { delay, takeUntil } from 'rxjs';
13
+ import * as _ from 'lodash';
12
14
  export const OAuthBackendPropertiesSet = (item, redirectUri, method, timeout = DateUtil.MILLISECONDS_SECOND) => {
13
15
  item.redirectUri = redirectUri;
14
16
  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)); }));
17
+ item.popUpClosed.pipe(delay(timeout), takeUntil(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () {
18
+ let data = yield method(item.state);
19
+ if (_.isEmpty(data)) {
20
+ data = { oAuthError: OAuthBase.ERROR_WINDOW_CLOSED, oAuthCodeOrToken: null };
21
+ }
22
+ item.parsePopUpResult(data);
23
+ }));
16
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-core/oauth",
3
- "version": "3.0.22",
3
+ "version": "3.0.24",
4
4
  "description": "Classes and utils for oauth",
5
5
  "main": "./cjs/public-api.js",
6
6
  "module": "./esm/public-api.js",