@ts-core/oauth 3.0.31 → 3.1.1
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 +12 -42
- package/cjs/OAuthBase.js +24 -116
- package/cjs/OAuthParser.js +10 -7
- package/cjs/PopUpBase.d.ts +45 -0
- package/cjs/PopUpBase.js +145 -0
- package/cjs/external/browser.d.ts +3 -0
- package/cjs/external/browser.js +10 -19
- package/cjs/external/cordovaInAppBrowserPlugin.js +8 -8
- package/cjs/external/cordovaOAuthPlugin.js +8 -8
- package/cjs/go/GoAuth.d.ts +1 -1
- package/cjs/go/GoAuth.js +3 -3
- package/cjs/keycloak/KeycloakAuth.d.ts +1 -1
- package/cjs/keycloak/KeycloakAuth.js +5 -5
- package/cjs/ma/MaAuth.d.ts +1 -1
- package/cjs/ma/MaAuth.js +4 -4
- package/cjs/public-api.d.ts +2 -1
- package/cjs/public-api.js +2 -1
- package/cjs/vk/VkAuth.d.ts +1 -1
- package/cjs/vk/VkAuth.js +3 -3
- package/cjs/ya/YaAuth.d.ts +1 -1
- package/cjs/ya/YaAuth.js +2 -2
- package/esm/OAuthBase.d.ts +12 -42
- package/esm/OAuthBase.js +24 -116
- package/esm/OAuthParser.js +10 -7
- package/esm/PopUpBase.d.ts +45 -0
- package/esm/PopUpBase.js +141 -0
- package/esm/external/browser.d.ts +3 -0
- package/esm/external/browser.js +7 -18
- package/esm/external/cordovaInAppBrowserPlugin.js +8 -8
- package/esm/external/cordovaOAuthPlugin.js +8 -8
- package/esm/go/GoAuth.d.ts +1 -1
- package/esm/go/GoAuth.js +3 -3
- package/esm/keycloak/KeycloakAuth.d.ts +1 -1
- package/esm/keycloak/KeycloakAuth.js +5 -5
- package/esm/ma/MaAuth.d.ts +1 -1
- package/esm/ma/MaAuth.js +4 -4
- package/esm/public-api.d.ts +2 -1
- package/esm/public-api.js +2 -1
- package/esm/vk/VkAuth.d.ts +1 -1
- package/esm/vk/VkAuth.js +3 -3
- package/esm/ya/YaAuth.d.ts +1 -1
- package/esm/ya/YaAuth.js +2 -2
- package/package.json +2 -2
package/cjs/OAuthBase.d.ts
CHANGED
|
@@ -1,56 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare abstract class OAuthBase<T = any> extends
|
|
1
|
+
import { ILogger, TransportHttp, ExtendedError } from "@ts-core/common";
|
|
2
|
+
import { PopUpBase } from "./PopUpBase";
|
|
3
|
+
export declare abstract class OAuthBase<T = any> extends PopUpBase<IOAuthDto> {
|
|
4
4
|
protected applicationId: string;
|
|
5
|
-
protected window?: Window;
|
|
6
|
-
static ERROR_WINDOW_CLOSED: string;
|
|
7
|
-
popUpWidth: number;
|
|
8
|
-
popUpHeight: number;
|
|
9
|
-
popUpTarget: string;
|
|
10
|
-
popUpOpener: IOAuthPopUpOpener;
|
|
11
|
-
popUpMessageParser: IOAuthPopUpMessageParser;
|
|
12
5
|
redirectUri: string;
|
|
13
|
-
isRejectWhenPopUpClosed: boolean;
|
|
14
6
|
protected http: TransportHttp;
|
|
15
|
-
protected subject: Subject<ObservableData<OAuthEvent, Window>>;
|
|
16
|
-
protected popUp: Window;
|
|
17
|
-
protected promise: PromiseHandler<IOAuthDto>;
|
|
18
7
|
protected responseType: string;
|
|
19
|
-
protected _urlParams: Map<string, string>;
|
|
20
|
-
protected _popUpCheckCloseTimer: any;
|
|
21
8
|
constructor(logger: ILogger, applicationId: string, window?: Window);
|
|
22
|
-
protected
|
|
23
|
-
protected
|
|
24
|
-
protected
|
|
25
|
-
protected
|
|
26
|
-
protected
|
|
27
|
-
protected popUpMessageHandler: (event: MessageEvent) => void;
|
|
28
|
-
abstract getPopUpUrl(): string;
|
|
29
|
-
getOriginUrl(): string;
|
|
30
|
-
getRedirectUri(): string;
|
|
9
|
+
protected getRedirectUri(): string;
|
|
10
|
+
protected getParams(): URLSearchParams;
|
|
11
|
+
protected parseMessageData(item: any): IOAuthDto;
|
|
12
|
+
protected isMessageError(item: any): boolean;
|
|
13
|
+
protected parseMessageError(item: any): ExtendedError;
|
|
31
14
|
abstract getProfile(token: string, ...params: any[]): Promise<T>;
|
|
32
15
|
abstract getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
33
|
-
parseResponse(data: IOAuthPopUpDto): void;
|
|
34
16
|
getCode(): Promise<IOAuthDto>;
|
|
35
17
|
getToken(): Promise<IOAuthDto>;
|
|
36
|
-
|
|
18
|
+
parse(item: any): void;
|
|
37
19
|
destroy(): void;
|
|
38
|
-
protected get isPopUpOpened(): boolean;
|
|
39
|
-
protected get popUpCheckCloseTimer(): any;
|
|
40
|
-
protected set popUpCheckCloseTimer(value: any);
|
|
41
|
-
get urlParams(): Map<string, string>;
|
|
42
20
|
get state(): string;
|
|
43
|
-
get events(): Observable<ObservableData<OAuthEvent, Window>>;
|
|
44
|
-
get popUpClosed(): Observable<Window>;
|
|
45
|
-
get popUpOpened(): Observable<Window>;
|
|
46
21
|
}
|
|
47
22
|
export interface IOAuthDto {
|
|
48
23
|
codeOrToken: string;
|
|
49
24
|
redirectUri: string;
|
|
50
25
|
}
|
|
51
26
|
export interface IOAuthPopUpDto {
|
|
52
|
-
|
|
53
|
-
|
|
27
|
+
oauthError?: string;
|
|
28
|
+
oauthCodeOrToken?: string;
|
|
29
|
+
oauthErrorDescription?: string;
|
|
54
30
|
}
|
|
55
31
|
export interface IOAuthToken {
|
|
56
32
|
expiresIn: number;
|
|
@@ -63,9 +39,3 @@ export interface IOAuthToken {
|
|
|
63
39
|
refreshToken?: string;
|
|
64
40
|
refreshExpiresIn?: string;
|
|
65
41
|
}
|
|
66
|
-
export declare enum OAuthEvent {
|
|
67
|
-
POPUP_OPENED = "POPUP_OPENED",
|
|
68
|
-
POPUP_CLOSED = "POPUP_CLOSED"
|
|
69
|
-
}
|
|
70
|
-
export type IOAuthPopUpOpener = <T extends OAuthBase>(item: T, window: Window) => Window;
|
|
71
|
-
export type IOAuthPopUpMessageParser = <T extends OAuthBase>(item: T, event: MessageEvent) => IOAuthPopUpDto;
|
package/cjs/OAuthBase.js
CHANGED
|
@@ -9,80 +9,43 @@ 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.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
|
|
17
|
-
|
|
16
|
+
const PopUpBase_1 = require("./PopUpBase");
|
|
17
|
+
const public_api_1 = require("./public-api");
|
|
18
|
+
class OAuthBase extends PopUpBase_1.PopUpBase {
|
|
18
19
|
constructor(logger, applicationId, window) {
|
|
19
|
-
super(logger);
|
|
20
|
+
super(logger, window);
|
|
20
21
|
this.applicationId = applicationId;
|
|
21
|
-
this.window = window;
|
|
22
|
-
this.popUpCheckClose = () => {
|
|
23
|
-
if (!this.isPopUpOpened) {
|
|
24
|
-
this.close();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
this.popUpOpenHandler = () => this.popUpOpener(this, this.window);
|
|
28
|
-
this.popUpMessageHandler = (event) => this.parseResponse(this.popUpMessageParser(this, event));
|
|
29
22
|
this.http = new common_1.TransportHttp(logger, { method: 'get' });
|
|
30
23
|
this.subject = new rxjs_1.Subject();
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
this
|
|
34
|
-
this._urlParams = new Map();
|
|
35
|
-
this.urlParams.set('state', common_1.RandomUtil.randomString());
|
|
36
|
-
this.urlParams.set('display', 'popup');
|
|
37
|
-
(0, external_1.OAuthBrowserPropertiesSet)(this);
|
|
38
|
-
}
|
|
39
|
-
open() {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
if (!_.isNil(this.promise)) {
|
|
42
|
-
this.popUpFocus();
|
|
43
|
-
return this.promise.promise;
|
|
44
|
-
}
|
|
45
|
-
this.promise = common_1.PromiseHandler.create();
|
|
46
|
-
this.popUp = this.popUpOpenHandler();
|
|
47
|
-
this.popUpFocus();
|
|
48
|
-
this.window.addEventListener('message', this.popUpMessageHandler, false);
|
|
49
|
-
this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_OPENED, this.popUp));
|
|
50
|
-
this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, common_1.DateUtil.MILLISECONDS_SECOND / 5);
|
|
51
|
-
return this.promise.promise;
|
|
52
|
-
});
|
|
24
|
+
this.params.set('state', common_1.RandomUtil.randomString());
|
|
25
|
+
this.params.set('display', 'popup');
|
|
26
|
+
(0, public_api_1.OAuthBrowserPropertiesSet)(this);
|
|
53
27
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.popUp.focus();
|
|
57
|
-
}
|
|
28
|
+
getRedirectUri() {
|
|
29
|
+
return !_.isNil(this.redirectUri) ? this.redirectUri : `${this.originUrl}/oauth`;
|
|
58
30
|
}
|
|
59
|
-
|
|
60
|
-
let item =
|
|
31
|
+
getParams() {
|
|
32
|
+
let item = super.getParams();
|
|
61
33
|
item.append('client_id', this.applicationId);
|
|
62
34
|
item.append('redirect_uri', this.getRedirectUri());
|
|
63
35
|
item.append('response_type', this.responseType);
|
|
64
|
-
this.urlParams.forEach((value, key) => item.append(key, value));
|
|
65
36
|
return item;
|
|
66
37
|
}
|
|
67
|
-
|
|
68
|
-
return
|
|
38
|
+
parseMessageData(item) {
|
|
39
|
+
return {
|
|
40
|
+
codeOrToken: item.oauthCodeOrToken,
|
|
41
|
+
redirectUri: this.getRedirectUri()
|
|
42
|
+
};
|
|
69
43
|
}
|
|
70
|
-
|
|
71
|
-
return !_.isNil(
|
|
44
|
+
isMessageError(item) {
|
|
45
|
+
return !_.isNil(item.oauthError);
|
|
72
46
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (!_.isEmpty(data.oAuthCodeOrToken)) {
|
|
78
|
-
this.promise.resolve({ redirectUri: this.getRedirectUri(), codeOrToken: data.oAuthCodeOrToken });
|
|
79
|
-
this.promise = null;
|
|
80
|
-
}
|
|
81
|
-
if (!_.isEmpty(data.oAuthError)) {
|
|
82
|
-
this.promise.reject(data.oAuthError);
|
|
83
|
-
this.promise = null;
|
|
84
|
-
}
|
|
85
|
-
this.close();
|
|
47
|
+
parseMessageError(item) {
|
|
48
|
+
return new common_1.ExtendedError(item.oauthError, item.oauthErrorDescription);
|
|
86
49
|
}
|
|
87
50
|
getCode() {
|
|
88
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -96,76 +59,21 @@ class OAuthBase extends common_1.LoggerWrapper {
|
|
|
96
59
|
return this.open();
|
|
97
60
|
});
|
|
98
61
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.popUpCheckCloseTimer = null;
|
|
102
|
-
if (_.isNil(this.popUp)) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
this.subject.next(new common_1.ObservableData(OAuthEvent.POPUP_CLOSED, this.popUp));
|
|
106
|
-
this.popUp.close();
|
|
107
|
-
this.popUp = null;
|
|
108
|
-
if (this.isRejectWhenPopUpClosed && !_.isNil(this.promise)) {
|
|
109
|
-
this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
|
|
110
|
-
this.promise = null;
|
|
111
|
-
}
|
|
62
|
+
parse(item) {
|
|
63
|
+
super.popUpMessageParse(item);
|
|
112
64
|
}
|
|
113
65
|
destroy() {
|
|
114
66
|
if (this.isDestroyed) {
|
|
115
67
|
return;
|
|
116
68
|
}
|
|
117
69
|
super.destroy();
|
|
118
|
-
this.close();
|
|
119
|
-
if (!_.isNil(this.promise)) {
|
|
120
|
-
this.promise.reject(OAuthBase.ERROR_WINDOW_CLOSED);
|
|
121
|
-
this.promise = null;
|
|
122
|
-
}
|
|
123
|
-
if (!_.isNil(this.urlParams)) {
|
|
124
|
-
this.urlParams.clear();
|
|
125
|
-
this._urlParams = null;
|
|
126
|
-
}
|
|
127
70
|
if (!_.isNil(this.http)) {
|
|
128
71
|
this.http.destroy();
|
|
129
72
|
this.http = null;
|
|
130
73
|
}
|
|
131
|
-
if (!_.isNil(this.subject)) {
|
|
132
|
-
this.subject.complete();
|
|
133
|
-
this.subject = null;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
get isPopUpOpened() {
|
|
137
|
-
return !_.isNil(this.popUp) && !this.popUp.closed;
|
|
138
|
-
}
|
|
139
|
-
get popUpCheckCloseTimer() {
|
|
140
|
-
return this._popUpCheckCloseTimer;
|
|
141
|
-
}
|
|
142
|
-
set popUpCheckCloseTimer(value) {
|
|
143
|
-
if (value === this._popUpCheckCloseTimer) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
clearInterval(this._popUpCheckCloseTimer);
|
|
147
|
-
this._popUpCheckCloseTimer = value;
|
|
148
|
-
}
|
|
149
|
-
get urlParams() {
|
|
150
|
-
return this._urlParams;
|
|
151
74
|
}
|
|
152
75
|
get state() {
|
|
153
|
-
return !_.isNil(this.
|
|
154
|
-
}
|
|
155
|
-
get events() {
|
|
156
|
-
return !_.isNil(this.subject) ? this.subject.asObservable() : null;
|
|
157
|
-
}
|
|
158
|
-
get popUpClosed() {
|
|
159
|
-
return this.events.pipe((0, rxjs_1.filter)(item => item.type === OAuthEvent.POPUP_CLOSED), (0, rxjs_1.map)(item => item.data));
|
|
160
|
-
}
|
|
161
|
-
get popUpOpened() {
|
|
162
|
-
return this.events.pipe((0, rxjs_1.filter)(item => item.type === OAuthEvent.POPUP_OPENED), (0, rxjs_1.map)(item => item.data));
|
|
76
|
+
return !_.isNil(this.params) ? this.params.get('state') : null;
|
|
163
77
|
}
|
|
164
78
|
}
|
|
165
79
|
exports.OAuthBase = OAuthBase;
|
|
166
|
-
OAuthBase.ERROR_WINDOW_CLOSED = 'WINDOW_CLOSED';
|
|
167
|
-
var OAuthEvent;
|
|
168
|
-
(function (OAuthEvent) {
|
|
169
|
-
OAuthEvent["POPUP_OPENED"] = "POPUP_OPENED";
|
|
170
|
-
OAuthEvent["POPUP_CLOSED"] = "POPUP_CLOSED";
|
|
171
|
-
})(OAuthEvent = exports.OAuthEvent || (exports.OAuthEvent = {}));
|
package/cjs/OAuthParser.js
CHANGED
|
@@ -9,18 +9,21 @@ class OAuthParser {
|
|
|
9
9
|
if (!_.isEmpty(fragment)) {
|
|
10
10
|
new URLSearchParams(fragment).forEach((value, key) => item[key] = value);
|
|
11
11
|
}
|
|
12
|
-
let
|
|
13
|
-
let
|
|
12
|
+
let oauthError = null;
|
|
13
|
+
let oauthCodeOrToken = null;
|
|
14
14
|
for (let key in item) {
|
|
15
15
|
let value = item[key];
|
|
16
16
|
if (OAuthParser.NAMES.includes(key)) {
|
|
17
|
-
|
|
17
|
+
oauthCodeOrToken = value;
|
|
18
18
|
}
|
|
19
19
|
else if (OAuthParser.ERRORS.includes(key)) {
|
|
20
|
-
|
|
20
|
+
oauthError = value;
|
|
21
21
|
}
|
|
22
|
-
if (!_.isEmpty(
|
|
23
|
-
return {
|
|
22
|
+
if (!_.isEmpty(oauthCodeOrToken)) {
|
|
23
|
+
return { oauthCodeOrToken };
|
|
24
|
+
}
|
|
25
|
+
else if (!_.isEmpty(oauthError)) {
|
|
26
|
+
return { oauthErrorDescription: item.error_description, oauthError };
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
;
|
|
@@ -29,4 +32,4 @@ class OAuthParser {
|
|
|
29
32
|
}
|
|
30
33
|
exports.OAuthParser = OAuthParser;
|
|
31
34
|
OAuthParser.NAMES = ['code', 'access_token'];
|
|
32
|
-
OAuthParser.ERRORS = ['
|
|
35
|
+
OAuthParser.ERRORS = ['error', 'error_description'];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PromiseHandler, ObservableData, LoggerWrapper, ILogger, ExtendedError } from "@ts-core/common";
|
|
2
|
+
import { Observable, Subject } from "rxjs";
|
|
3
|
+
export declare abstract class PopUpBase<U> extends LoggerWrapper {
|
|
4
|
+
static ERROR_WINDOW_CLOSED: string;
|
|
5
|
+
popUpWidth: number;
|
|
6
|
+
popUpHeight: number;
|
|
7
|
+
popUpTarget: string;
|
|
8
|
+
popUpOpener: IPopUpOpener;
|
|
9
|
+
popUpMessageEventParser: IPopUpMessageEventParser;
|
|
10
|
+
protected popUp: Window;
|
|
11
|
+
protected window: Window;
|
|
12
|
+
protected subject: Subject<ObservableData<PopUpEvent, Window>>;
|
|
13
|
+
protected promise: PromiseHandler<U, ExtendedError>;
|
|
14
|
+
protected _params: Map<string, string>;
|
|
15
|
+
protected _popUpCheckCloseTimer: any;
|
|
16
|
+
isRejectWhenPopUpClosed: boolean;
|
|
17
|
+
constructor(logger: ILogger, window?: Window);
|
|
18
|
+
protected popUpFocus(): void;
|
|
19
|
+
protected popUpCheckClose: () => void;
|
|
20
|
+
protected getParams(): URLSearchParams;
|
|
21
|
+
protected popUpMessageHandler(event: MessageEvent): void;
|
|
22
|
+
protected popUpMessageParse(item: any): void;
|
|
23
|
+
protected popUpMessageHandlerProxy: (event: MessageEvent) => void;
|
|
24
|
+
protected abstract isMessageError(item: any): boolean;
|
|
25
|
+
protected abstract parseMessageData(item: any): U;
|
|
26
|
+
protected abstract parseMessageError(item: any): ExtendedError;
|
|
27
|
+
open(...params: any[]): Promise<U>;
|
|
28
|
+
close(): void;
|
|
29
|
+
destroy(): void;
|
|
30
|
+
abstract popUpUrl(): string;
|
|
31
|
+
protected get isPopUpOpened(): boolean;
|
|
32
|
+
protected get popUpCheckCloseTimer(): any;
|
|
33
|
+
protected set popUpCheckCloseTimer(value: any);
|
|
34
|
+
get originUrl(): string;
|
|
35
|
+
get params(): Map<string, string>;
|
|
36
|
+
get events(): Observable<ObservableData<PopUpEvent, Window>>;
|
|
37
|
+
get closed(): Observable<Window>;
|
|
38
|
+
get opened(): Observable<Window>;
|
|
39
|
+
}
|
|
40
|
+
export type IPopUpOpener = <T extends PopUpBase<U>, U>(popUp: T, window: Window) => Window;
|
|
41
|
+
export type IPopUpMessageEventParser = (event: MessageEvent) => any;
|
|
42
|
+
export declare enum PopUpEvent {
|
|
43
|
+
OPENED = "OPENED",
|
|
44
|
+
CLOSED = "CLOSED"
|
|
45
|
+
}
|
package/cjs/PopUpBase.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
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.PopUpEvent = exports.PopUpBase = void 0;
|
|
13
|
+
const common_1 = require("@ts-core/common");
|
|
14
|
+
const rxjs_1 = require("rxjs");
|
|
15
|
+
const external_1 = require("./external");
|
|
16
|
+
const _ = require("lodash");
|
|
17
|
+
class PopUpBase extends common_1.LoggerWrapper {
|
|
18
|
+
constructor(logger, window) {
|
|
19
|
+
super(logger);
|
|
20
|
+
this.popUpCheckClose = () => {
|
|
21
|
+
if (!this.isPopUpOpened) {
|
|
22
|
+
this.close();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
this.popUpMessageHandlerProxy = (event) => this.popUpMessageHandler(event);
|
|
26
|
+
this.window = window;
|
|
27
|
+
this.subject = new rxjs_1.Subject();
|
|
28
|
+
this._params = new Map();
|
|
29
|
+
this.popUpWidth = 430;
|
|
30
|
+
this.popUpHeight = 520;
|
|
31
|
+
this.popUpTarget = '_blank';
|
|
32
|
+
this.popUpOpener = external_1.popUpOpener;
|
|
33
|
+
this.isRejectWhenPopUpClosed = true;
|
|
34
|
+
}
|
|
35
|
+
popUpFocus() {
|
|
36
|
+
if (this.isPopUpOpened && _.isFunction(this.popUp.focus)) {
|
|
37
|
+
this.popUp.focus();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
getParams() {
|
|
41
|
+
let item = new URLSearchParams();
|
|
42
|
+
this.params.forEach((value, key) => item.append(key, value));
|
|
43
|
+
return item;
|
|
44
|
+
}
|
|
45
|
+
popUpMessageHandler(event) {
|
|
46
|
+
if (event.origin === this.originUrl && !_.isNil(event.data)) {
|
|
47
|
+
this.popUpMessageParse(this.popUpMessageEventParser(event));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
popUpMessageParse(item) {
|
|
51
|
+
if (_.isNil(item)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (this.isMessageError(item)) {
|
|
55
|
+
this.promise.reject(this.parseMessageError(item));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.promise.resolve(this.parseMessageData(item));
|
|
59
|
+
}
|
|
60
|
+
this.close();
|
|
61
|
+
}
|
|
62
|
+
open(...params) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
if (!_.isNil(this.promise)) {
|
|
65
|
+
this.popUpFocus();
|
|
66
|
+
return this.promise.promise;
|
|
67
|
+
}
|
|
68
|
+
this.promise = common_1.PromiseHandler.create();
|
|
69
|
+
this.popUp = this.popUpOpener(this, this.window);
|
|
70
|
+
this.popUpFocus();
|
|
71
|
+
this.window.addEventListener('message', this.popUpMessageHandlerProxy, false);
|
|
72
|
+
this.subject.next(new common_1.ObservableData(PopUpEvent.OPENED, this.popUp));
|
|
73
|
+
this.popUpCheckCloseTimer = setInterval(this.popUpCheckClose, common_1.DateUtil.MILLISECONDS_SECOND / 5);
|
|
74
|
+
return this.promise.promise;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
close() {
|
|
78
|
+
this.window.removeEventListener('message', this.popUpMessageHandlerProxy, false);
|
|
79
|
+
this.popUpCheckCloseTimer = null;
|
|
80
|
+
if (_.isNil(this.popUp)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.subject.next(new common_1.ObservableData(PopUpEvent.CLOSED, this.popUp));
|
|
84
|
+
this.popUp.close();
|
|
85
|
+
this.popUp = null;
|
|
86
|
+
if (this.isRejectWhenPopUpClosed && !_.isNil(this.promise)) {
|
|
87
|
+
this.promise.reject(new common_1.ExtendedError(PopUpBase.ERROR_WINDOW_CLOSED, PopUpBase.ERROR_WINDOW_CLOSED));
|
|
88
|
+
this.promise = null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
destroy() {
|
|
92
|
+
if (this.isDestroyed) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
super.destroy();
|
|
96
|
+
this.close();
|
|
97
|
+
if (!_.isNil(this.promise)) {
|
|
98
|
+
this.promise.reject(new common_1.ExtendedError(PopUpBase.ERROR_WINDOW_CLOSED, PopUpBase.ERROR_WINDOW_CLOSED));
|
|
99
|
+
this.promise = null;
|
|
100
|
+
}
|
|
101
|
+
if (!_.isNil(this.params)) {
|
|
102
|
+
this.params.clear();
|
|
103
|
+
this._params = null;
|
|
104
|
+
}
|
|
105
|
+
if (!_.isNil(this.subject)) {
|
|
106
|
+
this.subject.complete();
|
|
107
|
+
this.subject = null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
get isPopUpOpened() {
|
|
111
|
+
return !_.isNil(this.popUp) && !this.popUp.closed;
|
|
112
|
+
}
|
|
113
|
+
get popUpCheckCloseTimer() {
|
|
114
|
+
return this._popUpCheckCloseTimer;
|
|
115
|
+
}
|
|
116
|
+
set popUpCheckCloseTimer(value) {
|
|
117
|
+
if (value === this._popUpCheckCloseTimer) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
clearInterval(this._popUpCheckCloseTimer);
|
|
121
|
+
this._popUpCheckCloseTimer = value;
|
|
122
|
+
}
|
|
123
|
+
get originUrl() {
|
|
124
|
+
return this.window.location.origin;
|
|
125
|
+
}
|
|
126
|
+
get params() {
|
|
127
|
+
return this._params;
|
|
128
|
+
}
|
|
129
|
+
get events() {
|
|
130
|
+
return !_.isNil(this.subject) ? this.subject.asObservable() : null;
|
|
131
|
+
}
|
|
132
|
+
get closed() {
|
|
133
|
+
return this.events.pipe((0, rxjs_1.filter)(item => item.type === PopUpEvent.CLOSED), (0, rxjs_1.map)(item => item.data));
|
|
134
|
+
}
|
|
135
|
+
get opened() {
|
|
136
|
+
return this.events.pipe((0, rxjs_1.filter)(item => item.type === PopUpEvent.OPENED), (0, rxjs_1.map)(item => item.data));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.PopUpBase = PopUpBase;
|
|
140
|
+
PopUpBase.ERROR_WINDOW_CLOSED = 'WINDOW_CLOSED';
|
|
141
|
+
var PopUpEvent;
|
|
142
|
+
(function (PopUpEvent) {
|
|
143
|
+
PopUpEvent["OPENED"] = "OPENED";
|
|
144
|
+
PopUpEvent["CLOSED"] = "CLOSED";
|
|
145
|
+
})(PopUpEvent = exports.PopUpEvent || (exports.PopUpEvent = {}));
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { OAuthBase } from '../OAuthBase';
|
|
2
|
+
import { PopUpBase } from '../PopUpBase';
|
|
2
3
|
export declare const OAuthBrowserPropertiesSet: (item: OAuthBase) => void;
|
|
4
|
+
export declare function popUpOpener<T extends PopUpBase<U>, U>(popUp: T, window: Window): Window;
|
|
5
|
+
export declare function popUpMessageEventParser(event: MessageEvent): any;
|
package/cjs/external/browser.js
CHANGED
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OAuthBrowserPropertiesSet = void 0;
|
|
3
|
+
exports.popUpMessageEventParser = exports.popUpOpener = exports.OAuthBrowserPropertiesSet = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
|
-
const common_1 = require("@ts-core/common");
|
|
6
5
|
const OAuthBrowserPropertiesSet = (item) => {
|
|
7
6
|
item.popUpOpener = popUpOpener;
|
|
8
|
-
item.
|
|
7
|
+
item.popUpMessageEventParser = popUpMessageEventParser;
|
|
9
8
|
item.isRejectWhenPopUpClosed = true;
|
|
10
9
|
};
|
|
11
10
|
exports.OAuthBrowserPropertiesSet = OAuthBrowserPropertiesSet;
|
|
12
|
-
function popUpOpener(
|
|
13
|
-
let top = (window.screen.height -
|
|
14
|
-
let left = (window.screen.width -
|
|
15
|
-
return window.open(
|
|
11
|
+
function popUpOpener(popUp, window) {
|
|
12
|
+
let top = (window.screen.height - popUp.popUpHeight) / 2;
|
|
13
|
+
let left = (window.screen.width - popUp.popUpWidth) / 2;
|
|
14
|
+
return window.open(popUp.popUpUrl(), popUp.popUpTarget, `scrollbars=yes,width=${popUp.popUpWidth},height=${popUp.popUpHeight},top=${top},left=${left}`);
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
16
|
+
exports.popUpOpener = popUpOpener;
|
|
17
|
+
function popUpMessageEventParser(event) {
|
|
18
|
+
return !_.isNil(event.data.oauthError) || !_.isNil(event.data.oauthCodeOrToken) ? event.data : null;
|
|
29
19
|
}
|
|
20
|
+
exports.popUpMessageEventParser = popUpMessageEventParser;
|
|
@@ -17,7 +17,7 @@ const common_1 = require("@ts-core/common");
|
|
|
17
17
|
const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method) => {
|
|
18
18
|
item.redirectUri = redirectUri;
|
|
19
19
|
item.popUpOpener = popUpOpener;
|
|
20
|
-
item.
|
|
20
|
+
item.opened.pipe((0, rxjs_1.takeUntil)(item.destroyed)).subscribe((popUp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
21
|
let popUpClosedHandler = () => {
|
|
22
22
|
popUp.removeEventListener('exit', popUpClosedHandler);
|
|
23
23
|
popUp.removeEventListener('loadstop', popUpLoadedHandler);
|
|
@@ -31,25 +31,25 @@ const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method)
|
|
|
31
31
|
try {
|
|
32
32
|
data = yield method(item.state);
|
|
33
33
|
if (_.isEmpty(data)) {
|
|
34
|
-
data = {
|
|
34
|
+
data = { oauthError: OAuthBase_1.OAuthBase.ERROR_WINDOW_CLOSED };
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
|
38
|
-
data = {
|
|
38
|
+
data = { oauthError: error.toString() };
|
|
39
39
|
}
|
|
40
|
-
item.
|
|
40
|
+
item.parse(data);
|
|
41
41
|
});
|
|
42
42
|
popUp.addEventListener('exit', popUpClosedHandler, false);
|
|
43
43
|
popUp.addEventListener('loadstop', popUpLoadedHandler, false);
|
|
44
44
|
}));
|
|
45
45
|
};
|
|
46
46
|
exports.OAuthCordovaInAppBrowserPluginPropertiesSet = OAuthCordovaInAppBrowserPluginPropertiesSet;
|
|
47
|
-
function popUpOpener(
|
|
48
|
-
let top = (window.screen.height -
|
|
49
|
-
let left = (window.screen.width -
|
|
47
|
+
function popUpOpener(popUp, window) {
|
|
48
|
+
let top = (window.screen.height - popUp.popUpHeight) / 2;
|
|
49
|
+
let left = (window.screen.width - popUp.popUpWidth) / 2;
|
|
50
50
|
let cordova = window['cordova'];
|
|
51
51
|
if (_.isNil(cordova) || _.isNil(cordova.InAppBrowser)) {
|
|
52
52
|
throw new common_1.ExtendedError(`Cordova InAppBrowser undefined, please check installed plugins`);
|
|
53
53
|
}
|
|
54
|
-
return cordova.InAppBrowser.open(
|
|
54
|
+
return cordova.InAppBrowser.open(popUp.popUpUrl(), popUp.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
55
55
|
}
|
|
@@ -6,22 +6,22 @@ const _ = require("lodash");
|
|
|
6
6
|
const OAuthCordovaOAuthPluginPropertiesSet = (item, packageName) => {
|
|
7
7
|
item.popUpTarget = 'oauth:cordova';
|
|
8
8
|
item.popUpOpener = popUpOpener;
|
|
9
|
-
item.
|
|
9
|
+
item.popUpMessageEventParser = popUpMessageEventParser;
|
|
10
10
|
item.redirectUri = `${packageName}://oauth_callback`;
|
|
11
11
|
item.isRejectWhenPopUpClosed = false;
|
|
12
12
|
};
|
|
13
13
|
exports.OAuthCordovaOAuthPluginPropertiesSet = OAuthCordovaOAuthPluginPropertiesSet;
|
|
14
|
-
function popUpOpener(
|
|
15
|
-
let top = (window.screen.height -
|
|
16
|
-
let left = (window.screen.width -
|
|
17
|
-
let
|
|
18
|
-
if (!_.isNil(
|
|
19
|
-
return
|
|
14
|
+
function popUpOpener(popUp, window) {
|
|
15
|
+
let top = (window.screen.height - popUp.popUpHeight) / 2;
|
|
16
|
+
let left = (window.screen.width - popUp.popUpWidth) / 2;
|
|
17
|
+
let item = window.open(popUp.popUpUrl(), popUp.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
18
|
+
if (!_.isNil(item)) {
|
|
19
|
+
return item;
|
|
20
20
|
}
|
|
21
21
|
let fake = { close: () => { fake.closed = true; }, closed: false };
|
|
22
22
|
return fake;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function popUpMessageEventParser(event) {
|
|
25
25
|
let data = event.data;
|
|
26
26
|
let prefix = 'oauth::';
|
|
27
27
|
return _.isString(data) && data.includes(prefix) ? OAuthParser_1.OAuthParser.parse(JSON.parse(data.substring(prefix.length)), '') : null;
|
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
|
+
popUpUrl(): 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
|
@@ -15,10 +15,10 @@ const OAuthBase_1 = require("../OAuthBase");
|
|
|
15
15
|
class GoAuth extends OAuthBase_1.OAuthBase {
|
|
16
16
|
constructor(logger, applicationId, window) {
|
|
17
17
|
super(logger, applicationId, window);
|
|
18
|
-
this.
|
|
18
|
+
this.params.set('scope', 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email');
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
return `https://accounts.google.com/o/oauth2/v2/auth?${this.
|
|
20
|
+
popUpUrl() {
|
|
21
|
+
return `https://accounts.google.com/o/oauth2/v2/auth?${this.getParams().toString()}`;
|
|
22
22
|
}
|
|
23
23
|
getProfile(token) {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -5,7 +5,7 @@ export declare class KeycloakAuth<T extends KeycloakUser = KeycloakUser> extends
|
|
|
5
5
|
protected _settings: IKeycloakAuthSettings;
|
|
6
6
|
constructor(logger: ILogger, settings: IKeycloakAuthSettings, window?: Window);
|
|
7
7
|
protected getBaseUrl(): string;
|
|
8
|
-
|
|
8
|
+
popUpUrl(): string;
|
|
9
9
|
getProfile(token: string): Promise<T>;
|
|
10
10
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
11
11
|
destroy(): void;
|
|
@@ -18,15 +18,15 @@ class KeycloakAuth extends OAuthBase_1.OAuthBase {
|
|
|
18
18
|
constructor(logger, settings, window) {
|
|
19
19
|
super(logger, settings.applicationId, window);
|
|
20
20
|
this._settings = settings;
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
21
|
+
this.params.set('scope', 'openid');
|
|
22
|
+
this.params.set('state', common_1.RandomUtil.randomString(10));
|
|
23
|
+
this.params.set('response_mode', 'query');
|
|
24
24
|
}
|
|
25
25
|
getBaseUrl() {
|
|
26
26
|
return `${this.settings.url}/realms/${this.settings.realm}/protocol/openid-connect`;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
return `${this.getBaseUrl()}/auth?${this.
|
|
28
|
+
popUpUrl() {
|
|
29
|
+
return `${this.getBaseUrl()}/auth?${this.getParams().toString()}`;
|
|
30
30
|
}
|
|
31
31
|
getProfile(token) {
|
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|