@ts-core/oauth 3.0.25 → 3.0.27
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.js +1 -1
- package/cjs/external/cordovaInAppBrowserPlugin.d.ts +1 -1
- package/cjs/external/cordovaInAppBrowserPlugin.js +32 -12
- package/cjs/external/cordovaOAuthPlugin.js +2 -2
- package/cjs/ma/MaAuth.d.ts +0 -1
- package/cjs/ma/MaAuth.js +1 -5
- package/esm/OAuthBase.js +1 -1
- package/esm/external/cordovaInAppBrowserPlugin.d.ts +1 -1
- package/esm/external/cordovaInAppBrowserPlugin.js +33 -13
- package/esm/external/cordovaOAuthPlugin.js +2 -2
- package/esm/ma/MaAuth.d.ts +0 -1
- package/esm/ma/MaAuth.js +1 -5
- package/package.json +1 -1
package/cjs/OAuthBase.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IOAuthPopUpDto, OAuthBase } from '../OAuthBase';
|
|
2
|
-
export declare const OAuthCordovaInAppBrowserPluginPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod
|
|
2
|
+
export declare const OAuthCordovaInAppBrowserPluginPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod) => void;
|
|
3
3
|
export type IOAuthBackendMethod = (state: string) => Promise<IOAuthPopUpDto>;
|
|
@@ -11,25 +11,45 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.OAuthCordovaInAppBrowserPluginPropertiesSet = void 0;
|
|
13
13
|
const OAuthBase_1 = require("../OAuthBase");
|
|
14
|
-
const common_1 = require("@ts-core/common");
|
|
15
14
|
const rxjs_1 = require("rxjs");
|
|
16
15
|
const _ = require("lodash");
|
|
17
|
-
const
|
|
18
|
-
|
|
16
|
+
const common_1 = require("@ts-core/common");
|
|
17
|
+
const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method) => {
|
|
19
18
|
item.redirectUri = redirectUri;
|
|
20
|
-
item.
|
|
21
|
-
item.
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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);
|
|
27
44
|
}));
|
|
28
45
|
};
|
|
29
46
|
exports.OAuthCordovaInAppBrowserPluginPropertiesSet = OAuthCordovaInAppBrowserPluginPropertiesSet;
|
|
30
47
|
function popUpOpener(item, window) {
|
|
31
48
|
let top = (window.screen.height - item.popUpHeight) / 2;
|
|
32
49
|
let left = (window.screen.width - item.popUpWidth) / 2;
|
|
33
|
-
let
|
|
34
|
-
|
|
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}`);
|
|
35
55
|
}
|
|
@@ -14,11 +14,11 @@ exports.OAuthCordovaOAuthPluginPropertiesSet = OAuthCordovaOAuthPluginProperties
|
|
|
14
14
|
function popUpOpener(item, window) {
|
|
15
15
|
let top = (window.screen.height - item.popUpHeight) / 2;
|
|
16
16
|
let left = (window.screen.width - item.popUpWidth) / 2;
|
|
17
|
-
let popUp = window.open(
|
|
17
|
+
let popUp = window.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
18
18
|
if (!_.isNil(popUp)) {
|
|
19
19
|
return popUp;
|
|
20
20
|
}
|
|
21
|
-
let fake = {
|
|
21
|
+
let fake = { close: () => { fake.closed = true; }, closed: false };
|
|
22
22
|
return fake;
|
|
23
23
|
}
|
|
24
24
|
function popUpMessageParser(item, event) {
|
package/cjs/ma/MaAuth.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
|
3
3
|
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
|
-
protected getUrlParams(): URLSearchParams;
|
|
7
6
|
getPopUpUrl(): string;
|
|
8
7
|
getProfile(token: string): Promise<T>;
|
|
9
8
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
package/cjs/ma/MaAuth.js
CHANGED
|
@@ -18,11 +18,7 @@ class MaAuth extends OAuthBase_1.OAuthBase {
|
|
|
18
18
|
constructor(logger, applicationId, window) {
|
|
19
19
|
super(logger, applicationId, window);
|
|
20
20
|
this.urlParams.set('scope', 'userinfo');
|
|
21
|
-
|
|
22
|
-
getUrlParams() {
|
|
23
|
-
let item = super.getUrlParams();
|
|
24
|
-
item.append('state', common_1.RandomUtil.randomString(43));
|
|
25
|
-
return item;
|
|
21
|
+
this.urlParams.set('state', common_1.RandomUtil.randomString(43));
|
|
26
22
|
}
|
|
27
23
|
getPopUpUrl() {
|
|
28
24
|
return `https://oauth.mail.ru/login?${this.getUrlParams().toString()}`;
|
package/esm/OAuthBase.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IOAuthPopUpDto, OAuthBase } from '../OAuthBase';
|
|
2
|
-
export declare const OAuthCordovaInAppBrowserPluginPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod
|
|
2
|
+
export declare const OAuthCordovaInAppBrowserPluginPropertiesSet: (item: OAuthBase, redirectUri: string, method: IOAuthBackendMethod) => void;
|
|
3
3
|
export type IOAuthBackendMethod = (state: string) => Promise<IOAuthPopUpDto>;
|
|
@@ -8,24 +8,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { OAuthBase } from '../OAuthBase';
|
|
11
|
-
import {
|
|
12
|
-
import { delay, takeUntil } from 'rxjs';
|
|
11
|
+
import { takeUntil } from 'rxjs';
|
|
13
12
|
import * as _ from 'lodash';
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
import { ExtendedError } from '@ts-core/common';
|
|
14
|
+
export const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method) => {
|
|
16
15
|
item.redirectUri = redirectUri;
|
|
17
|
-
item.
|
|
18
|
-
item.
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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);
|
|
24
41
|
}));
|
|
25
42
|
};
|
|
26
43
|
function popUpOpener(item, window) {
|
|
27
44
|
let top = (window.screen.height - item.popUpHeight) / 2;
|
|
28
45
|
let left = (window.screen.width - item.popUpWidth) / 2;
|
|
29
|
-
let
|
|
30
|
-
|
|
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}`);
|
|
31
51
|
}
|
|
@@ -10,11 +10,11 @@ export const OAuthCordovaOAuthPluginPropertiesSet = (item, packageName) => {
|
|
|
10
10
|
function popUpOpener(item, window) {
|
|
11
11
|
let top = (window.screen.height - item.popUpHeight) / 2;
|
|
12
12
|
let left = (window.screen.width - item.popUpWidth) / 2;
|
|
13
|
-
let popUp = window.open(
|
|
13
|
+
let popUp = window.open(item.getPopUpUrl(), item.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
14
14
|
if (!_.isNil(popUp)) {
|
|
15
15
|
return popUp;
|
|
16
16
|
}
|
|
17
|
-
let fake = {
|
|
17
|
+
let fake = { close: () => { fake.closed = true; }, closed: false };
|
|
18
18
|
return fake;
|
|
19
19
|
}
|
|
20
20
|
function popUpMessageParser(item, event) {
|
package/esm/ma/MaAuth.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
|
3
3
|
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
|
-
protected getUrlParams(): URLSearchParams;
|
|
7
6
|
getPopUpUrl(): string;
|
|
8
7
|
getProfile(token: string): Promise<T>;
|
|
9
8
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
package/esm/ma/MaAuth.js
CHANGED
|
@@ -15,11 +15,7 @@ export class MaAuth extends OAuthBase {
|
|
|
15
15
|
constructor(logger, applicationId, window) {
|
|
16
16
|
super(logger, applicationId, window);
|
|
17
17
|
this.urlParams.set('scope', 'userinfo');
|
|
18
|
-
|
|
19
|
-
getUrlParams() {
|
|
20
|
-
let item = super.getUrlParams();
|
|
21
|
-
item.append('state', RandomUtil.randomString(43));
|
|
22
|
-
return item;
|
|
18
|
+
this.urlParams.set('state', RandomUtil.randomString(43));
|
|
23
19
|
}
|
|
24
20
|
getPopUpUrl() {
|
|
25
21
|
return `https://oauth.mail.ru/login?${this.getUrlParams().toString()}`;
|