@ts-core/oauth 3.0.16 → 3.0.18
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 +3 -1
- package/cjs/OAuthBase.js +21 -17
- package/cjs/OAuthParser.d.ts +1 -1
- package/cjs/OAuthParser.js +3 -1
- 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 +3 -1
- package/esm/OAuthBase.js +22 -18
- package/esm/OAuthParser.d.ts +1 -1
- package/esm/OAuthParser.js +3 -1
- 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
|
@@ -17,7 +17,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
17
17
|
protected _popUpCheckCloseTimer: any;
|
|
18
18
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
19
19
|
protected open(): Promise<IOAuthDto>;
|
|
20
|
-
protected
|
|
20
|
+
protected popUpOpen(): Window;
|
|
21
21
|
protected popUpFocus(): void;
|
|
22
22
|
protected popUpCheckClose: () => void;
|
|
23
23
|
protected getUrlParams(): URLSearchParams;
|
|
@@ -28,6 +28,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
28
28
|
protected getRedirectUri(): string;
|
|
29
29
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
30
30
|
abstract getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
31
|
+
parsePopUpResult(data: IOAuthPopUpDto): void;
|
|
31
32
|
getCode(): Promise<IOAuthDto>;
|
|
32
33
|
getToken(): Promise<IOAuthDto>;
|
|
33
34
|
close(): void;
|
|
@@ -35,6 +36,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
35
36
|
protected get popUpCheckCloseTimer(): any;
|
|
36
37
|
protected set popUpCheckCloseTimer(value: any);
|
|
37
38
|
get urlParams(): Map<string, string>;
|
|
39
|
+
get state(): string;
|
|
38
40
|
}
|
|
39
41
|
export interface IOAuthDto {
|
|
40
42
|
codeOrToken: string;
|
package/cjs/OAuthBase.js
CHANGED
|
@@ -22,21 +22,7 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
22
22
|
this.close();
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
this.messageHandler = (event) =>
|
|
26
|
-
let data = this.popUpMessageParser(event);
|
|
27
|
-
if (_.isNil(data)) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (!_.isEmpty(data.oAuthCodeOrToken)) {
|
|
31
|
-
this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
|
|
32
|
-
}
|
|
33
|
-
if (!_.isEmpty(data.oAuthError)) {
|
|
34
|
-
this.promise.reject(data.oAuthError);
|
|
35
|
-
}
|
|
36
|
-
if (!this.promise.isPending) {
|
|
37
|
-
this.close();
|
|
38
|
-
}
|
|
39
|
-
};
|
|
25
|
+
this.messageHandler = (event) => this.parsePopUpResult(this.popUpMessageParser(event));
|
|
40
26
|
this.http = new common_1.TransportHttp(logger, { method: 'get' });
|
|
41
27
|
this.popUpWidth = 430;
|
|
42
28
|
this.popUpHeight = 520;
|
|
@@ -44,6 +30,7 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
44
30
|
this.popUpIsCheckClose = true;
|
|
45
31
|
this.popUpMessageParser = this.browserMessageHandler;
|
|
46
32
|
this._urlParams = new Map();
|
|
33
|
+
this.urlParams.set('state', common_1.RandomUtil.randomString());
|
|
47
34
|
this.urlParams.set('display', 'popup');
|
|
48
35
|
}
|
|
49
36
|
open() {
|
|
@@ -55,7 +42,7 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
55
42
|
return this.promise.promise;
|
|
56
43
|
}
|
|
57
44
|
this.promise = common_1.PromiseHandler.create();
|
|
58
|
-
this.popUp = this.
|
|
45
|
+
this.popUp = this.popUpOpen();
|
|
59
46
|
this.popUpFocus();
|
|
60
47
|
if (this.popUpIsCheckClose) {
|
|
61
48
|
this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, common_1.DateUtil.MILLISECONDS_SECOND / 10);
|
|
@@ -64,7 +51,7 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
64
51
|
return this.promise.promise;
|
|
65
52
|
});
|
|
66
53
|
}
|
|
67
|
-
|
|
54
|
+
popUpOpen() {
|
|
68
55
|
let window = this.window;
|
|
69
56
|
let top = (window.screen.height - this.popUpHeight) / 2;
|
|
70
57
|
let left = (window.screen.width - this.popUpWidth) / 2;
|
|
@@ -93,6 +80,20 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
93
80
|
getRedirectUri() {
|
|
94
81
|
return !_.isNil(this.redirectUri) ? this.redirectUri : `${this.getOriginUrl()}/oauth`;
|
|
95
82
|
}
|
|
83
|
+
parsePopUpResult(data) {
|
|
84
|
+
if (_.isNil(data)) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!_.isEmpty(data.oAuthCodeOrToken)) {
|
|
88
|
+
this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
|
|
89
|
+
}
|
|
90
|
+
if (!_.isEmpty(data.oAuthError)) {
|
|
91
|
+
this.promise.reject(data.oAuthError);
|
|
92
|
+
}
|
|
93
|
+
if (!this.promise.isPending) {
|
|
94
|
+
this.close();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
96
97
|
getCode() {
|
|
97
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
99
|
this.responseType = 'code';
|
|
@@ -145,6 +146,9 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
145
146
|
get urlParams() {
|
|
146
147
|
return this._urlParams;
|
|
147
148
|
}
|
|
149
|
+
get state() {
|
|
150
|
+
return !_.isNil(this.urlParams) ? this.urlParams.get('state') : null;
|
|
151
|
+
}
|
|
148
152
|
}
|
|
149
153
|
exports.OAuthBase = OAuthBase;
|
|
150
154
|
OAuthBase.ERROR_WINDOW_CLOSED = 'WINDOW_CLOSED';
|
package/cjs/OAuthParser.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import { IOAuthPopUpDto } from './OAuthBase';
|
|
|
2
2
|
export declare class OAuthParser {
|
|
3
3
|
static NAMES: Array<string>;
|
|
4
4
|
static ERRORS: Array<string>;
|
|
5
|
-
static parse(params: any, fragment
|
|
5
|
+
static parse(params: any, fragment?: string): IOAuthPopUpDto;
|
|
6
6
|
}
|
package/cjs/OAuthParser.js
CHANGED
|
@@ -6,7 +6,9 @@ class OAuthParser {
|
|
|
6
6
|
static parse(params, fragment) {
|
|
7
7
|
let item = new Object();
|
|
8
8
|
_.forIn(params, (value, key) => item[key] = value);
|
|
9
|
-
|
|
9
|
+
if (!_.isEmpty(fragment)) {
|
|
10
|
+
new URLSearchParams(fragment).forEach((value, key) => item[key] = value);
|
|
11
|
+
}
|
|
10
12
|
let oAuthError = null;
|
|
11
13
|
let oAuthCodeOrToken = null;
|
|
12
14
|
for (let key in item) {
|
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
|
@@ -17,7 +17,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
17
17
|
protected _popUpCheckCloseTimer: any;
|
|
18
18
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
19
19
|
protected open(): Promise<IOAuthDto>;
|
|
20
|
-
protected
|
|
20
|
+
protected popUpOpen(): Window;
|
|
21
21
|
protected popUpFocus(): void;
|
|
22
22
|
protected popUpCheckClose: () => void;
|
|
23
23
|
protected getUrlParams(): URLSearchParams;
|
|
@@ -28,6 +28,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
28
28
|
protected getRedirectUri(): string;
|
|
29
29
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
30
30
|
abstract getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
31
|
+
parsePopUpResult(data: IOAuthPopUpDto): void;
|
|
31
32
|
getCode(): Promise<IOAuthDto>;
|
|
32
33
|
getToken(): Promise<IOAuthDto>;
|
|
33
34
|
close(): void;
|
|
@@ -35,6 +36,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
35
36
|
protected get popUpCheckCloseTimer(): any;
|
|
36
37
|
protected set popUpCheckCloseTimer(value: any);
|
|
37
38
|
get urlParams(): Map<string, string>;
|
|
39
|
+
get state(): string;
|
|
38
40
|
}
|
|
39
41
|
export interface IOAuthDto {
|
|
40
42
|
codeOrToken: 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, LoggerWrapper, TransportHttp } from "@ts-core/common";
|
|
10
|
+
import { PromiseHandler, DateUtil, LoggerWrapper, TransportHttp, RandomUtil } from "@ts-core/common";
|
|
11
11
|
import * as _ from 'lodash';
|
|
12
12
|
export class OAuthBase extends LoggerWrapper {
|
|
13
13
|
constructor(logger, applicationId, window) {
|
|
@@ -19,21 +19,7 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
19
19
|
this.close();
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
this.messageHandler = (event) =>
|
|
23
|
-
let data = this.popUpMessageParser(event);
|
|
24
|
-
if (_.isNil(data)) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (!_.isEmpty(data.oAuthCodeOrToken)) {
|
|
28
|
-
this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
|
|
29
|
-
}
|
|
30
|
-
if (!_.isEmpty(data.oAuthError)) {
|
|
31
|
-
this.promise.reject(data.oAuthError);
|
|
32
|
-
}
|
|
33
|
-
if (!this.promise.isPending) {
|
|
34
|
-
this.close();
|
|
35
|
-
}
|
|
36
|
-
};
|
|
22
|
+
this.messageHandler = (event) => this.parsePopUpResult(this.popUpMessageParser(event));
|
|
37
23
|
this.http = new TransportHttp(logger, { method: 'get' });
|
|
38
24
|
this.popUpWidth = 430;
|
|
39
25
|
this.popUpHeight = 520;
|
|
@@ -41,6 +27,7 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
41
27
|
this.popUpIsCheckClose = true;
|
|
42
28
|
this.popUpMessageParser = this.browserMessageHandler;
|
|
43
29
|
this._urlParams = new Map();
|
|
30
|
+
this.urlParams.set('state', RandomUtil.randomString());
|
|
44
31
|
this.urlParams.set('display', 'popup');
|
|
45
32
|
}
|
|
46
33
|
open() {
|
|
@@ -52,7 +39,7 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
52
39
|
return this.promise.promise;
|
|
53
40
|
}
|
|
54
41
|
this.promise = PromiseHandler.create();
|
|
55
|
-
this.popUp = this.
|
|
42
|
+
this.popUp = this.popUpOpen();
|
|
56
43
|
this.popUpFocus();
|
|
57
44
|
if (this.popUpIsCheckClose) {
|
|
58
45
|
this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, DateUtil.MILLISECONDS_SECOND / 10);
|
|
@@ -61,7 +48,7 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
61
48
|
return this.promise.promise;
|
|
62
49
|
});
|
|
63
50
|
}
|
|
64
|
-
|
|
51
|
+
popUpOpen() {
|
|
65
52
|
let window = this.window;
|
|
66
53
|
let top = (window.screen.height - this.popUpHeight) / 2;
|
|
67
54
|
let left = (window.screen.width - this.popUpWidth) / 2;
|
|
@@ -90,6 +77,20 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
90
77
|
getRedirectUri() {
|
|
91
78
|
return !_.isNil(this.redirectUri) ? this.redirectUri : `${this.getOriginUrl()}/oauth`;
|
|
92
79
|
}
|
|
80
|
+
parsePopUpResult(data) {
|
|
81
|
+
if (_.isNil(data)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (!_.isEmpty(data.oAuthCodeOrToken)) {
|
|
85
|
+
this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
|
|
86
|
+
}
|
|
87
|
+
if (!_.isEmpty(data.oAuthError)) {
|
|
88
|
+
this.promise.reject(data.oAuthError);
|
|
89
|
+
}
|
|
90
|
+
if (!this.promise.isPending) {
|
|
91
|
+
this.close();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
93
94
|
getCode() {
|
|
94
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
96
|
this.responseType = 'code';
|
|
@@ -142,5 +143,8 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
142
143
|
get urlParams() {
|
|
143
144
|
return this._urlParams;
|
|
144
145
|
}
|
|
146
|
+
get state() {
|
|
147
|
+
return !_.isNil(this.urlParams) ? this.urlParams.get('state') : null;
|
|
148
|
+
}
|
|
145
149
|
}
|
|
146
150
|
OAuthBase.ERROR_WINDOW_CLOSED = 'WINDOW_CLOSED';
|
package/esm/OAuthParser.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import { IOAuthPopUpDto } from './OAuthBase';
|
|
|
2
2
|
export declare class OAuthParser {
|
|
3
3
|
static NAMES: Array<string>;
|
|
4
4
|
static ERRORS: Array<string>;
|
|
5
|
-
static parse(params: any, fragment
|
|
5
|
+
static parse(params: any, fragment?: string): IOAuthPopUpDto;
|
|
6
6
|
}
|
package/esm/OAuthParser.js
CHANGED
|
@@ -3,7 +3,9 @@ export class OAuthParser {
|
|
|
3
3
|
static parse(params, fragment) {
|
|
4
4
|
let item = new Object();
|
|
5
5
|
_.forIn(params, (value, key) => item[key] = value);
|
|
6
|
-
|
|
6
|
+
if (!_.isEmpty(fragment)) {
|
|
7
|
+
new URLSearchParams(fragment).forEach((value, key) => item[key] = value);
|
|
8
|
+
}
|
|
7
9
|
let oAuthError = null;
|
|
8
10
|
let oAuthCodeOrToken = null;
|
|
9
11
|
for (let key in item) {
|
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
|
}
|