@ts-core/oauth 3.0.12 → 3.0.14
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 +5 -3
- package/cjs/OAuthBase.js +10 -9
- package/esm/OAuthBase.d.ts +5 -3
- package/esm/OAuthBase.js +10 -9
- package/package.json +1 -1
package/cjs/OAuthBase.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { PromiseHandler, LoggerWrapper, ILogger, TransportHttp } from "@ts-core/
|
|
|
2
2
|
export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
3
3
|
protected applicationId: string;
|
|
4
4
|
protected window?: Window;
|
|
5
|
+
static ERROR_WINDOW_CLOSED: string;
|
|
6
|
+
redirectUri: string;
|
|
5
7
|
protected http: TransportHttp;
|
|
6
8
|
protected timer: any;
|
|
7
9
|
protected popUp: Window;
|
|
@@ -16,9 +18,9 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
16
18
|
protected checkPopUp: () => void;
|
|
17
19
|
protected getUrlParams(): URLSearchParams;
|
|
18
20
|
protected abstract getUrl(): string;
|
|
19
|
-
|
|
20
|
-
protected
|
|
21
|
-
protected
|
|
21
|
+
messageHandler: (event: MessageEvent<IOAuthPopUpDto>) => void;
|
|
22
|
+
protected getOriginUrl(): string;
|
|
23
|
+
protected getRedirectUri(): string;
|
|
22
24
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
23
25
|
abstract getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
24
26
|
getCode(): Promise<IOAuthDto>;
|
package/cjs/OAuthBase.js
CHANGED
|
@@ -26,11 +26,11 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
26
26
|
};
|
|
27
27
|
this.messageHandler = (event) => {
|
|
28
28
|
let data = event.data;
|
|
29
|
-
if (event.origin !== this.
|
|
29
|
+
if (event.origin !== this.getOriginUrl() || !_.isObject(data)) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
if (!_.isEmpty(data.oAuthCodeOrToken)) {
|
|
33
|
-
this.promise.resolve({ redirectUri: this.
|
|
33
|
+
this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
|
|
34
34
|
}
|
|
35
35
|
if (!_.isEmpty(data.oAuthError)) {
|
|
36
36
|
this.promise.reject(data.oAuthError);
|
|
@@ -54,7 +54,7 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
54
54
|
this.promise = common_1.PromiseHandler.create();
|
|
55
55
|
this.popUp = this.openPopup();
|
|
56
56
|
this.window.addEventListener('message', this.messageHandler, false);
|
|
57
|
-
this.timer = setInterval(this.checkPopUp, common_1.DateUtil.
|
|
57
|
+
this.timer = setInterval(this.checkPopUp, common_1.DateUtil.MILLISECONDS_SECOND / 10);
|
|
58
58
|
return this.promise.promise;
|
|
59
59
|
});
|
|
60
60
|
}
|
|
@@ -69,17 +69,17 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
69
69
|
getUrlParams() {
|
|
70
70
|
let item = new URLSearchParams();
|
|
71
71
|
item.append('client_id', this.applicationId);
|
|
72
|
-
item.append('redirect_uri', this.
|
|
72
|
+
item.append('redirect_uri', this.getRedirectUri());
|
|
73
73
|
item.append('response_type', this.responseType);
|
|
74
74
|
this.urlParams.forEach((value, key) => item.append(key, value));
|
|
75
75
|
return item;
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
return `${this.originUrl}/oauth`;
|
|
79
|
-
}
|
|
80
|
-
get originUrl() {
|
|
77
|
+
getOriginUrl() {
|
|
81
78
|
return this.window.location.origin;
|
|
82
79
|
}
|
|
80
|
+
getRedirectUri() {
|
|
81
|
+
return !_.isNil(this.redirectUri) ? this.redirectUri : `${this.getOriginUrl()}/oauth`;
|
|
82
|
+
}
|
|
83
83
|
getCode() {
|
|
84
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
85
|
this.responseType = 'code';
|
|
@@ -101,7 +101,7 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
101
101
|
this.popUp = null;
|
|
102
102
|
}
|
|
103
103
|
if (!_.isNil(this.promise)) {
|
|
104
|
-
this.promise.reject();
|
|
104
|
+
this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
|
|
105
105
|
this.promise = null;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -125,3 +125,4 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
exports.OAuthBase = OAuthBase;
|
|
128
|
+
OAuthBase.ERROR_WINDOW_CLOSED = 'WINDOW_CLOSED';
|
package/esm/OAuthBase.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { PromiseHandler, LoggerWrapper, ILogger, TransportHttp } from "@ts-core/
|
|
|
2
2
|
export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
3
3
|
protected applicationId: string;
|
|
4
4
|
protected window?: Window;
|
|
5
|
+
static ERROR_WINDOW_CLOSED: string;
|
|
6
|
+
redirectUri: string;
|
|
5
7
|
protected http: TransportHttp;
|
|
6
8
|
protected timer: any;
|
|
7
9
|
protected popUp: Window;
|
|
@@ -16,9 +18,9 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
16
18
|
protected checkPopUp: () => void;
|
|
17
19
|
protected getUrlParams(): URLSearchParams;
|
|
18
20
|
protected abstract getUrl(): string;
|
|
19
|
-
|
|
20
|
-
protected
|
|
21
|
-
protected
|
|
21
|
+
messageHandler: (event: MessageEvent<IOAuthPopUpDto>) => void;
|
|
22
|
+
protected getOriginUrl(): string;
|
|
23
|
+
protected getRedirectUri(): string;
|
|
22
24
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
23
25
|
abstract getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
24
26
|
getCode(): Promise<IOAuthDto>;
|
package/esm/OAuthBase.js
CHANGED
|
@@ -23,11 +23,11 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
23
23
|
};
|
|
24
24
|
this.messageHandler = (event) => {
|
|
25
25
|
let data = event.data;
|
|
26
|
-
if (event.origin !== this.
|
|
26
|
+
if (event.origin !== this.getOriginUrl() || !_.isObject(data)) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
if (!_.isEmpty(data.oAuthCodeOrToken)) {
|
|
30
|
-
this.promise.resolve({ redirectUri: this.
|
|
30
|
+
this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
|
|
31
31
|
}
|
|
32
32
|
if (!_.isEmpty(data.oAuthError)) {
|
|
33
33
|
this.promise.reject(data.oAuthError);
|
|
@@ -51,7 +51,7 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
51
51
|
this.promise = PromiseHandler.create();
|
|
52
52
|
this.popUp = this.openPopup();
|
|
53
53
|
this.window.addEventListener('message', this.messageHandler, false);
|
|
54
|
-
this.timer = setInterval(this.checkPopUp, DateUtil.
|
|
54
|
+
this.timer = setInterval(this.checkPopUp, DateUtil.MILLISECONDS_SECOND / 10);
|
|
55
55
|
return this.promise.promise;
|
|
56
56
|
});
|
|
57
57
|
}
|
|
@@ -66,17 +66,17 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
66
66
|
getUrlParams() {
|
|
67
67
|
let item = new URLSearchParams();
|
|
68
68
|
item.append('client_id', this.applicationId);
|
|
69
|
-
item.append('redirect_uri', this.
|
|
69
|
+
item.append('redirect_uri', this.getRedirectUri());
|
|
70
70
|
item.append('response_type', this.responseType);
|
|
71
71
|
this.urlParams.forEach((value, key) => item.append(key, value));
|
|
72
72
|
return item;
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
return `${this.originUrl}/oauth`;
|
|
76
|
-
}
|
|
77
|
-
get originUrl() {
|
|
74
|
+
getOriginUrl() {
|
|
78
75
|
return this.window.location.origin;
|
|
79
76
|
}
|
|
77
|
+
getRedirectUri() {
|
|
78
|
+
return !_.isNil(this.redirectUri) ? this.redirectUri : `${this.getOriginUrl()}/oauth`;
|
|
79
|
+
}
|
|
80
80
|
getCode() {
|
|
81
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
82
|
this.responseType = 'code';
|
|
@@ -98,7 +98,7 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
98
98
|
this.popUp = null;
|
|
99
99
|
}
|
|
100
100
|
if (!_.isNil(this.promise)) {
|
|
101
|
-
this.promise.reject();
|
|
101
|
+
this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
|
|
102
102
|
this.promise = null;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -121,3 +121,4 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
121
121
|
return this._urlParams;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
+
OAuthBase.ERROR_WINDOW_CLOSED = 'WINDOW_CLOSED';
|