@ts-core/oauth 3.0.14 → 3.0.16
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.d.ts +14 -6
- package/cjs/OAuthBase.js +34 -12
- package/esm/OAuthBase.d.ts +14 -6
- package/esm/OAuthBase.js +34 -12
- package/package.json +1 -1
package/cjs/OAuthBase.d.ts
CHANGED
|
@@ -3,22 +3,27 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
3
3
|
protected applicationId: string;
|
|
4
4
|
protected window?: Window;
|
|
5
5
|
static ERROR_WINDOW_CLOSED: string;
|
|
6
|
+
popUpWidth: number;
|
|
7
|
+
popUpHeight: number;
|
|
8
|
+
popUpTarget: string;
|
|
9
|
+
popUpIsCheckClose: boolean;
|
|
10
|
+
popUpMessageParser: IOAuthPopUpMessageParser;
|
|
6
11
|
redirectUri: string;
|
|
7
12
|
protected http: TransportHttp;
|
|
8
|
-
protected timer: any;
|
|
9
13
|
protected popUp: Window;
|
|
10
14
|
protected promise: PromiseHandler<IOAuthDto>;
|
|
11
|
-
protected popUpWidth: number;
|
|
12
|
-
protected popUpHeight: number;
|
|
13
15
|
protected responseType: string;
|
|
14
16
|
protected _urlParams: Map<string, string>;
|
|
17
|
+
protected _popUpCheckCloseTimer: any;
|
|
15
18
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
16
19
|
protected open(): Promise<IOAuthDto>;
|
|
17
|
-
protected
|
|
18
|
-
protected
|
|
20
|
+
protected popupOpen(): Window;
|
|
21
|
+
protected popUpFocus(): void;
|
|
22
|
+
protected popUpCheckClose: () => void;
|
|
19
23
|
protected getUrlParams(): URLSearchParams;
|
|
20
24
|
protected abstract getUrl(): string;
|
|
21
|
-
messageHandler: (event: MessageEvent
|
|
25
|
+
protected messageHandler: (event: MessageEvent) => void;
|
|
26
|
+
protected browserMessageHandler(event: MessageEvent<IOAuthPopUpDto>): IOAuthPopUpDto;
|
|
22
27
|
protected getOriginUrl(): string;
|
|
23
28
|
protected getRedirectUri(): string;
|
|
24
29
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
@@ -27,6 +32,8 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
27
32
|
getToken(): Promise<IOAuthDto>;
|
|
28
33
|
close(): void;
|
|
29
34
|
destroy(): void;
|
|
35
|
+
protected get popUpCheckCloseTimer(): any;
|
|
36
|
+
protected set popUpCheckCloseTimer(value: any);
|
|
30
37
|
get urlParams(): Map<string, string>;
|
|
31
38
|
}
|
|
32
39
|
export interface IOAuthDto {
|
|
@@ -47,3 +54,4 @@ export interface IOAuthToken {
|
|
|
47
54
|
expiresIn: number;
|
|
48
55
|
accessToken: string;
|
|
49
56
|
}
|
|
57
|
+
export type IOAuthPopUpMessageParser = (event: MessageEvent) => IOAuthPopUpDto;
|
package/cjs/OAuthBase.js
CHANGED
|
@@ -17,16 +17,14 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
17
17
|
super(logger);
|
|
18
18
|
this.applicationId = applicationId;
|
|
19
19
|
this.window = window;
|
|
20
|
-
this.
|
|
21
|
-
this.popUpHeight = 520;
|
|
22
|
-
this.checkPopUp = () => {
|
|
20
|
+
this.popUpCheckClose = () => {
|
|
23
21
|
if (_.isNil(this.popUp) || this.popUp.closed) {
|
|
24
22
|
this.close();
|
|
25
23
|
}
|
|
26
24
|
};
|
|
27
25
|
this.messageHandler = (event) => {
|
|
28
|
-
let data = event
|
|
29
|
-
if (
|
|
26
|
+
let data = this.popUpMessageParser(event);
|
|
27
|
+
if (_.isNil(data)) {
|
|
30
28
|
return;
|
|
31
29
|
}
|
|
32
30
|
if (!_.isEmpty(data.oAuthCodeOrToken)) {
|
|
@@ -40,6 +38,11 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
40
38
|
}
|
|
41
39
|
};
|
|
42
40
|
this.http = new common_1.TransportHttp(logger, { method: 'get' });
|
|
41
|
+
this.popUpWidth = 430;
|
|
42
|
+
this.popUpHeight = 520;
|
|
43
|
+
this.popUpTarget = '_blank';
|
|
44
|
+
this.popUpIsCheckClose = true;
|
|
45
|
+
this.popUpMessageParser = this.browserMessageHandler;
|
|
43
46
|
this._urlParams = new Map();
|
|
44
47
|
this.urlParams.set('display', 'popup');
|
|
45
48
|
}
|
|
@@ -52,20 +55,27 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
52
55
|
return this.promise.promise;
|
|
53
56
|
}
|
|
54
57
|
this.promise = common_1.PromiseHandler.create();
|
|
55
|
-
this.popUp = this.
|
|
58
|
+
this.popUp = this.popupOpen();
|
|
59
|
+
this.popUpFocus();
|
|
60
|
+
if (this.popUpIsCheckClose) {
|
|
61
|
+
this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, common_1.DateUtil.MILLISECONDS_SECOND / 10);
|
|
62
|
+
}
|
|
56
63
|
this.window.addEventListener('message', this.messageHandler, false);
|
|
57
|
-
this.timer = setInterval(this.checkPopUp, common_1.DateUtil.MILLISECONDS_SECOND / 10);
|
|
58
64
|
return this.promise.promise;
|
|
59
65
|
});
|
|
60
66
|
}
|
|
61
|
-
|
|
67
|
+
popupOpen() {
|
|
62
68
|
let window = this.window;
|
|
63
69
|
let top = (window.screen.height - this.popUpHeight) / 2;
|
|
64
70
|
let left = (window.screen.width - this.popUpWidth) / 2;
|
|
65
|
-
let item = window.open(this.getUrl(),
|
|
66
|
-
item.focus();
|
|
71
|
+
let item = window.open(this.getUrl(), this.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
67
72
|
return item;
|
|
68
73
|
}
|
|
74
|
+
popUpFocus() {
|
|
75
|
+
if (!_.isNil(this.popUp) && !this.popUp.closed) {
|
|
76
|
+
this.popUp.focus();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
69
79
|
getUrlParams() {
|
|
70
80
|
let item = new URLSearchParams();
|
|
71
81
|
item.append('client_id', this.applicationId);
|
|
@@ -74,6 +84,9 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
74
84
|
this.urlParams.forEach((value, key) => item.append(key, value));
|
|
75
85
|
return item;
|
|
76
86
|
}
|
|
87
|
+
browserMessageHandler(event) {
|
|
88
|
+
return event.origin === this.getOriginUrl() && _.isObject(event.data) ? event.data : null;
|
|
89
|
+
}
|
|
77
90
|
getOriginUrl() {
|
|
78
91
|
return this.window.location.origin;
|
|
79
92
|
}
|
|
@@ -94,8 +107,7 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
94
107
|
}
|
|
95
108
|
close() {
|
|
96
109
|
this.window.removeEventListener('message', this.messageHandler, false);
|
|
97
|
-
|
|
98
|
-
this.timer = null;
|
|
110
|
+
this.popUpCheckCloseTimer = null;
|
|
99
111
|
if (!_.isNil(this.popUp)) {
|
|
100
112
|
this.popUp.close();
|
|
101
113
|
this.popUp = null;
|
|
@@ -120,6 +132,16 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
120
132
|
this.http = null;
|
|
121
133
|
}
|
|
122
134
|
}
|
|
135
|
+
get popUpCheckCloseTimer() {
|
|
136
|
+
return this._popUpCheckCloseTimer;
|
|
137
|
+
}
|
|
138
|
+
set popUpCheckCloseTimer(value) {
|
|
139
|
+
if (value === this._popUpCheckCloseTimer) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
clearInterval(this._popUpCheckCloseTimer);
|
|
143
|
+
this._popUpCheckCloseTimer = value;
|
|
144
|
+
}
|
|
123
145
|
get urlParams() {
|
|
124
146
|
return this._urlParams;
|
|
125
147
|
}
|
package/esm/OAuthBase.d.ts
CHANGED
|
@@ -3,22 +3,27 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
3
3
|
protected applicationId: string;
|
|
4
4
|
protected window?: Window;
|
|
5
5
|
static ERROR_WINDOW_CLOSED: string;
|
|
6
|
+
popUpWidth: number;
|
|
7
|
+
popUpHeight: number;
|
|
8
|
+
popUpTarget: string;
|
|
9
|
+
popUpIsCheckClose: boolean;
|
|
10
|
+
popUpMessageParser: IOAuthPopUpMessageParser;
|
|
6
11
|
redirectUri: string;
|
|
7
12
|
protected http: TransportHttp;
|
|
8
|
-
protected timer: any;
|
|
9
13
|
protected popUp: Window;
|
|
10
14
|
protected promise: PromiseHandler<IOAuthDto>;
|
|
11
|
-
protected popUpWidth: number;
|
|
12
|
-
protected popUpHeight: number;
|
|
13
15
|
protected responseType: string;
|
|
14
16
|
protected _urlParams: Map<string, string>;
|
|
17
|
+
protected _popUpCheckCloseTimer: any;
|
|
15
18
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
16
19
|
protected open(): Promise<IOAuthDto>;
|
|
17
|
-
protected
|
|
18
|
-
protected
|
|
20
|
+
protected popupOpen(): Window;
|
|
21
|
+
protected popUpFocus(): void;
|
|
22
|
+
protected popUpCheckClose: () => void;
|
|
19
23
|
protected getUrlParams(): URLSearchParams;
|
|
20
24
|
protected abstract getUrl(): string;
|
|
21
|
-
messageHandler: (event: MessageEvent
|
|
25
|
+
protected messageHandler: (event: MessageEvent) => void;
|
|
26
|
+
protected browserMessageHandler(event: MessageEvent<IOAuthPopUpDto>): IOAuthPopUpDto;
|
|
22
27
|
protected getOriginUrl(): string;
|
|
23
28
|
protected getRedirectUri(): string;
|
|
24
29
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
@@ -27,6 +32,8 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
27
32
|
getToken(): Promise<IOAuthDto>;
|
|
28
33
|
close(): void;
|
|
29
34
|
destroy(): void;
|
|
35
|
+
protected get popUpCheckCloseTimer(): any;
|
|
36
|
+
protected set popUpCheckCloseTimer(value: any);
|
|
30
37
|
get urlParams(): Map<string, string>;
|
|
31
38
|
}
|
|
32
39
|
export interface IOAuthDto {
|
|
@@ -47,3 +54,4 @@ export interface IOAuthToken {
|
|
|
47
54
|
expiresIn: number;
|
|
48
55
|
accessToken: string;
|
|
49
56
|
}
|
|
57
|
+
export type IOAuthPopUpMessageParser = (event: MessageEvent) => IOAuthPopUpDto;
|
package/esm/OAuthBase.js
CHANGED
|
@@ -14,16 +14,14 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
14
14
|
super(logger);
|
|
15
15
|
this.applicationId = applicationId;
|
|
16
16
|
this.window = window;
|
|
17
|
-
this.
|
|
18
|
-
this.popUpHeight = 520;
|
|
19
|
-
this.checkPopUp = () => {
|
|
17
|
+
this.popUpCheckClose = () => {
|
|
20
18
|
if (_.isNil(this.popUp) || this.popUp.closed) {
|
|
21
19
|
this.close();
|
|
22
20
|
}
|
|
23
21
|
};
|
|
24
22
|
this.messageHandler = (event) => {
|
|
25
|
-
let data = event
|
|
26
|
-
if (
|
|
23
|
+
let data = this.popUpMessageParser(event);
|
|
24
|
+
if (_.isNil(data)) {
|
|
27
25
|
return;
|
|
28
26
|
}
|
|
29
27
|
if (!_.isEmpty(data.oAuthCodeOrToken)) {
|
|
@@ -37,6 +35,11 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
37
35
|
}
|
|
38
36
|
};
|
|
39
37
|
this.http = new TransportHttp(logger, { method: 'get' });
|
|
38
|
+
this.popUpWidth = 430;
|
|
39
|
+
this.popUpHeight = 520;
|
|
40
|
+
this.popUpTarget = '_blank';
|
|
41
|
+
this.popUpIsCheckClose = true;
|
|
42
|
+
this.popUpMessageParser = this.browserMessageHandler;
|
|
40
43
|
this._urlParams = new Map();
|
|
41
44
|
this.urlParams.set('display', 'popup');
|
|
42
45
|
}
|
|
@@ -49,20 +52,27 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
49
52
|
return this.promise.promise;
|
|
50
53
|
}
|
|
51
54
|
this.promise = PromiseHandler.create();
|
|
52
|
-
this.popUp = this.
|
|
55
|
+
this.popUp = this.popupOpen();
|
|
56
|
+
this.popUpFocus();
|
|
57
|
+
if (this.popUpIsCheckClose) {
|
|
58
|
+
this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, DateUtil.MILLISECONDS_SECOND / 10);
|
|
59
|
+
}
|
|
53
60
|
this.window.addEventListener('message', this.messageHandler, false);
|
|
54
|
-
this.timer = setInterval(this.checkPopUp, DateUtil.MILLISECONDS_SECOND / 10);
|
|
55
61
|
return this.promise.promise;
|
|
56
62
|
});
|
|
57
63
|
}
|
|
58
|
-
|
|
64
|
+
popupOpen() {
|
|
59
65
|
let window = this.window;
|
|
60
66
|
let top = (window.screen.height - this.popUpHeight) / 2;
|
|
61
67
|
let left = (window.screen.width - this.popUpWidth) / 2;
|
|
62
|
-
let item = window.open(this.getUrl(),
|
|
63
|
-
item.focus();
|
|
68
|
+
let item = window.open(this.getUrl(), this.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
64
69
|
return item;
|
|
65
70
|
}
|
|
71
|
+
popUpFocus() {
|
|
72
|
+
if (!_.isNil(this.popUp) && !this.popUp.closed) {
|
|
73
|
+
this.popUp.focus();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
66
76
|
getUrlParams() {
|
|
67
77
|
let item = new URLSearchParams();
|
|
68
78
|
item.append('client_id', this.applicationId);
|
|
@@ -71,6 +81,9 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
71
81
|
this.urlParams.forEach((value, key) => item.append(key, value));
|
|
72
82
|
return item;
|
|
73
83
|
}
|
|
84
|
+
browserMessageHandler(event) {
|
|
85
|
+
return event.origin === this.getOriginUrl() && _.isObject(event.data) ? event.data : null;
|
|
86
|
+
}
|
|
74
87
|
getOriginUrl() {
|
|
75
88
|
return this.window.location.origin;
|
|
76
89
|
}
|
|
@@ -91,8 +104,7 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
91
104
|
}
|
|
92
105
|
close() {
|
|
93
106
|
this.window.removeEventListener('message', this.messageHandler, false);
|
|
94
|
-
|
|
95
|
-
this.timer = null;
|
|
107
|
+
this.popUpCheckCloseTimer = null;
|
|
96
108
|
if (!_.isNil(this.popUp)) {
|
|
97
109
|
this.popUp.close();
|
|
98
110
|
this.popUp = null;
|
|
@@ -117,6 +129,16 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
117
129
|
this.http = null;
|
|
118
130
|
}
|
|
119
131
|
}
|
|
132
|
+
get popUpCheckCloseTimer() {
|
|
133
|
+
return this._popUpCheckCloseTimer;
|
|
134
|
+
}
|
|
135
|
+
set popUpCheckCloseTimer(value) {
|
|
136
|
+
if (value === this._popUpCheckCloseTimer) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
clearInterval(this._popUpCheckCloseTimer);
|
|
140
|
+
this._popUpCheckCloseTimer = value;
|
|
141
|
+
}
|
|
120
142
|
get urlParams() {
|
|
121
143
|
return this._urlParams;
|
|
122
144
|
}
|