@ts-core/oauth 3.0.19 → 3.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/OAuthBase.d.ts +3 -3
- package/cjs/OAuthBase.js +4 -4
- package/cjs/external/backend.d.ts +3 -0
- package/cjs/external/backend.js +20 -0
- package/cjs/external/cordova.d.ts +2 -0
- package/cjs/external/cordova.js +17 -0
- package/cjs/public-api.d.ts +2 -0
- package/cjs/public-api.js +2 -0
- package/esm/OAuthBase.d.ts +3 -3
- package/esm/OAuthBase.js +4 -4
- package/esm/external/backend.d.ts +3 -0
- package/esm/external/backend.js +16 -0
- package/esm/external/cordova.d.ts +2 -0
- package/esm/external/cordova.js +13 -0
- package/esm/public-api.d.ts +2 -0
- package/esm/public-api.js +2 -0
- package/package.json +1 -1
package/cjs/OAuthBase.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
8
8
|
popUpHeight: number;
|
|
9
9
|
popUpTarget: string;
|
|
10
10
|
popUpIsCheckClose: boolean;
|
|
11
|
-
popUpMessageParser:
|
|
11
|
+
popUpMessageParser: IOAuthPopUpParser;
|
|
12
12
|
redirectUri: string;
|
|
13
13
|
protected http: TransportHttp;
|
|
14
14
|
protected subject: Subject<ObservableData<OAuthEvent, Window>>;
|
|
@@ -25,7 +25,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
25
25
|
protected getUrlParams(): URLSearchParams;
|
|
26
26
|
protected abstract getUrl(): string;
|
|
27
27
|
protected messageHandler: (event: MessageEvent) => void;
|
|
28
|
-
protected
|
|
28
|
+
protected browserInternalMessageHandler: IOAuthPopUpParser;
|
|
29
29
|
protected getOriginUrl(): string;
|
|
30
30
|
protected getRedirectUri(): string;
|
|
31
31
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
@@ -65,4 +65,4 @@ export declare enum OAuthEvent {
|
|
|
65
65
|
POPUP_OPENED = "POPUP_OPENED",
|
|
66
66
|
POPUP_CLOSED = "POPUP_CLOSED"
|
|
67
67
|
}
|
|
68
|
-
export type
|
|
68
|
+
export type IOAuthPopUpParser = (...params: any[]) => IOAuthPopUpDto;
|
package/cjs/OAuthBase.js
CHANGED
|
@@ -24,13 +24,16 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
this.messageHandler = (event) => this.parsePopUpResult(this.popUpMessageParser(event));
|
|
27
|
+
this.browserInternalMessageHandler = (event) => {
|
|
28
|
+
return event.origin === this.getOriginUrl() && _.isObject(event.data) ? event.data : null;
|
|
29
|
+
};
|
|
27
30
|
this.http = new common_1.TransportHttp(logger, { method: 'get' });
|
|
28
31
|
this.subject = new rxjs_1.Subject();
|
|
29
32
|
this.popUpWidth = 430;
|
|
30
33
|
this.popUpHeight = 520;
|
|
31
34
|
this.popUpTarget = '_blank';
|
|
32
35
|
this.popUpIsCheckClose = true;
|
|
33
|
-
this.popUpMessageParser = this.
|
|
36
|
+
this.popUpMessageParser = this.browserInternalMessageHandler;
|
|
34
37
|
this._urlParams = new Map();
|
|
35
38
|
this.urlParams.set('state', common_1.RandomUtil.randomString());
|
|
36
39
|
this.urlParams.set('display', 'popup');
|
|
@@ -74,9 +77,6 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
74
77
|
this.urlParams.forEach((value, key) => item.append(key, value));
|
|
75
78
|
return item;
|
|
76
79
|
}
|
|
77
|
-
browserMessageHandler(event) {
|
|
78
|
-
return event.origin === this.getOriginUrl() && _.isObject(event.data) ? event.data : null;
|
|
79
|
-
}
|
|
80
80
|
getOriginUrl() {
|
|
81
81
|
return this.window.location.origin;
|
|
82
82
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
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>;
|
|
@@ -0,0 +1,20 @@
|
|
|
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 common_1 = require("@ts-core/common");
|
|
14
|
+
const rxjs_1 = require("rxjs");
|
|
15
|
+
const OAuthBackendPropertiesSet = (item, redirectUri, method, timeout = common_1.DateUtil.MILLISECONDS_SECOND) => {
|
|
16
|
+
item.redirectUri = redirectUri;
|
|
17
|
+
item.popUpIsCheckClose = false;
|
|
18
|
+
item.popUpOpened.pipe((0, rxjs_1.delay)(timeout), (0, rxjs_1.takeUntil)(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () { return item.parsePopUpResult(yield method.call(this, item.state)); }));
|
|
19
|
+
};
|
|
20
|
+
exports.OAuthBackendPropertiesSet = OAuthBackendPropertiesSet;
|
|
@@ -0,0 +1,17 @@
|
|
|
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.popUpTarget = 'oauth:cordova';
|
|
8
|
+
item.redirectUri = `${packageName}://oauth_callback`;
|
|
9
|
+
item.popUpIsCheckClose = false;
|
|
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
|
+
}
|
package/cjs/public-api.d.ts
CHANGED
package/cjs/public-api.js
CHANGED
|
@@ -25,3 +25,5 @@ __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/backend"), exports);
|
|
29
|
+
__exportStar(require("./external/cordova"), exports);
|
package/esm/OAuthBase.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
8
8
|
popUpHeight: number;
|
|
9
9
|
popUpTarget: string;
|
|
10
10
|
popUpIsCheckClose: boolean;
|
|
11
|
-
popUpMessageParser:
|
|
11
|
+
popUpMessageParser: IOAuthPopUpParser;
|
|
12
12
|
redirectUri: string;
|
|
13
13
|
protected http: TransportHttp;
|
|
14
14
|
protected subject: Subject<ObservableData<OAuthEvent, Window>>;
|
|
@@ -25,7 +25,7 @@ export declare abstract class OAuthBase<T = any> extends LoggerWrapper {
|
|
|
25
25
|
protected getUrlParams(): URLSearchParams;
|
|
26
26
|
protected abstract getUrl(): string;
|
|
27
27
|
protected messageHandler: (event: MessageEvent) => void;
|
|
28
|
-
protected
|
|
28
|
+
protected browserInternalMessageHandler: IOAuthPopUpParser;
|
|
29
29
|
protected getOriginUrl(): string;
|
|
30
30
|
protected getRedirectUri(): string;
|
|
31
31
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
@@ -65,4 +65,4 @@ export declare enum OAuthEvent {
|
|
|
65
65
|
POPUP_OPENED = "POPUP_OPENED",
|
|
66
66
|
POPUP_CLOSED = "POPUP_CLOSED"
|
|
67
67
|
}
|
|
68
|
-
export type
|
|
68
|
+
export type IOAuthPopUpParser = (...params: any[]) => IOAuthPopUpDto;
|
package/esm/OAuthBase.js
CHANGED
|
@@ -21,13 +21,16 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
this.messageHandler = (event) => this.parsePopUpResult(this.popUpMessageParser(event));
|
|
24
|
+
this.browserInternalMessageHandler = (event) => {
|
|
25
|
+
return event.origin === this.getOriginUrl() && _.isObject(event.data) ? event.data : null;
|
|
26
|
+
};
|
|
24
27
|
this.http = new TransportHttp(logger, { method: 'get' });
|
|
25
28
|
this.subject = new Subject();
|
|
26
29
|
this.popUpWidth = 430;
|
|
27
30
|
this.popUpHeight = 520;
|
|
28
31
|
this.popUpTarget = '_blank';
|
|
29
32
|
this.popUpIsCheckClose = true;
|
|
30
|
-
this.popUpMessageParser = this.
|
|
33
|
+
this.popUpMessageParser = this.browserInternalMessageHandler;
|
|
31
34
|
this._urlParams = new Map();
|
|
32
35
|
this.urlParams.set('state', RandomUtil.randomString());
|
|
33
36
|
this.urlParams.set('display', 'popup');
|
|
@@ -71,9 +74,6 @@ export class OAuthBase extends LoggerWrapper {
|
|
|
71
74
|
this.urlParams.forEach((value, key) => item.append(key, value));
|
|
72
75
|
return item;
|
|
73
76
|
}
|
|
74
|
-
browserMessageHandler(event) {
|
|
75
|
-
return event.origin === this.getOriginUrl() && _.isObject(event.data) ? event.data : null;
|
|
76
|
-
}
|
|
77
77
|
getOriginUrl() {
|
|
78
78
|
return this.window.location.origin;
|
|
79
79
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
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>;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { DateUtil } from '@ts-core/common';
|
|
11
|
+
import { delay, takeUntil } from 'rxjs';
|
|
12
|
+
export const OAuthBackendPropertiesSet = (item, redirectUri, method, timeout = DateUtil.MILLISECONDS_SECOND) => {
|
|
13
|
+
item.redirectUri = redirectUri;
|
|
14
|
+
item.popUpIsCheckClose = false;
|
|
15
|
+
item.popUpOpened.pipe(delay(timeout), takeUntil(item.destroyed)).subscribe(() => __awaiter(void 0, void 0, void 0, function* () { return item.parsePopUpResult(yield method.call(this, item.state)); }));
|
|
16
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OAuthParser } from '../OAuthParser';
|
|
2
|
+
import * as _ from 'lodash';
|
|
3
|
+
export const OAuthCordovaPropertiesSet = (item, packageName) => {
|
|
4
|
+
item.popUpTarget = 'oauth:cordova';
|
|
5
|
+
item.redirectUri = `${packageName}://oauth_callback`;
|
|
6
|
+
item.popUpIsCheckClose = false;
|
|
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
|
+
}
|
package/esm/public-api.d.ts
CHANGED
package/esm/public-api.js
CHANGED