@ts-core/oauth 3.0.3 → 3.0.4
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 +9 -5
- package/cjs/OAuthBase.js +24 -6
- package/cjs/OAuthUser.d.ts +3 -3
- package/cjs/OAuthUser.js +1 -5
- package/cjs/go/{GoOAuth.d.ts → GoAuth.d.ts} +3 -3
- package/cjs/go/{GoOAuth.js → GoAuth.js} +20 -21
- package/cjs/go/GoUser.d.ts +1 -1
- package/cjs/ma/MaAuth.d.ts +10 -0
- package/cjs/ma/MaAuth.js +64 -0
- package/cjs/ma/MaUser.d.ts +8 -0
- package/cjs/ma/MaUser.js +28 -0
- package/cjs/public-api.d.ts +3 -3
- package/cjs/public-api.js +3 -3
- package/cjs/vk/VkAuth.d.ts +8 -0
- package/cjs/vk/{VkOAuth.js → VkAuth.js} +25 -16
- package/cjs/vk/VkUser.d.ts +1 -1
- package/cjs/ya/{YaOAuth.d.ts → YaAuth.d.ts} +3 -3
- package/cjs/ya/YaAuth.js +57 -0
- package/cjs/ya/YaUser.d.ts +1 -1
- package/esm/OAuthBase.d.ts +9 -5
- package/esm/OAuthBase.js +24 -6
- package/esm/OAuthUser.d.ts +3 -3
- package/esm/OAuthUser.js +1 -5
- package/esm/go/{GoOAuth.d.ts → GoAuth.d.ts} +3 -3
- package/esm/go/{GoOAuth.js → GoAuth.js} +18 -19
- package/esm/go/GoUser.d.ts +1 -1
- package/esm/ma/MaAuth.d.ts +10 -0
- package/esm/ma/MaAuth.js +60 -0
- package/esm/ma/MaUser.d.ts +8 -0
- package/esm/ma/MaUser.js +24 -0
- package/esm/public-api.d.ts +3 -3
- package/esm/public-api.js +3 -3
- package/esm/vk/VkAuth.d.ts +8 -0
- package/esm/vk/{VkOAuth.js → VkAuth.js} +23 -14
- package/esm/vk/VkUser.d.ts +1 -1
- package/esm/ya/{YaOAuth.d.ts → YaAuth.d.ts} +3 -3
- package/esm/ya/YaAuth.js +53 -0
- package/esm/ya/YaUser.d.ts +1 -1
- package/package.json +1 -1
- package/cjs/vk/VkOAuth.d.ts +0 -7
- package/cjs/ya/YaOAuth.js +0 -57
- package/esm/vk/VkOAuth.d.ts +0 -7
- package/esm/ya/YaOAuth.js +0 -53
package/cjs/OAuthBase.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { PromiseHandler, LoggerWrapper, ILogger, TransportHttp } from "@ts-core/common";
|
|
3
|
+
import { URLSearchParams } from "url";
|
|
2
4
|
export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
3
|
-
protected window: Window;
|
|
4
5
|
protected applicationId: string;
|
|
5
|
-
protected
|
|
6
|
+
protected window?: Window;
|
|
6
7
|
protected http: TransportHttp;
|
|
7
8
|
protected timer: any;
|
|
8
9
|
protected popUp: Window;
|
|
@@ -10,12 +11,14 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
10
11
|
protected popUpWidth: number;
|
|
11
12
|
protected popUpHeight: number;
|
|
12
13
|
protected responseType: string;
|
|
13
|
-
|
|
14
|
+
protected _urlParams: Map<string, string>;
|
|
15
|
+
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
14
16
|
protected open(): Promise<IOAuthDto>;
|
|
15
|
-
protected openPopup(
|
|
17
|
+
protected openPopup(): Window;
|
|
16
18
|
protected checkPopUp: () => void;
|
|
19
|
+
protected getUrlParams(): URLSearchParams;
|
|
20
|
+
protected abstract getUrl(): string;
|
|
17
21
|
protected messageHandler: (event: MessageEvent<IOAuthPopUpDto>) => void;
|
|
18
|
-
protected abstract getAuthUrl(): string;
|
|
19
22
|
protected get redirectUri(): string;
|
|
20
23
|
protected get originUrl(): string;
|
|
21
24
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
@@ -24,6 +27,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
24
27
|
getToken(): Promise<IOAuthDto>;
|
|
25
28
|
close(): void;
|
|
26
29
|
destroy(): void;
|
|
30
|
+
get urlParams(): Map<string, string>;
|
|
27
31
|
}
|
|
28
32
|
export interface IOAuthDto {
|
|
29
33
|
codeOrToken: string;
|
package/cjs/OAuthBase.js
CHANGED
|
@@ -12,12 +12,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.OAuthBase = void 0;
|
|
13
13
|
const common_1 = require("@ts-core/common");
|
|
14
14
|
const _ = require("lodash");
|
|
15
|
+
const url_1 = require("url");
|
|
15
16
|
class OAuthBase extends common_1.LoggerWrapper {
|
|
16
|
-
constructor(logger,
|
|
17
|
+
constructor(logger, applicationId, window) {
|
|
17
18
|
super(logger);
|
|
18
|
-
this.window = window;
|
|
19
19
|
this.applicationId = applicationId;
|
|
20
|
-
this.
|
|
20
|
+
this.window = window;
|
|
21
21
|
this.popUpWidth = 640;
|
|
22
22
|
this.popUpHeight = 480;
|
|
23
23
|
this.checkPopUp = () => {
|
|
@@ -41,6 +41,8 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
this.http = new common_1.TransportHttp(logger, { method: 'get' });
|
|
44
|
+
this._urlParams = new Map();
|
|
45
|
+
this.urlParams.set('display', 'popup');
|
|
44
46
|
}
|
|
45
47
|
open() {
|
|
46
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -48,20 +50,29 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
48
50
|
return this.promise.promise;
|
|
49
51
|
}
|
|
50
52
|
this.promise = common_1.PromiseHandler.create();
|
|
51
|
-
this.popUp = this.openPopup(
|
|
53
|
+
this.popUp = this.openPopup();
|
|
52
54
|
this.window.addEventListener('message', this.messageHandler, false);
|
|
53
55
|
this.timer = setInterval(this.checkPopUp, common_1.DateUtil.MILLISECONDS_NANOSECOND / 2);
|
|
54
56
|
return this.promise.promise;
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
|
-
openPopup(
|
|
59
|
+
openPopup() {
|
|
58
60
|
let window = this.window;
|
|
59
61
|
let top = (window.screen.height - this.popUpHeight) / 2;
|
|
60
62
|
let left = (window.screen.width - this.popUpWidth) / 2;
|
|
61
|
-
let item = window.open(
|
|
63
|
+
let item = window.open(this.getUrl(), '_blank', `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
62
64
|
item.focus();
|
|
63
65
|
return item;
|
|
64
66
|
}
|
|
67
|
+
getUrlParams() {
|
|
68
|
+
let item = new url_1.URLSearchParams();
|
|
69
|
+
item.append('display', 'popup');
|
|
70
|
+
item.append('client_id', this.applicationId);
|
|
71
|
+
item.append('redirect_uri', this.redirectUri);
|
|
72
|
+
item.append('response_type', this.responseType);
|
|
73
|
+
this.urlParams.forEach((value, key) => item.append(key, value));
|
|
74
|
+
return item;
|
|
75
|
+
}
|
|
65
76
|
get redirectUri() {
|
|
66
77
|
return `${this.originUrl}/oauth`;
|
|
67
78
|
}
|
|
@@ -99,10 +110,17 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
99
110
|
}
|
|
100
111
|
super.destroy();
|
|
101
112
|
this.close();
|
|
113
|
+
if (!_.isNil(this.urlParams)) {
|
|
114
|
+
this.urlParams.clear();
|
|
115
|
+
this._urlParams = null;
|
|
116
|
+
}
|
|
102
117
|
if (!_.isNil(this.http)) {
|
|
103
118
|
this.http.destroy();
|
|
104
119
|
this.http = null;
|
|
105
120
|
}
|
|
106
121
|
}
|
|
122
|
+
get urlParams() {
|
|
123
|
+
return this._urlParams;
|
|
124
|
+
}
|
|
107
125
|
}
|
|
108
126
|
exports.OAuthBase = OAuthBase;
|
package/cjs/OAuthUser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare abstract class OAuthUser {
|
|
2
|
-
id: string
|
|
2
|
+
id: string;
|
|
3
3
|
name: string;
|
|
4
4
|
city?: string;
|
|
5
5
|
phone?: string;
|
|
@@ -17,7 +17,7 @@ export declare abstract class OAuthUser {
|
|
|
17
17
|
telegram?: string;
|
|
18
18
|
instagram?: string;
|
|
19
19
|
birthday?: Date;
|
|
20
|
-
constructor(
|
|
21
|
-
|
|
20
|
+
constructor();
|
|
21
|
+
abstract parse(item: any): void;
|
|
22
22
|
get location(): string;
|
|
23
23
|
}
|
package/cjs/OAuthUser.js
CHANGED
|
@@ -13,11 +13,7 @@ exports.OAuthUser = void 0;
|
|
|
13
13
|
const _ = require("lodash");
|
|
14
14
|
const class_transformer_1 = require("class-transformer");
|
|
15
15
|
class OAuthUser {
|
|
16
|
-
constructor(
|
|
17
|
-
if (!_.isNil(item)) {
|
|
18
|
-
this.parse(item);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
16
|
+
constructor() { }
|
|
21
17
|
get location() {
|
|
22
18
|
let items = new Array();
|
|
23
19
|
if (!_.isEmpty(this.country)) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { GoUser } from './GoUser';
|
|
2
2
|
import { IOAuthDto, IOAuthToken, OAuthBase } from '../OAuthBase';
|
|
3
3
|
import { ILogger } from '@ts-core/common';
|
|
4
|
-
export declare class
|
|
5
|
-
constructor(logger: ILogger,
|
|
6
|
-
protected
|
|
4
|
+
export declare class GoAuth<T extends GoUser = GoUser> extends OAuthBase<T> {
|
|
5
|
+
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
6
|
+
protected getUrl(): string;
|
|
7
7
|
getProfile(token: string): Promise<T>;
|
|
8
8
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
9
9
|
}
|
|
@@ -9,45 +9,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
const _ = require("lodash");
|
|
12
|
+
exports.GoAuth = void 0;
|
|
14
13
|
const GoUser_1 = require("./GoUser");
|
|
15
14
|
const OAuthBase_1 = require("../OAuthBase");
|
|
16
|
-
class
|
|
17
|
-
constructor(logger,
|
|
18
|
-
super(logger,
|
|
15
|
+
class GoAuth extends OAuthBase_1.OAuthBase {
|
|
16
|
+
constructor(logger, applicationId, window) {
|
|
17
|
+
super(logger, applicationId, window);
|
|
18
|
+
this.urlParams.set('scope', 'https://www.googleapis.com/auth/userinfo.profile');
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
params.append('display', 'popup');
|
|
23
|
-
params.append('client_id', this.applicationId);
|
|
24
|
-
params.append('redirect_uri', this.redirectUri);
|
|
25
|
-
params.append('response_type', this.responseType);
|
|
26
|
-
if (!_.isEmpty(this.scope)) {
|
|
27
|
-
params.append('scope', this.scope);
|
|
28
|
-
}
|
|
29
|
-
return `https://accounts.google.com/o/oauth2/v2/auth?${params.toString()}`;
|
|
20
|
+
getUrl() {
|
|
21
|
+
return `https://accounts.google.com/o/oauth2/v2/auth?${this.getUrlParams().toString()}`;
|
|
30
22
|
}
|
|
31
23
|
getProfile(token) {
|
|
32
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
let item =
|
|
34
|
-
|
|
25
|
+
let item = new GoUser_1.GoUser();
|
|
26
|
+
item.parse(yield this.http.call('https://www.googleapis.com/oauth2/v3/userinfo', { headers: { 'Authorization': `Bearer ${token}` } }));
|
|
27
|
+
return item;
|
|
35
28
|
});
|
|
36
29
|
}
|
|
37
30
|
getTokenByCode(dto, secret) {
|
|
38
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
32
|
let item = yield this.http.call('https://oauth2.googleapis.com/token', {
|
|
40
|
-
method: 'post',
|
|
41
33
|
data: {
|
|
42
34
|
code: dto.codeOrToken,
|
|
43
35
|
client_id: this.applicationId,
|
|
44
36
|
client_secret: secret,
|
|
45
37
|
redirect_uri: dto.redirectUri,
|
|
46
38
|
grant_type: 'authorization_code'
|
|
47
|
-
}
|
|
39
|
+
},
|
|
40
|
+
method: 'post'
|
|
48
41
|
});
|
|
49
|
-
return {
|
|
42
|
+
return {
|
|
43
|
+
expiresIn: item.expires_in,
|
|
44
|
+
accessToken: item.access_token,
|
|
45
|
+
tokenType: item.token_type,
|
|
46
|
+
idToken: item.id_token,
|
|
47
|
+
scope: item.scope
|
|
48
|
+
};
|
|
50
49
|
});
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
|
-
exports.
|
|
52
|
+
exports.GoAuth = GoAuth;
|
package/cjs/go/GoUser.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ILogger } from "@ts-core/common";
|
|
2
|
+
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
3
|
+
import { MaUser } from "./MaUser";
|
|
4
|
+
export declare class MaAuth<T extends MaUser = MaUser> extends OAuthBase<T> {
|
|
5
|
+
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
6
|
+
protected getUrlParams(): URLSearchParams;
|
|
7
|
+
protected getUrl(): string;
|
|
8
|
+
getProfile(token: string): Promise<T>;
|
|
9
|
+
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
10
|
+
}
|
package/cjs/ma/MaAuth.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MaAuth = void 0;
|
|
13
|
+
const common_1 = require("@ts-core/common");
|
|
14
|
+
const OAuthBase_1 = require("../OAuthBase");
|
|
15
|
+
const MaUser_1 = require("./MaUser");
|
|
16
|
+
const _ = require("lodash");
|
|
17
|
+
class MaAuth extends OAuthBase_1.OAuthBase {
|
|
18
|
+
constructor(logger, applicationId, window) {
|
|
19
|
+
super(logger, applicationId, window);
|
|
20
|
+
this.popUpWidth = 480;
|
|
21
|
+
this.popUpHeight = 520;
|
|
22
|
+
this.urlParams.set('scope', 'userinfo');
|
|
23
|
+
}
|
|
24
|
+
getUrlParams() {
|
|
25
|
+
let item = super.getUrlParams();
|
|
26
|
+
item.append('state', common_1.RandomUtil.randomString(43));
|
|
27
|
+
return item;
|
|
28
|
+
}
|
|
29
|
+
getUrl() {
|
|
30
|
+
return `https://oauth.mail.ru/login?${this.getUrlParams().toString()}`;
|
|
31
|
+
}
|
|
32
|
+
getProfile(token) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
let item = new MaUser_1.MaUser();
|
|
35
|
+
item.parse(yield this.http.call('https://oauth.mail.ru/userinfo', { data: { access_token: token } }));
|
|
36
|
+
return item;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
getTokenByCode(dto, secret) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
let item = yield this.http.call('https://oauth.mail.ru/token', {
|
|
42
|
+
data: {
|
|
43
|
+
code: dto.codeOrToken,
|
|
44
|
+
client_id: this.applicationId,
|
|
45
|
+
client_secret: secret,
|
|
46
|
+
redirect_uri: dto.redirectUri,
|
|
47
|
+
grant_type: 'authorization_code'
|
|
48
|
+
},
|
|
49
|
+
method: 'post',
|
|
50
|
+
headers: { 'Content-Type': 'multipart/form-data' }
|
|
51
|
+
});
|
|
52
|
+
if (!_.isNil(item.error_description)) {
|
|
53
|
+
throw new common_1.ExtendedError(item.error_description);
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
tokenType: item.token_type,
|
|
57
|
+
expiresIn: item.expires_in,
|
|
58
|
+
accessToken: item.access_token,
|
|
59
|
+
refreshToken: item.refresh_token,
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.MaAuth = MaAuth;
|
package/cjs/ma/MaUser.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MaUser = void 0;
|
|
4
|
+
const OAuthUser_1 = require("../OAuthUser");
|
|
5
|
+
const _ = require("lodash");
|
|
6
|
+
class MaUser extends OAuthUser_1.OAuthUser {
|
|
7
|
+
parse(item) {
|
|
8
|
+
this.id = item.id;
|
|
9
|
+
this.name = item.name;
|
|
10
|
+
this.email = item.email;
|
|
11
|
+
this.locale = item.locale;
|
|
12
|
+
this.picture = item.image;
|
|
13
|
+
this.clientId = item.clientId;
|
|
14
|
+
this.nickname = item.nickname;
|
|
15
|
+
this.lastName = item.last_name;
|
|
16
|
+
this.firstName = item.first_name;
|
|
17
|
+
if (!_.isNil(item.gender)) {
|
|
18
|
+
this.isMale = item.gender === 'm';
|
|
19
|
+
}
|
|
20
|
+
if (!_.isNil(item.birthday)) {
|
|
21
|
+
let array = String(item.birthday).split('.');
|
|
22
|
+
if (array.length === 3) {
|
|
23
|
+
this.birthday = new Date(Number(array[2]), Number(array[1]) - 1, Number(array[0]));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.MaUser = MaUser;
|
package/cjs/public-api.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from './OAuthBase';
|
|
2
2
|
export * from './OAuthUser';
|
|
3
3
|
export * from './go/GoUser';
|
|
4
|
-
export * from './go/
|
|
4
|
+
export * from './go/GoAuth';
|
|
5
5
|
export * from './vk/VkUser';
|
|
6
|
-
export * from './vk/
|
|
6
|
+
export * from './vk/VkAuth';
|
|
7
7
|
export * from './ya/YaUser';
|
|
8
|
-
export * from './ya/
|
|
8
|
+
export * from './ya/YaAuth';
|
package/cjs/public-api.js
CHANGED
|
@@ -17,8 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./OAuthBase"), exports);
|
|
18
18
|
__exportStar(require("./OAuthUser"), exports);
|
|
19
19
|
__exportStar(require("./go/GoUser"), exports);
|
|
20
|
-
__exportStar(require("./go/
|
|
20
|
+
__exportStar(require("./go/GoAuth"), exports);
|
|
21
21
|
__exportStar(require("./vk/VkUser"), exports);
|
|
22
|
-
__exportStar(require("./vk/
|
|
22
|
+
__exportStar(require("./vk/VkAuth"), exports);
|
|
23
23
|
__exportStar(require("./ya/YaUser"), exports);
|
|
24
|
-
__exportStar(require("./ya/
|
|
24
|
+
__exportStar(require("./ya/YaAuth"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
2
|
+
import { VkUser } from "./VkUser";
|
|
3
|
+
export declare class VkAuth<T extends VkUser = VkUser> extends OAuthBase<T> {
|
|
4
|
+
v: string;
|
|
5
|
+
protected getUrl(): string;
|
|
6
|
+
getProfile(token: string, fields?: string): Promise<T>;
|
|
7
|
+
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
8
|
+
}
|
|
@@ -9,26 +9,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.VkAuth = void 0;
|
|
13
|
+
const common_1 = require("@ts-core/common");
|
|
13
14
|
const _ = require("lodash");
|
|
14
15
|
const OAuthBase_1 = require("../OAuthBase");
|
|
15
16
|
const VkUser_1 = require("./VkUser");
|
|
16
|
-
class
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!_.isEmpty(this.scope)) {
|
|
24
|
-
params.append('scope', this.scope);
|
|
25
|
-
}
|
|
26
|
-
return `https://oauth.vk.com/authorize?${params.toString()}`;
|
|
17
|
+
class VkAuth extends OAuthBase_1.OAuthBase {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.v = '5.131';
|
|
21
|
+
}
|
|
22
|
+
getUrl() {
|
|
23
|
+
return `https://oauth.vk.com/authorize?${this.getUrlParams().toString()}`;
|
|
27
24
|
}
|
|
28
25
|
getProfile(token, fields) {
|
|
29
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
if (_.isNil(fields)) {
|
|
28
|
+
fields = 'photo_200,bdate,sex,city,country,status,about';
|
|
29
|
+
}
|
|
30
|
+
let { response } = yield this.http.call('https://api.vk.com/method/users.get', { data: { access_token: token, v: this.v, fields } });
|
|
31
|
+
let item = new VkUser_1.VkUser();
|
|
32
|
+
item.parse(response[0]);
|
|
33
|
+
return item;
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
36
|
getTokenByCode(dto, secret) {
|
|
@@ -41,8 +43,15 @@ class VkOAuth extends OAuthBase_1.OAuthBase {
|
|
|
41
43
|
client_secret: secret,
|
|
42
44
|
}
|
|
43
45
|
});
|
|
44
|
-
|
|
46
|
+
if (!_.isNil(item.error_description)) {
|
|
47
|
+
throw new common_1.ExtendedError(item.error_description);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
expiresIn: item.expires_in,
|
|
51
|
+
accessToken: item.access_token,
|
|
52
|
+
userId: item.user_id,
|
|
53
|
+
};
|
|
45
54
|
});
|
|
46
55
|
}
|
|
47
56
|
}
|
|
48
|
-
exports.
|
|
57
|
+
exports.VkAuth = VkAuth;
|
package/cjs/vk/VkUser.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ILogger } from "@ts-core/common";
|
|
2
2
|
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
3
3
|
import { YaUser } from "./YaUser";
|
|
4
|
-
export declare class
|
|
5
|
-
constructor(logger: ILogger,
|
|
6
|
-
protected
|
|
4
|
+
export declare class YaAuth<T extends YaUser = YaUser> extends OAuthBase<T> {
|
|
5
|
+
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
6
|
+
protected getUrl(): string;
|
|
7
7
|
getProfile(token: string): Promise<T>;
|
|
8
8
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
9
9
|
}
|
package/cjs/ya/YaAuth.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.YaAuth = void 0;
|
|
13
|
+
const common_1 = require("@ts-core/common");
|
|
14
|
+
const OAuthBase_1 = require("../OAuthBase");
|
|
15
|
+
const YaUser_1 = require("./YaUser");
|
|
16
|
+
const _ = require("lodash");
|
|
17
|
+
class YaAuth extends OAuthBase_1.OAuthBase {
|
|
18
|
+
constructor(logger, applicationId, window) {
|
|
19
|
+
super(logger, applicationId, window);
|
|
20
|
+
this.popUpWidth = 480;
|
|
21
|
+
this.popUpHeight = 520;
|
|
22
|
+
}
|
|
23
|
+
getUrl() {
|
|
24
|
+
return `https://oauth.yandex.ru/authorize?${this.getUrlParams().toString()}`;
|
|
25
|
+
}
|
|
26
|
+
getProfile(token) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
let item = new YaUser_1.YaUser();
|
|
29
|
+
item.parse(yield this.http.call('https://login.yandex.ru/info', { data: { oauth_token: token } }));
|
|
30
|
+
return item;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getTokenByCode(dto, secret) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
let item = yield this.http.call('https://oauth.yandex.ru/token', {
|
|
36
|
+
data: {
|
|
37
|
+
code: dto.codeOrToken,
|
|
38
|
+
client_id: this.applicationId,
|
|
39
|
+
client_secret: secret,
|
|
40
|
+
grant_type: 'authorization_code'
|
|
41
|
+
},
|
|
42
|
+
method: 'post',
|
|
43
|
+
headers: { 'Content-Type': 'multipart/form-data' }
|
|
44
|
+
});
|
|
45
|
+
if (!_.isNil(item.error_description)) {
|
|
46
|
+
throw new common_1.ExtendedError(item.error_description);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
expiresIn: item.expires_in,
|
|
50
|
+
accessToken: item.access_token,
|
|
51
|
+
refreshToken: item.refresh_token,
|
|
52
|
+
tokenType: item.token_type,
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.YaAuth = YaAuth;
|
package/cjs/ya/YaUser.d.ts
CHANGED
package/esm/OAuthBase.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { PromiseHandler, LoggerWrapper, ILogger, TransportHttp } from "@ts-core/common";
|
|
3
|
+
import { URLSearchParams } from "url";
|
|
2
4
|
export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
3
|
-
protected window: Window;
|
|
4
5
|
protected applicationId: string;
|
|
5
|
-
protected
|
|
6
|
+
protected window?: Window;
|
|
6
7
|
protected http: TransportHttp;
|
|
7
8
|
protected timer: any;
|
|
8
9
|
protected popUp: Window;
|
|
@@ -10,12 +11,14 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
10
11
|
protected popUpWidth: number;
|
|
11
12
|
protected popUpHeight: number;
|
|
12
13
|
protected responseType: string;
|
|
13
|
-
|
|
14
|
+
protected _urlParams: Map<string, string>;
|
|
15
|
+
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
14
16
|
protected open(): Promise<IOAuthDto>;
|
|
15
|
-
protected openPopup(
|
|
17
|
+
protected openPopup(): Window;
|
|
16
18
|
protected checkPopUp: () => void;
|
|
19
|
+
protected getUrlParams(): URLSearchParams;
|
|
20
|
+
protected abstract getUrl(): string;
|
|
17
21
|
protected messageHandler: (event: MessageEvent<IOAuthPopUpDto>) => void;
|
|
18
|
-
protected abstract getAuthUrl(): string;
|
|
19
22
|
protected get redirectUri(): string;
|
|
20
23
|
protected get originUrl(): string;
|
|
21
24
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
@@ -24,6 +27,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
24
27
|
getToken(): Promise<IOAuthDto>;
|
|
25
28
|
close(): void;
|
|
26
29
|
destroy(): void;
|
|
30
|
+
get urlParams(): Map<string, string>;
|
|
27
31
|
}
|
|
28
32
|
export interface IOAuthDto {
|
|
29
33
|
codeOrToken: string;
|
package/esm/OAuthBase.js
CHANGED
|
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { PromiseHandler, DateUtil, LoggerWrapper, TransportHttp } from "@ts-core/common";
|
|
11
11
|
import * as _ from 'lodash';
|
|
12
|
+
import { URLSearchParams } from "url";
|
|
12
13
|
export class OAuthBase extends LoggerWrapper {
|
|
13
|
-
constructor(logger,
|
|
14
|
+
constructor(logger, applicationId, window) {
|
|
14
15
|
super(logger);
|
|
15
|
-
this.window = window;
|
|
16
16
|
this.applicationId = applicationId;
|
|
17
|
-
this.
|
|
17
|
+
this.window = window;
|
|
18
18
|
this.popUpWidth = 640;
|
|
19
19
|
this.popUpHeight = 480;
|
|
20
20
|
this.checkPopUp = () => {
|
|
@@ -38,6 +38,8 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
this.http = new TransportHttp(logger, { method: 'get' });
|
|
41
|
+
this._urlParams = new Map();
|
|
42
|
+
this.urlParams.set('display', 'popup');
|
|
41
43
|
}
|
|
42
44
|
open() {
|
|
43
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -45,20 +47,29 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
45
47
|
return this.promise.promise;
|
|
46
48
|
}
|
|
47
49
|
this.promise = PromiseHandler.create();
|
|
48
|
-
this.popUp = this.openPopup(
|
|
50
|
+
this.popUp = this.openPopup();
|
|
49
51
|
this.window.addEventListener('message', this.messageHandler, false);
|
|
50
52
|
this.timer = setInterval(this.checkPopUp, DateUtil.MILLISECONDS_NANOSECOND / 2);
|
|
51
53
|
return this.promise.promise;
|
|
52
54
|
});
|
|
53
55
|
}
|
|
54
|
-
openPopup(
|
|
56
|
+
openPopup() {
|
|
55
57
|
let window = this.window;
|
|
56
58
|
let top = (window.screen.height - this.popUpHeight) / 2;
|
|
57
59
|
let left = (window.screen.width - this.popUpWidth) / 2;
|
|
58
|
-
let item = window.open(
|
|
60
|
+
let item = window.open(this.getUrl(), '_blank', `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
59
61
|
item.focus();
|
|
60
62
|
return item;
|
|
61
63
|
}
|
|
64
|
+
getUrlParams() {
|
|
65
|
+
let item = new URLSearchParams();
|
|
66
|
+
item.append('display', 'popup');
|
|
67
|
+
item.append('client_id', this.applicationId);
|
|
68
|
+
item.append('redirect_uri', this.redirectUri);
|
|
69
|
+
item.append('response_type', this.responseType);
|
|
70
|
+
this.urlParams.forEach((value, key) => item.append(key, value));
|
|
71
|
+
return item;
|
|
72
|
+
}
|
|
62
73
|
get redirectUri() {
|
|
63
74
|
return `${this.originUrl}/oauth`;
|
|
64
75
|
}
|
|
@@ -96,9 +107,16 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
96
107
|
}
|
|
97
108
|
super.destroy();
|
|
98
109
|
this.close();
|
|
110
|
+
if (!_.isNil(this.urlParams)) {
|
|
111
|
+
this.urlParams.clear();
|
|
112
|
+
this._urlParams = null;
|
|
113
|
+
}
|
|
99
114
|
if (!_.isNil(this.http)) {
|
|
100
115
|
this.http.destroy();
|
|
101
116
|
this.http = null;
|
|
102
117
|
}
|
|
103
118
|
}
|
|
119
|
+
get urlParams() {
|
|
120
|
+
return this._urlParams;
|
|
121
|
+
}
|
|
104
122
|
}
|
package/esm/OAuthUser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare abstract class OAuthUser {
|
|
2
|
-
id: string
|
|
2
|
+
id: string;
|
|
3
3
|
name: string;
|
|
4
4
|
city?: string;
|
|
5
5
|
phone?: string;
|
|
@@ -17,7 +17,7 @@ export declare abstract class OAuthUser {
|
|
|
17
17
|
telegram?: string;
|
|
18
18
|
instagram?: string;
|
|
19
19
|
birthday?: Date;
|
|
20
|
-
constructor(
|
|
21
|
-
|
|
20
|
+
constructor();
|
|
21
|
+
abstract parse(item: any): void;
|
|
22
22
|
get location(): string;
|
|
23
23
|
}
|
package/esm/OAuthUser.js
CHANGED
|
@@ -10,11 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
import * as _ from 'lodash';
|
|
11
11
|
import { Type } from 'class-transformer';
|
|
12
12
|
export class OAuthUser {
|
|
13
|
-
constructor(
|
|
14
|
-
if (!_.isNil(item)) {
|
|
15
|
-
this.parse(item);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
13
|
+
constructor() { }
|
|
18
14
|
get location() {
|
|
19
15
|
let items = new Array();
|
|
20
16
|
if (!_.isEmpty(this.country)) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { GoUser } from './GoUser';
|
|
2
2
|
import { IOAuthDto, IOAuthToken, OAuthBase } from '../OAuthBase';
|
|
3
3
|
import { ILogger } from '@ts-core/common';
|
|
4
|
-
export declare class
|
|
5
|
-
constructor(logger: ILogger,
|
|
6
|
-
protected
|
|
4
|
+
export declare class GoAuth<T extends GoUser = GoUser> extends OAuthBase<T> {
|
|
5
|
+
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
6
|
+
protected getUrl(): string;
|
|
7
7
|
getProfile(token: string): Promise<T>;
|
|
8
8
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
9
9
|
}
|
|
@@ -7,43 +7,42 @@ 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 * as _ from 'lodash';
|
|
11
10
|
import { GoUser } from './GoUser';
|
|
12
11
|
import { OAuthBase } from '../OAuthBase';
|
|
13
|
-
export class
|
|
14
|
-
constructor(logger,
|
|
15
|
-
super(logger,
|
|
12
|
+
export class GoAuth extends OAuthBase {
|
|
13
|
+
constructor(logger, applicationId, window) {
|
|
14
|
+
super(logger, applicationId, window);
|
|
15
|
+
this.urlParams.set('scope', 'https://www.googleapis.com/auth/userinfo.profile');
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
params.append('display', 'popup');
|
|
20
|
-
params.append('client_id', this.applicationId);
|
|
21
|
-
params.append('redirect_uri', this.redirectUri);
|
|
22
|
-
params.append('response_type', this.responseType);
|
|
23
|
-
if (!_.isEmpty(this.scope)) {
|
|
24
|
-
params.append('scope', this.scope);
|
|
25
|
-
}
|
|
26
|
-
return `https://accounts.google.com/o/oauth2/v2/auth?${params.toString()}`;
|
|
17
|
+
getUrl() {
|
|
18
|
+
return `https://accounts.google.com/o/oauth2/v2/auth?${this.getUrlParams().toString()}`;
|
|
27
19
|
}
|
|
28
20
|
getProfile(token) {
|
|
29
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
let item =
|
|
31
|
-
|
|
22
|
+
let item = new GoUser();
|
|
23
|
+
item.parse(yield this.http.call('https://www.googleapis.com/oauth2/v3/userinfo', { headers: { 'Authorization': `Bearer ${token}` } }));
|
|
24
|
+
return item;
|
|
32
25
|
});
|
|
33
26
|
}
|
|
34
27
|
getTokenByCode(dto, secret) {
|
|
35
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
29
|
let item = yield this.http.call('https://oauth2.googleapis.com/token', {
|
|
37
|
-
method: 'post',
|
|
38
30
|
data: {
|
|
39
31
|
code: dto.codeOrToken,
|
|
40
32
|
client_id: this.applicationId,
|
|
41
33
|
client_secret: secret,
|
|
42
34
|
redirect_uri: dto.redirectUri,
|
|
43
35
|
grant_type: 'authorization_code'
|
|
44
|
-
}
|
|
36
|
+
},
|
|
37
|
+
method: 'post'
|
|
45
38
|
});
|
|
46
|
-
return {
|
|
39
|
+
return {
|
|
40
|
+
expiresIn: item.expires_in,
|
|
41
|
+
accessToken: item.access_token,
|
|
42
|
+
tokenType: item.token_type,
|
|
43
|
+
idToken: item.id_token,
|
|
44
|
+
scope: item.scope
|
|
45
|
+
};
|
|
47
46
|
});
|
|
48
47
|
}
|
|
49
48
|
}
|
package/esm/go/GoUser.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ILogger } from "@ts-core/common";
|
|
2
|
+
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
3
|
+
import { MaUser } from "./MaUser";
|
|
4
|
+
export declare class MaAuth<T extends MaUser = MaUser> extends OAuthBase<T> {
|
|
5
|
+
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
6
|
+
protected getUrlParams(): URLSearchParams;
|
|
7
|
+
protected getUrl(): string;
|
|
8
|
+
getProfile(token: string): Promise<T>;
|
|
9
|
+
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
10
|
+
}
|
package/esm/ma/MaAuth.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { ExtendedError, RandomUtil } from "@ts-core/common";
|
|
11
|
+
import { OAuthBase } from "../OAuthBase";
|
|
12
|
+
import { MaUser } from "./MaUser";
|
|
13
|
+
import * as _ from 'lodash';
|
|
14
|
+
export class MaAuth extends OAuthBase {
|
|
15
|
+
constructor(logger, applicationId, window) {
|
|
16
|
+
super(logger, applicationId, window);
|
|
17
|
+
this.popUpWidth = 480;
|
|
18
|
+
this.popUpHeight = 520;
|
|
19
|
+
this.urlParams.set('scope', 'userinfo');
|
|
20
|
+
}
|
|
21
|
+
getUrlParams() {
|
|
22
|
+
let item = super.getUrlParams();
|
|
23
|
+
item.append('state', RandomUtil.randomString(43));
|
|
24
|
+
return item;
|
|
25
|
+
}
|
|
26
|
+
getUrl() {
|
|
27
|
+
return `https://oauth.mail.ru/login?${this.getUrlParams().toString()}`;
|
|
28
|
+
}
|
|
29
|
+
getProfile(token) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
let item = new MaUser();
|
|
32
|
+
item.parse(yield this.http.call('https://oauth.mail.ru/userinfo', { data: { access_token: token } }));
|
|
33
|
+
return item;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getTokenByCode(dto, secret) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
let item = yield this.http.call('https://oauth.mail.ru/token', {
|
|
39
|
+
data: {
|
|
40
|
+
code: dto.codeOrToken,
|
|
41
|
+
client_id: this.applicationId,
|
|
42
|
+
client_secret: secret,
|
|
43
|
+
redirect_uri: dto.redirectUri,
|
|
44
|
+
grant_type: 'authorization_code'
|
|
45
|
+
},
|
|
46
|
+
method: 'post',
|
|
47
|
+
headers: { 'Content-Type': 'multipart/form-data' }
|
|
48
|
+
});
|
|
49
|
+
if (!_.isNil(item.error_description)) {
|
|
50
|
+
throw new ExtendedError(item.error_description);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
tokenType: item.token_type,
|
|
54
|
+
expiresIn: item.expires_in,
|
|
55
|
+
accessToken: item.access_token,
|
|
56
|
+
refreshToken: item.refresh_token,
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
package/esm/ma/MaUser.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { OAuthUser } from "../OAuthUser";
|
|
2
|
+
import * as _ from 'lodash';
|
|
3
|
+
export class MaUser extends OAuthUser {
|
|
4
|
+
parse(item) {
|
|
5
|
+
this.id = item.id;
|
|
6
|
+
this.name = item.name;
|
|
7
|
+
this.email = item.email;
|
|
8
|
+
this.locale = item.locale;
|
|
9
|
+
this.picture = item.image;
|
|
10
|
+
this.clientId = item.clientId;
|
|
11
|
+
this.nickname = item.nickname;
|
|
12
|
+
this.lastName = item.last_name;
|
|
13
|
+
this.firstName = item.first_name;
|
|
14
|
+
if (!_.isNil(item.gender)) {
|
|
15
|
+
this.isMale = item.gender === 'm';
|
|
16
|
+
}
|
|
17
|
+
if (!_.isNil(item.birthday)) {
|
|
18
|
+
let array = String(item.birthday).split('.');
|
|
19
|
+
if (array.length === 3) {
|
|
20
|
+
this.birthday = new Date(Number(array[2]), Number(array[1]) - 1, Number(array[0]));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/esm/public-api.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from './OAuthBase';
|
|
2
2
|
export * from './OAuthUser';
|
|
3
3
|
export * from './go/GoUser';
|
|
4
|
-
export * from './go/
|
|
4
|
+
export * from './go/GoAuth';
|
|
5
5
|
export * from './vk/VkUser';
|
|
6
|
-
export * from './vk/
|
|
6
|
+
export * from './vk/VkAuth';
|
|
7
7
|
export * from './ya/YaUser';
|
|
8
|
-
export * from './ya/
|
|
8
|
+
export * from './ya/YaAuth';
|
package/esm/public-api.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from './OAuthBase';
|
|
2
2
|
export * from './OAuthUser';
|
|
3
3
|
export * from './go/GoUser';
|
|
4
|
-
export * from './go/
|
|
4
|
+
export * from './go/GoAuth';
|
|
5
5
|
export * from './vk/VkUser';
|
|
6
|
-
export * from './vk/
|
|
6
|
+
export * from './vk/VkAuth';
|
|
7
7
|
export * from './ya/YaUser';
|
|
8
|
-
export * from './ya/
|
|
8
|
+
export * from './ya/YaAuth';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
2
|
+
import { VkUser } from "./VkUser";
|
|
3
|
+
export declare class VkAuth<T extends VkUser = VkUser> extends OAuthBase<T> {
|
|
4
|
+
v: string;
|
|
5
|
+
protected getUrl(): string;
|
|
6
|
+
getProfile(token: string, fields?: string): Promise<T>;
|
|
7
|
+
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
8
|
+
}
|
|
@@ -7,25 +7,27 @@ 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 { ExtendedError } from '@ts-core/common';
|
|
10
11
|
import * as _ from 'lodash';
|
|
11
12
|
import { OAuthBase } from "../OAuthBase";
|
|
12
13
|
import { VkUser } from "./VkUser";
|
|
13
|
-
export class
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!_.isEmpty(this.scope)) {
|
|
21
|
-
params.append('scope', this.scope);
|
|
22
|
-
}
|
|
23
|
-
return `https://oauth.vk.com/authorize?${params.toString()}`;
|
|
14
|
+
export class VkAuth extends OAuthBase {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
this.v = '5.131';
|
|
18
|
+
}
|
|
19
|
+
getUrl() {
|
|
20
|
+
return `https://oauth.vk.com/authorize?${this.getUrlParams().toString()}`;
|
|
24
21
|
}
|
|
25
22
|
getProfile(token, fields) {
|
|
26
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (_.isNil(fields)) {
|
|
25
|
+
fields = 'photo_200,bdate,sex,city,country,status,about';
|
|
26
|
+
}
|
|
27
|
+
let { response } = yield this.http.call('https://api.vk.com/method/users.get', { data: { access_token: token, v: this.v, fields } });
|
|
28
|
+
let item = new VkUser();
|
|
29
|
+
item.parse(response[0]);
|
|
30
|
+
return item;
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
33
|
getTokenByCode(dto, secret) {
|
|
@@ -38,7 +40,14 @@ export class VkOAuth extends OAuthBase {
|
|
|
38
40
|
client_secret: secret,
|
|
39
41
|
}
|
|
40
42
|
});
|
|
41
|
-
|
|
43
|
+
if (!_.isNil(item.error_description)) {
|
|
44
|
+
throw new ExtendedError(item.error_description);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
expiresIn: item.expires_in,
|
|
48
|
+
accessToken: item.access_token,
|
|
49
|
+
userId: item.user_id,
|
|
50
|
+
};
|
|
42
51
|
});
|
|
43
52
|
}
|
|
44
53
|
}
|
package/esm/vk/VkUser.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ILogger } from "@ts-core/common";
|
|
2
2
|
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
3
3
|
import { YaUser } from "./YaUser";
|
|
4
|
-
export declare class
|
|
5
|
-
constructor(logger: ILogger,
|
|
6
|
-
protected
|
|
4
|
+
export declare class YaAuth<T extends YaUser = YaUser> extends OAuthBase<T> {
|
|
5
|
+
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
6
|
+
protected getUrl(): string;
|
|
7
7
|
getProfile(token: string): Promise<T>;
|
|
8
8
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
9
9
|
}
|
package/esm/ya/YaAuth.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { ExtendedError } from "@ts-core/common";
|
|
11
|
+
import { OAuthBase } from "../OAuthBase";
|
|
12
|
+
import { YaUser } from "./YaUser";
|
|
13
|
+
import * as _ from 'lodash';
|
|
14
|
+
export class YaAuth extends OAuthBase {
|
|
15
|
+
constructor(logger, applicationId, window) {
|
|
16
|
+
super(logger, applicationId, window);
|
|
17
|
+
this.popUpWidth = 480;
|
|
18
|
+
this.popUpHeight = 520;
|
|
19
|
+
}
|
|
20
|
+
getUrl() {
|
|
21
|
+
return `https://oauth.yandex.ru/authorize?${this.getUrlParams().toString()}`;
|
|
22
|
+
}
|
|
23
|
+
getProfile(token) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
let item = new YaUser();
|
|
26
|
+
item.parse(yield this.http.call('https://login.yandex.ru/info', { data: { oauth_token: token } }));
|
|
27
|
+
return item;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
getTokenByCode(dto, secret) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
let item = yield this.http.call('https://oauth.yandex.ru/token', {
|
|
33
|
+
data: {
|
|
34
|
+
code: dto.codeOrToken,
|
|
35
|
+
client_id: this.applicationId,
|
|
36
|
+
client_secret: secret,
|
|
37
|
+
grant_type: 'authorization_code'
|
|
38
|
+
},
|
|
39
|
+
method: 'post',
|
|
40
|
+
headers: { 'Content-Type': 'multipart/form-data' }
|
|
41
|
+
});
|
|
42
|
+
if (!_.isNil(item.error_description)) {
|
|
43
|
+
throw new ExtendedError(item.error_description);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
expiresIn: item.expires_in,
|
|
47
|
+
accessToken: item.access_token,
|
|
48
|
+
refreshToken: item.refresh_token,
|
|
49
|
+
tokenType: item.token_type,
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
package/esm/ya/YaUser.d.ts
CHANGED
package/package.json
CHANGED
package/cjs/vk/VkOAuth.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
2
|
-
import { VkUser } from "./VkUser";
|
|
3
|
-
export declare class VkOAuth<T extends VkUser = VkUser> extends OAuthBase<T> {
|
|
4
|
-
protected getAuthUrl(): string;
|
|
5
|
-
getProfile(token: string, fields: string): Promise<T>;
|
|
6
|
-
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
7
|
-
}
|
package/cjs/ya/YaOAuth.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.YaOAuth = void 0;
|
|
13
|
-
const OAuthBase_1 = require("../OAuthBase");
|
|
14
|
-
const YaUser_1 = require("./YaUser");
|
|
15
|
-
const _ = require("lodash");
|
|
16
|
-
const axios_1 = require("axios");
|
|
17
|
-
class YaOAuth extends OAuthBase_1.OAuthBase {
|
|
18
|
-
constructor(logger, window, applicationId, scope) {
|
|
19
|
-
super(logger, window, applicationId, scope);
|
|
20
|
-
this.popUpWidth = 480;
|
|
21
|
-
this.popUpHeight = 520;
|
|
22
|
-
}
|
|
23
|
-
getAuthUrl() {
|
|
24
|
-
let params = new URLSearchParams();
|
|
25
|
-
params.append('display', 'popup');
|
|
26
|
-
params.append('client_id', this.applicationId);
|
|
27
|
-
params.append('redirect_uri', this.redirectUri);
|
|
28
|
-
params.append('response_type', this.responseType);
|
|
29
|
-
if (!_.isEmpty(this.scope)) {
|
|
30
|
-
params.append('scope', this.scope);
|
|
31
|
-
}
|
|
32
|
-
return `https://oauth.yandex.ru/authorize?${params.toString()}`;
|
|
33
|
-
}
|
|
34
|
-
getProfile(token) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
let item = yield this.http.call('https://login.yandex.ru/info', { data: { oauth_token: token } });
|
|
37
|
-
return new YaUser_1.YaUser(item);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
getTokenByCode(dto, secret) {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
let { data } = yield axios_1.default.postForm('https://oauth.yandex.ru/token', {
|
|
43
|
-
code: dto.codeOrToken,
|
|
44
|
-
client_id: this.applicationId,
|
|
45
|
-
client_secret: secret,
|
|
46
|
-
grant_type: 'authorization_code'
|
|
47
|
-
});
|
|
48
|
-
return {
|
|
49
|
-
tokenType: data.token_type,
|
|
50
|
-
expiresIn: data.expires_in,
|
|
51
|
-
accessToken: data.access_token,
|
|
52
|
-
refreshToken: data.refresh_token,
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.YaOAuth = YaOAuth;
|
package/esm/vk/VkOAuth.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
2
|
-
import { VkUser } from "./VkUser";
|
|
3
|
-
export declare class VkOAuth<T extends VkUser = VkUser> extends OAuthBase<T> {
|
|
4
|
-
protected getAuthUrl(): string;
|
|
5
|
-
getProfile(token: string, fields: string): Promise<T>;
|
|
6
|
-
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
7
|
-
}
|
package/esm/ya/YaOAuth.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { OAuthBase } from "../OAuthBase";
|
|
11
|
-
import { YaUser } from "./YaUser";
|
|
12
|
-
import * as _ from 'lodash';
|
|
13
|
-
import axios from 'axios';
|
|
14
|
-
export class YaOAuth extends OAuthBase {
|
|
15
|
-
constructor(logger, window, applicationId, scope) {
|
|
16
|
-
super(logger, window, applicationId, scope);
|
|
17
|
-
this.popUpWidth = 480;
|
|
18
|
-
this.popUpHeight = 520;
|
|
19
|
-
}
|
|
20
|
-
getAuthUrl() {
|
|
21
|
-
let params = new URLSearchParams();
|
|
22
|
-
params.append('display', 'popup');
|
|
23
|
-
params.append('client_id', this.applicationId);
|
|
24
|
-
params.append('redirect_uri', this.redirectUri);
|
|
25
|
-
params.append('response_type', this.responseType);
|
|
26
|
-
if (!_.isEmpty(this.scope)) {
|
|
27
|
-
params.append('scope', this.scope);
|
|
28
|
-
}
|
|
29
|
-
return `https://oauth.yandex.ru/authorize?${params.toString()}`;
|
|
30
|
-
}
|
|
31
|
-
getProfile(token) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
let item = yield this.http.call('https://login.yandex.ru/info', { data: { oauth_token: token } });
|
|
34
|
-
return new YaUser(item);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
getTokenByCode(dto, secret) {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
let { data } = yield axios.postForm('https://oauth.yandex.ru/token', {
|
|
40
|
-
code: dto.codeOrToken,
|
|
41
|
-
client_id: this.applicationId,
|
|
42
|
-
client_secret: secret,
|
|
43
|
-
grant_type: 'authorization_code'
|
|
44
|
-
});
|
|
45
|
-
return {
|
|
46
|
-
tokenType: data.token_type,
|
|
47
|
-
expiresIn: data.expires_in,
|
|
48
|
-
accessToken: data.access_token,
|
|
49
|
-
refreshToken: data.refresh_token,
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|