@ts-core/oauth 3.0.24 → 3.0.26
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 +10 -9
- package/cjs/OAuthBase.js +9 -28
- package/cjs/external/browser.d.ts +2 -0
- package/cjs/external/browser.js +29 -0
- package/cjs/external/cordovaInAppBrowserPlugin.d.ts +3 -0
- package/cjs/external/cordovaInAppBrowserPlugin.js +55 -0
- package/cjs/external/cordovaOAuthPlugin.d.ts +2 -0
- package/cjs/external/cordovaOAuthPlugin.js +28 -0
- package/cjs/external/index.d.ts +3 -0
- package/cjs/external/index.js +19 -0
- package/cjs/go/GoAuth.d.ts +1 -1
- package/cjs/go/GoAuth.js +1 -1
- package/cjs/ma/MaAuth.d.ts +1 -1
- package/cjs/ma/MaAuth.js +1 -1
- package/cjs/public-api.d.ts +3 -2
- package/cjs/public-api.js +3 -2
- package/cjs/vk/VkAuth.d.ts +1 -1
- package/cjs/vk/VkAuth.js +1 -1
- package/cjs/ya/YaAuth.d.ts +1 -1
- package/cjs/ya/YaAuth.js +1 -1
- package/esm/OAuthBase.d.ts +10 -9
- package/esm/OAuthBase.js +10 -29
- package/esm/external/browser.d.ts +2 -0
- package/esm/external/browser.js +25 -0
- package/esm/external/cordovaInAppBrowserPlugin.d.ts +3 -0
- package/esm/external/cordovaInAppBrowserPlugin.js +51 -0
- package/esm/external/cordovaOAuthPlugin.d.ts +2 -0
- package/esm/external/cordovaOAuthPlugin.js +24 -0
- package/esm/external/index.d.ts +3 -0
- package/esm/external/index.js +3 -0
- package/esm/go/GoAuth.d.ts +1 -1
- package/esm/go/GoAuth.js +1 -1
- package/esm/ma/MaAuth.d.ts +1 -1
- package/esm/ma/MaAuth.js +1 -1
- package/esm/public-api.d.ts +3 -2
- package/esm/public-api.js +3 -2
- package/esm/vk/VkAuth.d.ts +1 -1
- package/esm/vk/VkAuth.js +1 -1
- package/esm/ya/YaAuth.d.ts +1 -1
- package/esm/ya/YaAuth.js +1 -1
- package/package.json +2 -2
- package/cjs/external/backend.d.ts +0 -3
- package/cjs/external/backend.js +0 -28
- package/cjs/external/cordova.d.ts +0 -2
- package/cjs/external/cordova.js +0 -17
- package/esm/external/backend.d.ts +0 -3
- package/esm/external/backend.js +0 -24
- package/esm/external/cordova.d.ts +0 -2
- package/esm/external/cordova.js +0 -13
package/cjs/OAuthBase.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
7
7
|
popUpWidth: number;
|
|
8
8
|
popUpHeight: number;
|
|
9
9
|
popUpTarget: string;
|
|
10
|
-
|
|
10
|
+
popUpOpener: IOAuthPopUpOpener;
|
|
11
|
+
popUpMessageParser: IOAuthPopUpMessageParser;
|
|
11
12
|
redirectUri: string;
|
|
12
13
|
isRejectWhenPopUpClosed: boolean;
|
|
13
14
|
protected http: TransportHttp;
|
|
@@ -19,18 +20,17 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
19
20
|
protected _popUpCheckCloseTimer: any;
|
|
20
21
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
21
22
|
protected open(): Promise<IOAuthDto>;
|
|
22
|
-
protected popUpOpen(): Window;
|
|
23
23
|
protected popUpFocus(): void;
|
|
24
24
|
protected popUpCheckClose: () => void;
|
|
25
25
|
protected getUrlParams(): URLSearchParams;
|
|
26
|
-
protected
|
|
27
|
-
protected
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
protected popUpOpenHandler: () => Window;
|
|
27
|
+
protected popUpMessageHandler: (event: MessageEvent) => void;
|
|
28
|
+
abstract getPopUpUrl(): string;
|
|
29
|
+
getOriginUrl(): string;
|
|
30
|
+
getRedirectUri(): string;
|
|
31
31
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
32
32
|
abstract getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
33
|
-
|
|
33
|
+
parseResponse(data: IOAuthPopUpDto): void;
|
|
34
34
|
getCode(): Promise<IOAuthDto>;
|
|
35
35
|
getToken(): Promise<IOAuthDto>;
|
|
36
36
|
close(): void;
|
|
@@ -66,4 +66,5 @@ export declare enum OAuthEvent {
|
|
|
66
66
|
POPUP_OPENED = "POPUP_OPENED",
|
|
67
67
|
POPUP_CLOSED = "POPUP_CLOSED"
|
|
68
68
|
}
|
|
69
|
-
export type
|
|
69
|
+
export type IOAuthPopUpOpener = <T extends OAuthBase>(item: T, window: Window) => Window;
|
|
70
|
+
export type IOAuthPopUpMessageParser = <T extends OAuthBase>(item: T, event: MessageEvent) => IOAuthPopUpDto;
|
package/cjs/OAuthBase.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.OAuthEvent = exports.OAuthBase = void 0;
|
|
|
13
13
|
const common_1 = require("@ts-core/common");
|
|
14
14
|
const _ = require("lodash");
|
|
15
15
|
const rxjs_1 = require("rxjs");
|
|
16
|
+
const external_1 = require("./external");
|
|
16
17
|
class OAuthBase extends common_1.LoggerWrapper {
|
|
17
18
|
constructor(logger, applicationId, window) {
|
|
18
19
|
super(logger);
|
|
@@ -23,30 +24,17 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
23
24
|
this.close();
|
|
24
25
|
}
|
|
25
26
|
};
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
28
|
-
if (event.origin !== this.getOriginUrl()) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
let data = event.data;
|
|
32
|
-
if (!_.isObject(data)) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
if (!common_1.ObjectUtil.hasOwnProperty(data, 'oAuthCodeOrToken') && !common_1.ObjectUtil.hasOwnProperty(data, 'oAuthError')) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
return data;
|
|
39
|
-
};
|
|
27
|
+
this.popUpOpenHandler = () => this.popUpOpener(this, this.window);
|
|
28
|
+
this.popUpMessageHandler = (event) => this.parseResponse(this.popUpMessageParser(this, event));
|
|
40
29
|
this.http = new common_1.TransportHttp(logger, { method: 'get' });
|
|
41
30
|
this.subject = new rxjs_1.Subject();
|
|
42
31
|
this.popUpWidth = 430;
|
|
43
32
|
this.popUpHeight = 520;
|
|
44
33
|
this.popUpTarget = '_blank';
|
|
45
|
-
this.popUpMessageParser = this.browserInternalMessageHandler;
|
|
46
|
-
this.isRejectWhenPopUpClosed = true;
|
|
47
34
|
this._urlParams = new Map();
|
|
48
35
|
this.urlParams.set('state', common_1.RandomUtil.randomString());
|
|
49
36
|
this.urlParams.set('display', 'popup');
|
|
37
|
+
(0, external_1.OAuthBrowserPropertiesSet)(this);
|
|
50
38
|
}
|
|
51
39
|
open() {
|
|
52
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -55,23 +43,16 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
55
43
|
return this.promise.promise;
|
|
56
44
|
}
|
|
57
45
|
this.promise = common_1.PromiseHandler.create();
|
|
58
|
-
this.popUp = this.
|
|
46
|
+
this.popUp = this.popUpOpenHandler();
|
|
59
47
|
this.popUpFocus();
|
|
60
|
-
this.window.addEventListener('message', this.
|
|
48
|
+
this.window.addEventListener('message', this.popUpMessageHandler, false);
|
|
61
49
|
this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_OPENED, this.popUp));
|
|
62
50
|
this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, common_1.DateUtil.MILLISECONDS_SECOND / 5);
|
|
63
51
|
return this.promise.promise;
|
|
64
52
|
});
|
|
65
53
|
}
|
|
66
|
-
popUpOpen() {
|
|
67
|
-
let window = this.window;
|
|
68
|
-
let top = (window.screen.height - this.popUpHeight) / 2;
|
|
69
|
-
let left = (window.screen.width - this.popUpWidth) / 2;
|
|
70
|
-
let item = window.open(this.getUrl(), this.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
71
|
-
return item;
|
|
72
|
-
}
|
|
73
54
|
popUpFocus() {
|
|
74
|
-
if (this.isPopUpOpened) {
|
|
55
|
+
if (this.isPopUpOpened && _.isFunction(this.popUp.focus)) {
|
|
75
56
|
this.popUp.focus();
|
|
76
57
|
}
|
|
77
58
|
}
|
|
@@ -89,7 +70,7 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
89
70
|
getRedirectUri() {
|
|
90
71
|
return !_.isNil(this.redirectUri) ? this.redirectUri : `${this.getOriginUrl()}/oauth`;
|
|
91
72
|
}
|
|
92
|
-
|
|
73
|
+
parseResponse(data) {
|
|
93
74
|
if (_.isNil(data)) {
|
|
94
75
|
return;
|
|
95
76
|
}
|
|
@@ -116,7 +97,7 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
116
97
|
});
|
|
117
98
|
}
|
|
118
99
|
close() {
|
|
119
|
-
this.window.removeEventListener('message', this.
|
|
100
|
+
this.window.removeEventListener('message', this.popUpMessageHandler, false);
|
|
120
101
|
this.popUpCheckCloseTimer = null;
|
|
121
102
|
if (_.isNil(this.popUp)) {
|
|
122
103
|
return;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OAuthBrowserPropertiesSet = void 0;
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
const common_1 = require("@ts-core/common");
|
|
6
|
+
const OAuthBrowserPropertiesSet = (item) => {
|
|
7
|
+
item.popUpOpener = popUpOpener;
|
|
8
|
+
item.popUpMessageParser = popUpMessageParser;
|
|
9
|
+
item.isRejectWhenPopUpClosed = true;
|
|
10
|
+
};
|
|
11
|
+
exports.OAuthBrowserPropertiesSet = OAuthBrowserPropertiesSet;
|
|
12
|
+
function popUpOpener(item, window) {
|
|
13
|
+
let top = (window.screen.height - item.popUpHeight) / 2;
|
|
14
|
+
let left = (window.screen.width - item.popUpWidth) / 2;
|
|
15
|
+
return window.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
16
|
+
}
|
|
17
|
+
function popUpMessageParser(item, event) {
|
|
18
|
+
if (event.origin !== item.getOriginUrl()) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
let data = event.data;
|
|
22
|
+
if (!_.isObject(data)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (!common_1.ObjectUtil.hasOwnProperty(data, 'oAuthCodeOrToken') && !common_1.ObjectUtil.hasOwnProperty(data, 'oAuthError')) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IOAuthPopUpDto, OAuthBase } from '../OAuthBase';
|
|
2
|
+
export declare const OAuthCordovaInAppBrowserPluginPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod) => void;
|
|
3
|
+
export type IOAuthBackendMethod = (state: string) => Promise<IOAuthPopUpDto>;
|
|
@@ -0,0 +1,55 @@
|
|
|
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.OAuthCordovaInAppBrowserPluginPropertiesSet = void 0;
|
|
13
|
+
const OAuthBase_1 = require("../OAuthBase");
|
|
14
|
+
const rxjs_1 = require("rxjs");
|
|
15
|
+
const _ = require("lodash");
|
|
16
|
+
const common_1 = require("@ts-core/common");
|
|
17
|
+
const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method) => {
|
|
18
|
+
item.redirectUri = redirectUri;
|
|
19
|
+
item.popUpOpener = popUpOpener;
|
|
20
|
+
item.popUpOpened.pipe((0, rxjs_1.takeUntil)(item.destroyed)).subscribe((popUp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
let popUpClosedHandler = () => {
|
|
22
|
+
popUp.removeEventListener('exit', popUpClosedHandler);
|
|
23
|
+
popUp.removeEventListener('loadstop', popUpLoadedHandler);
|
|
24
|
+
item.close();
|
|
25
|
+
};
|
|
26
|
+
let popUpLoadedHandler = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
if (!event.url.includes(item.redirectUri)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
let data = null;
|
|
31
|
+
try {
|
|
32
|
+
data = yield method(item.state);
|
|
33
|
+
if (_.isEmpty(data)) {
|
|
34
|
+
data = { oAuthError: OAuthBase_1.OAuthBase.ERROR_WINDOW_CLOSED, oAuthCodeOrToken: null };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
data = { oAuthError: error.toString(), oAuthCodeOrToken: null };
|
|
39
|
+
}
|
|
40
|
+
item.parseResponse(data);
|
|
41
|
+
});
|
|
42
|
+
popUp.addEventListener('exit', popUpClosedHandler, false);
|
|
43
|
+
popUp.addEventListener('loadstop', popUpLoadedHandler, false);
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
46
|
+
exports.OAuthCordovaInAppBrowserPluginPropertiesSet = OAuthCordovaInAppBrowserPluginPropertiesSet;
|
|
47
|
+
function popUpOpener(item, window) {
|
|
48
|
+
let top = (window.screen.height - item.popUpHeight) / 2;
|
|
49
|
+
let left = (window.screen.width - item.popUpWidth) / 2;
|
|
50
|
+
let cordova = window['cordova'];
|
|
51
|
+
if (_.isNil(cordova) || _.isNil(cordova.InAppBrowser)) {
|
|
52
|
+
throw new common_1.ExtendedError(`Cordova InAppBrowser undefined, please check installed plugins`);
|
|
53
|
+
}
|
|
54
|
+
return cordova.InAppBrowser.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
55
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OAuthCordovaOAuthPluginPropertiesSet = void 0;
|
|
4
|
+
const OAuthParser_1 = require("../OAuthParser");
|
|
5
|
+
const _ = require("lodash");
|
|
6
|
+
const OAuthCordovaOAuthPluginPropertiesSet = (item, packageName) => {
|
|
7
|
+
item.popUpTarget = 'oauth:cordova';
|
|
8
|
+
item.popUpOpener = popUpOpener;
|
|
9
|
+
item.popUpMessageParser = popUpMessageParser;
|
|
10
|
+
item.redirectUri = `${packageName}://oauth_callback`;
|
|
11
|
+
item.isRejectWhenPopUpClosed = false;
|
|
12
|
+
};
|
|
13
|
+
exports.OAuthCordovaOAuthPluginPropertiesSet = OAuthCordovaOAuthPluginPropertiesSet;
|
|
14
|
+
function popUpOpener(item, window) {
|
|
15
|
+
let top = (window.screen.height - item.popUpHeight) / 2;
|
|
16
|
+
let left = (window.screen.width - item.popUpWidth) / 2;
|
|
17
|
+
let popUp = window.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
18
|
+
if (!_.isNil(popUp)) {
|
|
19
|
+
return popUp;
|
|
20
|
+
}
|
|
21
|
+
let fake = { close: () => { fake.closed = true; }, closed: false };
|
|
22
|
+
return fake;
|
|
23
|
+
}
|
|
24
|
+
function popUpMessageParser(item, event) {
|
|
25
|
+
let data = event.data;
|
|
26
|
+
let prefix = 'oauth::';
|
|
27
|
+
return _.isString(data) && data.includes(prefix) ? OAuthParser_1.OAuthParser.parse(JSON.parse(data.substring(prefix.length)), '') : null;
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./browser"), exports);
|
|
18
|
+
__exportStar(require("./cordovaOAuthPlugin"), exports);
|
|
19
|
+
__exportStar(require("./cordovaInAppBrowserPlugin"), exports);
|
package/cjs/go/GoAuth.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { IOAuthDto, IOAuthToken, OAuthBase } from '../OAuthBase';
|
|
|
3
3
|
import { ILogger } from '@ts-core/common';
|
|
4
4
|
export declare class GoAuth<T extends GoUser = GoUser> extends OAuthBase<T> {
|
|
5
5
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
6
|
-
|
|
6
|
+
getPopUpUrl(): string;
|
|
7
7
|
getProfile(token: string): Promise<T>;
|
|
8
8
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
9
9
|
}
|
package/cjs/go/GoAuth.js
CHANGED
|
@@ -17,7 +17,7 @@ class GoAuth extends OAuthBase_1.OAuthBase {
|
|
|
17
17
|
super(logger, applicationId, window);
|
|
18
18
|
this.urlParams.set('scope', 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email');
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
getPopUpUrl() {
|
|
21
21
|
return `https://accounts.google.com/o/oauth2/v2/auth?${this.getUrlParams().toString()}`;
|
|
22
22
|
}
|
|
23
23
|
getProfile(token) {
|
package/cjs/ma/MaAuth.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { MaUser } from "./MaUser";
|
|
|
4
4
|
export declare class MaAuth<T extends MaUser = MaUser> extends OAuthBase<T> {
|
|
5
5
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
6
6
|
protected getUrlParams(): URLSearchParams;
|
|
7
|
-
|
|
7
|
+
getPopUpUrl(): string;
|
|
8
8
|
getProfile(token: string): Promise<T>;
|
|
9
9
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
10
10
|
}
|
package/cjs/ma/MaAuth.js
CHANGED
|
@@ -24,7 +24,7 @@ class MaAuth extends OAuthBase_1.OAuthBase {
|
|
|
24
24
|
item.append('state', common_1.RandomUtil.randomString(43));
|
|
25
25
|
return item;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
getPopUpUrl() {
|
|
28
28
|
return `https://oauth.mail.ru/login?${this.getUrlParams().toString()}`;
|
|
29
29
|
}
|
|
30
30
|
getProfile(token) {
|
package/cjs/public-api.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ export * from './ya/YaUser';
|
|
|
9
9
|
export * from './ya/YaAuth';
|
|
10
10
|
export * from './ma/MaAuth';
|
|
11
11
|
export * from './ma/MaUser';
|
|
12
|
-
export * from './external/
|
|
13
|
-
export * from './external/
|
|
12
|
+
export * from './external/browser';
|
|
13
|
+
export * from './external/cordovaOAuthPlugin';
|
|
14
|
+
export * from './external/cordovaInAppBrowserPlugin';
|
package/cjs/public-api.js
CHANGED
|
@@ -25,5 +25,6 @@ __exportStar(require("./ya/YaUser"), exports);
|
|
|
25
25
|
__exportStar(require("./ya/YaAuth"), exports);
|
|
26
26
|
__exportStar(require("./ma/MaAuth"), exports);
|
|
27
27
|
__exportStar(require("./ma/MaUser"), exports);
|
|
28
|
-
__exportStar(require("./external/
|
|
29
|
-
__exportStar(require("./external/
|
|
28
|
+
__exportStar(require("./external/browser"), exports);
|
|
29
|
+
__exportStar(require("./external/cordovaOAuthPlugin"), exports);
|
|
30
|
+
__exportStar(require("./external/cordovaInAppBrowserPlugin"), exports);
|
package/cjs/vk/VkAuth.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare class VkAuth<T extends VkUser = VkUser> extends OAuthBase<T> {
|
|
|
5
5
|
v: string;
|
|
6
6
|
private email;
|
|
7
7
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
8
|
-
|
|
8
|
+
getPopUpUrl(): string;
|
|
9
9
|
getProfile(token: string, fields?: string): Promise<T>;
|
|
10
10
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
11
11
|
}
|
package/cjs/vk/VkAuth.js
CHANGED
|
@@ -20,7 +20,7 @@ class VkAuth extends OAuthBase_1.OAuthBase {
|
|
|
20
20
|
this.v = '5.131';
|
|
21
21
|
this.urlParams.set('scope', 'status,email');
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
getPopUpUrl() {
|
|
24
24
|
return `https://oauth.vk.com/authorize?${this.getUrlParams().toString()}`;
|
|
25
25
|
}
|
|
26
26
|
getProfile(token, fields) {
|
package/cjs/ya/YaAuth.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
2
2
|
import { YaUser } from "./YaUser";
|
|
3
3
|
export declare class YaAuth<T extends YaUser = YaUser> extends OAuthBase<T> {
|
|
4
|
-
|
|
4
|
+
getPopUpUrl(): string;
|
|
5
5
|
getProfile(token: string): Promise<T>;
|
|
6
6
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
7
7
|
}
|
package/cjs/ya/YaAuth.js
CHANGED
|
@@ -15,7 +15,7 @@ const OAuthBase_1 = require("../OAuthBase");
|
|
|
15
15
|
const YaUser_1 = require("./YaUser");
|
|
16
16
|
const _ = require("lodash");
|
|
17
17
|
class YaAuth extends OAuthBase_1.OAuthBase {
|
|
18
|
-
|
|
18
|
+
getPopUpUrl() {
|
|
19
19
|
return `https://oauth.yandex.ru/authorize?${this.getUrlParams().toString()}`;
|
|
20
20
|
}
|
|
21
21
|
getProfile(token) {
|
package/esm/OAuthBase.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
7
7
|
popUpWidth: number;
|
|
8
8
|
popUpHeight: number;
|
|
9
9
|
popUpTarget: string;
|
|
10
|
-
|
|
10
|
+
popUpOpener: IOAuthPopUpOpener;
|
|
11
|
+
popUpMessageParser: IOAuthPopUpMessageParser;
|
|
11
12
|
redirectUri: string;
|
|
12
13
|
isRejectWhenPopUpClosed: boolean;
|
|
13
14
|
protected http: TransportHttp;
|
|
@@ -19,18 +20,17 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
19
20
|
protected _popUpCheckCloseTimer: any;
|
|
20
21
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
21
22
|
protected open(): Promise<IOAuthDto>;
|
|
22
|
-
protected popUpOpen(): Window;
|
|
23
23
|
protected popUpFocus(): void;
|
|
24
24
|
protected popUpCheckClose: () => void;
|
|
25
25
|
protected getUrlParams(): URLSearchParams;
|
|
26
|
-
protected
|
|
27
|
-
protected
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
protected popUpOpenHandler: () => Window;
|
|
27
|
+
protected popUpMessageHandler: (event: MessageEvent) => void;
|
|
28
|
+
abstract getPopUpUrl(): string;
|
|
29
|
+
getOriginUrl(): string;
|
|
30
|
+
getRedirectUri(): string;
|
|
31
31
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
32
32
|
abstract getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
33
|
-
|
|
33
|
+
parseResponse(data: IOAuthPopUpDto): void;
|
|
34
34
|
getCode(): Promise<IOAuthDto>;
|
|
35
35
|
getToken(): Promise<IOAuthDto>;
|
|
36
36
|
close(): void;
|
|
@@ -66,4 +66,5 @@ export declare enum OAuthEvent {
|
|
|
66
66
|
POPUP_OPENED = "POPUP_OPENED",
|
|
67
67
|
POPUP_CLOSED = "POPUP_CLOSED"
|
|
68
68
|
}
|
|
69
|
-
export type
|
|
69
|
+
export type IOAuthPopUpOpener = <T extends OAuthBase>(item: T, window: Window) => Window;
|
|
70
|
+
export type IOAuthPopUpMessageParser = <T extends OAuthBase>(item: T, event: MessageEvent) => IOAuthPopUpDto;
|
package/esm/OAuthBase.js
CHANGED
|
@@ -7,9 +7,10 @@ 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, ObservableData, LoggerWrapper, TransportHttp, RandomUtil
|
|
10
|
+
import { PromiseHandler, DateUtil, ObservableData, LoggerWrapper, TransportHttp, RandomUtil } from "@ts-core/common";
|
|
11
11
|
import * as _ from 'lodash';
|
|
12
12
|
import { filter, map, Subject } from "rxjs";
|
|
13
|
+
import { OAuthBrowserPropertiesSet } from "./external";
|
|
13
14
|
export class OAuthBase extends LoggerWrapper {
|
|
14
15
|
constructor(logger, applicationId, window) {
|
|
15
16
|
super(logger);
|
|
@@ -20,30 +21,17 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
20
21
|
this.close();
|
|
21
22
|
}
|
|
22
23
|
};
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
if (event.origin !== this.getOriginUrl()) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
let data = event.data;
|
|
29
|
-
if (!_.isObject(data)) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
if (!ObjectUtil.hasOwnProperty(data, 'oAuthCodeOrToken') && !ObjectUtil.hasOwnProperty(data, 'oAuthError')) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
return data;
|
|
36
|
-
};
|
|
24
|
+
this.popUpOpenHandler = () => this.popUpOpener(this, this.window);
|
|
25
|
+
this.popUpMessageHandler = (event) => this.parseResponse(this.popUpMessageParser(this, event));
|
|
37
26
|
this.http = new TransportHttp(logger, { method: 'get' });
|
|
38
27
|
this.subject = new Subject();
|
|
39
28
|
this.popUpWidth = 430;
|
|
40
29
|
this.popUpHeight = 520;
|
|
41
30
|
this.popUpTarget = '_blank';
|
|
42
|
-
this.popUpMessageParser = this.browserInternalMessageHandler;
|
|
43
|
-
this.isRejectWhenPopUpClosed = true;
|
|
44
31
|
this._urlParams = new Map();
|
|
45
32
|
this.urlParams.set('state', RandomUtil.randomString());
|
|
46
33
|
this.urlParams.set('display', 'popup');
|
|
34
|
+
OAuthBrowserPropertiesSet(this);
|
|
47
35
|
}
|
|
48
36
|
open() {
|
|
49
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -52,23 +40,16 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
52
40
|
return this.promise.promise;
|
|
53
41
|
}
|
|
54
42
|
this.promise = PromiseHandler.create();
|
|
55
|
-
this.popUp = this.
|
|
43
|
+
this.popUp = this.popUpOpenHandler();
|
|
56
44
|
this.popUpFocus();
|
|
57
|
-
this.window.addEventListener('message', this.
|
|
45
|
+
this.window.addEventListener('message', this.popUpMessageHandler, false);
|
|
58
46
|
this.subject.next(new ObservableData(OAuthEvent.POPUP_OPENED, this.popUp));
|
|
59
47
|
this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, DateUtil.MILLISECONDS_SECOND / 5);
|
|
60
48
|
return this.promise.promise;
|
|
61
49
|
});
|
|
62
50
|
}
|
|
63
|
-
popUpOpen() {
|
|
64
|
-
let window = this.window;
|
|
65
|
-
let top = (window.screen.height - this.popUpHeight) / 2;
|
|
66
|
-
let left = (window.screen.width - this.popUpWidth) / 2;
|
|
67
|
-
let item = window.open(this.getUrl(), this.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
68
|
-
return item;
|
|
69
|
-
}
|
|
70
51
|
popUpFocus() {
|
|
71
|
-
if (this.isPopUpOpened) {
|
|
52
|
+
if (this.isPopUpOpened && _.isFunction(this.popUp.focus)) {
|
|
72
53
|
this.popUp.focus();
|
|
73
54
|
}
|
|
74
55
|
}
|
|
@@ -86,7 +67,7 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
86
67
|
getRedirectUri() {
|
|
87
68
|
return !_.isNil(this.redirectUri) ? this.redirectUri : `${this.getOriginUrl()}/oauth`;
|
|
88
69
|
}
|
|
89
|
-
|
|
70
|
+
parseResponse(data) {
|
|
90
71
|
if (_.isNil(data)) {
|
|
91
72
|
return;
|
|
92
73
|
}
|
|
@@ -113,7 +94,7 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
113
94
|
});
|
|
114
95
|
}
|
|
115
96
|
close() {
|
|
116
|
-
this.window.removeEventListener('message', this.
|
|
97
|
+
this.window.removeEventListener('message', this.popUpMessageHandler, false);
|
|
117
98
|
this.popUpCheckCloseTimer = null;
|
|
118
99
|
if (_.isNil(this.popUp)) {
|
|
119
100
|
return;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as _ from 'lodash';
|
|
2
|
+
import { ObjectUtil } from '@ts-core/common';
|
|
3
|
+
export const OAuthBrowserPropertiesSet = (item) => {
|
|
4
|
+
item.popUpOpener = popUpOpener;
|
|
5
|
+
item.popUpMessageParser = popUpMessageParser;
|
|
6
|
+
item.isRejectWhenPopUpClosed = true;
|
|
7
|
+
};
|
|
8
|
+
function popUpOpener(item, window) {
|
|
9
|
+
let top = (window.screen.height - item.popUpHeight) / 2;
|
|
10
|
+
let left = (window.screen.width - item.popUpWidth) / 2;
|
|
11
|
+
return window.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
12
|
+
}
|
|
13
|
+
function popUpMessageParser(item, event) {
|
|
14
|
+
if (event.origin !== item.getOriginUrl()) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
let data = event.data;
|
|
18
|
+
if (!_.isObject(data)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (!ObjectUtil.hasOwnProperty(data, 'oAuthCodeOrToken') && !ObjectUtil.hasOwnProperty(data, 'oAuthError')) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IOAuthPopUpDto, OAuthBase } from '../OAuthBase';
|
|
2
|
+
export declare const OAuthCordovaInAppBrowserPluginPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod) => void;
|
|
3
|
+
export type IOAuthBackendMethod = (state: string) => Promise<IOAuthPopUpDto>;
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { takeUntil } from 'rxjs';
|
|
12
|
+
import * as _ from 'lodash';
|
|
13
|
+
import { ExtendedError } from '@ts-core/common';
|
|
14
|
+
export const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method) => {
|
|
15
|
+
item.redirectUri = redirectUri;
|
|
16
|
+
item.popUpOpener = popUpOpener;
|
|
17
|
+
item.popUpOpened.pipe(takeUntil(item.destroyed)).subscribe((popUp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
let popUpClosedHandler = () => {
|
|
19
|
+
popUp.removeEventListener('exit', popUpClosedHandler);
|
|
20
|
+
popUp.removeEventListener('loadstop', popUpLoadedHandler);
|
|
21
|
+
item.close();
|
|
22
|
+
};
|
|
23
|
+
let popUpLoadedHandler = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
if (!event.url.includes(item.redirectUri)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
let data = null;
|
|
28
|
+
try {
|
|
29
|
+
data = yield method(item.state);
|
|
30
|
+
if (_.isEmpty(data)) {
|
|
31
|
+
data = { oAuthError: OAuthBase.ERROR_WINDOW_CLOSED, oAuthCodeOrToken: null };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
data = { oAuthError: error.toString(), oAuthCodeOrToken: null };
|
|
36
|
+
}
|
|
37
|
+
item.parseResponse(data);
|
|
38
|
+
});
|
|
39
|
+
popUp.addEventListener('exit', popUpClosedHandler, false);
|
|
40
|
+
popUp.addEventListener('loadstop', popUpLoadedHandler, false);
|
|
41
|
+
}));
|
|
42
|
+
};
|
|
43
|
+
function popUpOpener(item, window) {
|
|
44
|
+
let top = (window.screen.height - item.popUpHeight) / 2;
|
|
45
|
+
let left = (window.screen.width - item.popUpWidth) / 2;
|
|
46
|
+
let cordova = window['cordova'];
|
|
47
|
+
if (_.isNil(cordova) || _.isNil(cordova.InAppBrowser)) {
|
|
48
|
+
throw new ExtendedError(`Cordova InAppBrowser undefined, please check installed plugins`);
|
|
49
|
+
}
|
|
50
|
+
return cordova.InAppBrowser.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
51
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { OAuthParser } from '../OAuthParser';
|
|
2
|
+
import * as _ from 'lodash';
|
|
3
|
+
export const OAuthCordovaOAuthPluginPropertiesSet = (item, packageName) => {
|
|
4
|
+
item.popUpTarget = 'oauth:cordova';
|
|
5
|
+
item.popUpOpener = popUpOpener;
|
|
6
|
+
item.popUpMessageParser = popUpMessageParser;
|
|
7
|
+
item.redirectUri = `${packageName}://oauth_callback`;
|
|
8
|
+
item.isRejectWhenPopUpClosed = false;
|
|
9
|
+
};
|
|
10
|
+
function popUpOpener(item, window) {
|
|
11
|
+
let top = (window.screen.height - item.popUpHeight) / 2;
|
|
12
|
+
let left = (window.screen.width - item.popUpWidth) / 2;
|
|
13
|
+
let popUp = window.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
14
|
+
if (!_.isNil(popUp)) {
|
|
15
|
+
return popUp;
|
|
16
|
+
}
|
|
17
|
+
let fake = { close: () => { fake.closed = true; }, closed: false };
|
|
18
|
+
return fake;
|
|
19
|
+
}
|
|
20
|
+
function popUpMessageParser(item, event) {
|
|
21
|
+
let data = event.data;
|
|
22
|
+
let prefix = 'oauth::';
|
|
23
|
+
return _.isString(data) && data.includes(prefix) ? OAuthParser.parse(JSON.parse(data.substring(prefix.length)), '') : null;
|
|
24
|
+
}
|
package/esm/go/GoAuth.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { IOAuthDto, IOAuthToken, OAuthBase } from '../OAuthBase';
|
|
|
3
3
|
import { ILogger } from '@ts-core/common';
|
|
4
4
|
export declare class GoAuth<T extends GoUser = GoUser> extends OAuthBase<T> {
|
|
5
5
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
6
|
-
|
|
6
|
+
getPopUpUrl(): string;
|
|
7
7
|
getProfile(token: string): Promise<T>;
|
|
8
8
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
9
9
|
}
|
package/esm/go/GoAuth.js
CHANGED
|
@@ -14,7 +14,7 @@ export class GoAuth extends OAuthBase {
|
|
|
14
14
|
super(logger, applicationId, window);
|
|
15
15
|
this.urlParams.set('scope', 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email');
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
getPopUpUrl() {
|
|
18
18
|
return `https://accounts.google.com/o/oauth2/v2/auth?${this.getUrlParams().toString()}`;
|
|
19
19
|
}
|
|
20
20
|
getProfile(token) {
|
package/esm/ma/MaAuth.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { MaUser } from "./MaUser";
|
|
|
4
4
|
export declare class MaAuth<T extends MaUser = MaUser> extends OAuthBase<T> {
|
|
5
5
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
6
6
|
protected getUrlParams(): URLSearchParams;
|
|
7
|
-
|
|
7
|
+
getPopUpUrl(): string;
|
|
8
8
|
getProfile(token: string): Promise<T>;
|
|
9
9
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
10
10
|
}
|
package/esm/ma/MaAuth.js
CHANGED
package/esm/public-api.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ export * from './ya/YaUser';
|
|
|
9
9
|
export * from './ya/YaAuth';
|
|
10
10
|
export * from './ma/MaAuth';
|
|
11
11
|
export * from './ma/MaUser';
|
|
12
|
-
export * from './external/
|
|
13
|
-
export * from './external/
|
|
12
|
+
export * from './external/browser';
|
|
13
|
+
export * from './external/cordovaOAuthPlugin';
|
|
14
|
+
export * from './external/cordovaInAppBrowserPlugin';
|
package/esm/public-api.js
CHANGED
|
@@ -9,5 +9,6 @@ export * from './ya/YaUser';
|
|
|
9
9
|
export * from './ya/YaAuth';
|
|
10
10
|
export * from './ma/MaAuth';
|
|
11
11
|
export * from './ma/MaUser';
|
|
12
|
-
export * from './external/
|
|
13
|
-
export * from './external/
|
|
12
|
+
export * from './external/browser';
|
|
13
|
+
export * from './external/cordovaOAuthPlugin';
|
|
14
|
+
export * from './external/cordovaInAppBrowserPlugin';
|
package/esm/vk/VkAuth.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare class VkAuth<T extends VkUser = VkUser> extends OAuthBase<T> {
|
|
|
5
5
|
v: string;
|
|
6
6
|
private email;
|
|
7
7
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
8
|
-
|
|
8
|
+
getPopUpUrl(): string;
|
|
9
9
|
getProfile(token: string, fields?: string): Promise<T>;
|
|
10
10
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
11
11
|
}
|
package/esm/vk/VkAuth.js
CHANGED
|
@@ -17,7 +17,7 @@ export class VkAuth extends OAuthBase {
|
|
|
17
17
|
this.v = '5.131';
|
|
18
18
|
this.urlParams.set('scope', 'status,email');
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
getPopUpUrl() {
|
|
21
21
|
return `https://oauth.vk.com/authorize?${this.getUrlParams().toString()}`;
|
|
22
22
|
}
|
|
23
23
|
getProfile(token, fields) {
|
package/esm/ya/YaAuth.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
2
2
|
import { YaUser } from "./YaUser";
|
|
3
3
|
export declare class YaAuth<T extends YaUser = YaUser> extends OAuthBase<T> {
|
|
4
|
-
|
|
4
|
+
getPopUpUrl(): string;
|
|
5
5
|
getProfile(token: string): Promise<T>;
|
|
6
6
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
7
7
|
}
|
package/esm/ya/YaAuth.js
CHANGED
|
@@ -12,7 +12,7 @@ import { OAuthBase } from "../OAuthBase";
|
|
|
12
12
|
import { YaUser } from "./YaUser";
|
|
13
13
|
import * as _ from 'lodash';
|
|
14
14
|
export class YaAuth extends OAuthBase {
|
|
15
|
-
|
|
15
|
+
getPopUpUrl() {
|
|
16
16
|
return `https://oauth.yandex.ru/authorize?${this.getUrlParams().toString()}`;
|
|
17
17
|
}
|
|
18
18
|
getProfile(token) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-core/oauth",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.26",
|
|
4
4
|
"description": "Classes and utils for oauth",
|
|
5
5
|
"main": "./cjs/public-api.js",
|
|
6
6
|
"module": "./esm/public-api.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ts-core/common": "
|
|
20
|
+
"@ts-core/common": "~3.0.14"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^14.14.31",
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { IOAuthPopUpDto, OAuthBase } from '../OAuthBase';
|
|
2
|
-
export declare const OAuthBackendPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod, timeout?: number) => void;
|
|
3
|
-
export type IOAuthBackendMethod = (state: string) => Promise<IOAuthPopUpDto>;
|
package/cjs/external/backend.js
DELETED
|
@@ -1,28 +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.OAuthBackendPropertiesSet = void 0;
|
|
13
|
-
const OAuthBase_1 = require("../OAuthBase");
|
|
14
|
-
const common_1 = require("@ts-core/common");
|
|
15
|
-
const rxjs_1 = require("rxjs");
|
|
16
|
-
const _ = require("lodash");
|
|
17
|
-
const OAuthBackendPropertiesSet = (item, redirectUri, method, timeout = common_1.DateUtil.MILLISECONDS_SECOND) => {
|
|
18
|
-
item.redirectUri = redirectUri;
|
|
19
|
-
item.isRejectWhenPopUpClosed = false;
|
|
20
|
-
item.popUpClosed.pipe((0, rxjs_1.delay)(timeout), (0, rxjs_1.takeUntil)(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
let data = yield method(item.state);
|
|
22
|
-
if (_.isEmpty(data)) {
|
|
23
|
-
data = { oAuthError: OAuthBase_1.OAuthBase.ERROR_WINDOW_CLOSED, oAuthCodeOrToken: null };
|
|
24
|
-
}
|
|
25
|
-
item.parsePopUpResult(data);
|
|
26
|
-
}));
|
|
27
|
-
};
|
|
28
|
-
exports.OAuthBackendPropertiesSet = OAuthBackendPropertiesSet;
|
package/cjs/external/cordova.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OAuthCordovaPropertiesSet = void 0;
|
|
4
|
-
const OAuthParser_1 = require("../OAuthParser");
|
|
5
|
-
const _ = require("lodash");
|
|
6
|
-
const OAuthCordovaPropertiesSet = (item, packageName) => {
|
|
7
|
-
item.redirectUri = `${packageName}://oauth_callback`;
|
|
8
|
-
item.isRejectWhenPopUpClosed = false;
|
|
9
|
-
item.popUpTarget = 'oauth:cordova';
|
|
10
|
-
item.popUpMessageParser = cordovaPopUpMessageParser;
|
|
11
|
-
};
|
|
12
|
-
exports.OAuthCordovaPropertiesSet = OAuthCordovaPropertiesSet;
|
|
13
|
-
function cordovaPopUpMessageParser(event) {
|
|
14
|
-
let data = event.data;
|
|
15
|
-
let prefix = 'oauth::';
|
|
16
|
-
return _.isString(data) && data.includes(prefix) ? OAuthParser_1.OAuthParser.parse(JSON.parse(data.substring(prefix.length)), '') : null;
|
|
17
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { IOAuthPopUpDto, OAuthBase } from '../OAuthBase';
|
|
2
|
-
export declare const OAuthBackendPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod, timeout?: number) => void;
|
|
3
|
-
export type IOAuthBackendMethod = (state: string) => Promise<IOAuthPopUpDto>;
|
package/esm/external/backend.js
DELETED
|
@@ -1,24 +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 { DateUtil } from '@ts-core/common';
|
|
12
|
-
import { delay, takeUntil } from 'rxjs';
|
|
13
|
-
import * as _ from 'lodash';
|
|
14
|
-
export const OAuthBackendPropertiesSet = (item, redirectUri, method, timeout = DateUtil.MILLISECONDS_SECOND) => {
|
|
15
|
-
item.redirectUri = redirectUri;
|
|
16
|
-
item.isRejectWhenPopUpClosed = false;
|
|
17
|
-
item.popUpClosed.pipe(delay(timeout), takeUntil(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
let data = yield method(item.state);
|
|
19
|
-
if (_.isEmpty(data)) {
|
|
20
|
-
data = { oAuthError: OAuthBase.ERROR_WINDOW_CLOSED, oAuthCodeOrToken: null };
|
|
21
|
-
}
|
|
22
|
-
item.parsePopUpResult(data);
|
|
23
|
-
}));
|
|
24
|
-
};
|
package/esm/external/cordova.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { OAuthParser } from '../OAuthParser';
|
|
2
|
-
import * as _ from 'lodash';
|
|
3
|
-
export const OAuthCordovaPropertiesSet = (item, packageName) => {
|
|
4
|
-
item.redirectUri = `${packageName}://oauth_callback`;
|
|
5
|
-
item.isRejectWhenPopUpClosed = false;
|
|
6
|
-
item.popUpTarget = 'oauth:cordova';
|
|
7
|
-
item.popUpMessageParser = cordovaPopUpMessageParser;
|
|
8
|
-
};
|
|
9
|
-
function cordovaPopUpMessageParser(event) {
|
|
10
|
-
let data = event.data;
|
|
11
|
-
let prefix = 'oauth::';
|
|
12
|
-
return _.isString(data) && data.includes(prefix) ? OAuthParser.parse(JSON.parse(data.substring(prefix.length)), '') : null;
|
|
13
|
-
}
|