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