@ts-core/oauth 3.0.30 → 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 +6 -7
- 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 -6
- 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 -5
|
@@ -14,7 +14,7 @@ import { ExtendedError } from '@ts-core/common';
|
|
|
14
14
|
export const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, method) => {
|
|
15
15
|
item.redirectUri = redirectUri;
|
|
16
16
|
item.popUpOpener = popUpOpener;
|
|
17
|
-
item.
|
|
17
|
+
item.opened.pipe(takeUntil(item.destroyed)).subscribe((popUp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
let popUpClosedHandler = () => {
|
|
19
19
|
popUp.removeEventListener('exit', popUpClosedHandler);
|
|
20
20
|
popUp.removeEventListener('loadstop', popUpLoadedHandler);
|
|
@@ -28,24 +28,24 @@ export const OAuthCordovaInAppBrowserPluginPropertiesSet = (item, redirectUri, m
|
|
|
28
28
|
try {
|
|
29
29
|
data = yield method(item.state);
|
|
30
30
|
if (_.isEmpty(data)) {
|
|
31
|
-
data = {
|
|
31
|
+
data = { oauthError: OAuthBase.ERROR_WINDOW_CLOSED };
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
|
-
data = {
|
|
35
|
+
data = { oauthError: error.toString() };
|
|
36
36
|
}
|
|
37
|
-
item.
|
|
37
|
+
item.parse(data);
|
|
38
38
|
});
|
|
39
39
|
popUp.addEventListener('exit', popUpClosedHandler, false);
|
|
40
40
|
popUp.addEventListener('loadstop', popUpLoadedHandler, false);
|
|
41
41
|
}));
|
|
42
42
|
};
|
|
43
|
-
function popUpOpener(
|
|
44
|
-
let top = (window.screen.height -
|
|
45
|
-
let left = (window.screen.width -
|
|
43
|
+
function popUpOpener(popUp, window) {
|
|
44
|
+
let top = (window.screen.height - popUp.popUpHeight) / 2;
|
|
45
|
+
let left = (window.screen.width - popUp.popUpWidth) / 2;
|
|
46
46
|
let cordova = window['cordova'];
|
|
47
47
|
if (_.isNil(cordova) || _.isNil(cordova.InAppBrowser)) {
|
|
48
48
|
throw new ExtendedError(`Cordova InAppBrowser undefined, please check installed plugins`);
|
|
49
49
|
}
|
|
50
|
-
return cordova.InAppBrowser.open(
|
|
50
|
+
return cordova.InAppBrowser.open(popUp.popUpUrl(), popUp.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
51
51
|
}
|
|
@@ -3,21 +3,21 @@ import * as _ from 'lodash';
|
|
|
3
3
|
export const OAuthCordovaOAuthPluginPropertiesSet = (item, packageName) => {
|
|
4
4
|
item.popUpTarget = 'oauth:cordova';
|
|
5
5
|
item.popUpOpener = popUpOpener;
|
|
6
|
-
item.
|
|
6
|
+
item.popUpMessageEventParser = popUpMessageEventParser;
|
|
7
7
|
item.redirectUri = `${packageName}://oauth_callback`;
|
|
8
8
|
item.isRejectWhenPopUpClosed = false;
|
|
9
9
|
};
|
|
10
|
-
function popUpOpener(
|
|
11
|
-
let top = (window.screen.height -
|
|
12
|
-
let left = (window.screen.width -
|
|
13
|
-
let
|
|
14
|
-
if (!_.isNil(
|
|
15
|
-
return
|
|
10
|
+
function popUpOpener(popUp, window) {
|
|
11
|
+
let top = (window.screen.height - popUp.popUpHeight) / 2;
|
|
12
|
+
let left = (window.screen.width - popUp.popUpWidth) / 2;
|
|
13
|
+
let item = window.open(popUp.popUpUrl(), popUp.popUpTarget, `scrollbars=yes,width=${this.popUpWidth},height=${this.popUpHeight},top=${top},left=${left}`);
|
|
14
|
+
if (!_.isNil(item)) {
|
|
15
|
+
return item;
|
|
16
16
|
}
|
|
17
17
|
let fake = { close: () => { fake.closed = true; }, closed: false };
|
|
18
18
|
return fake;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function popUpMessageEventParser(event) {
|
|
21
21
|
let data = event.data;
|
|
22
22
|
let prefix = 'oauth::';
|
|
23
23
|
return _.isString(data) && data.includes(prefix) ? OAuthParser.parse(JSON.parse(data.substring(prefix.length)), '') : null;
|
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
|
+
popUpUrl(): 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
|
@@ -12,10 +12,10 @@ import { OAuthBase } from '../OAuthBase';
|
|
|
12
12
|
export class GoAuth extends OAuthBase {
|
|
13
13
|
constructor(logger, applicationId, window) {
|
|
14
14
|
super(logger, applicationId, window);
|
|
15
|
-
this.
|
|
15
|
+
this.params.set('scope', 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email');
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
return `https://accounts.google.com/o/oauth2/v2/auth?${this.
|
|
17
|
+
popUpUrl() {
|
|
18
|
+
return `https://accounts.google.com/o/oauth2/v2/auth?${this.getParams().toString()}`;
|
|
19
19
|
}
|
|
20
20
|
getProfile(token) {
|
|
21
21
|
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;
|
|
@@ -10,21 +10,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { ExtendedError, RandomUtil } from "@ts-core/common";
|
|
11
11
|
import { OAuthBase } from "../OAuthBase";
|
|
12
12
|
import { KeycloakUser } from "./KeycloakUser";
|
|
13
|
-
import { URLSearchParams } from "url";
|
|
14
13
|
import * as _ from 'lodash';
|
|
15
14
|
export class KeycloakAuth extends OAuthBase {
|
|
16
15
|
constructor(logger, settings, window) {
|
|
17
16
|
super(logger, settings.applicationId, window);
|
|
18
17
|
this._settings = settings;
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
18
|
+
this.params.set('scope', 'openid');
|
|
19
|
+
this.params.set('state', RandomUtil.randomString(10));
|
|
20
|
+
this.params.set('response_mode', 'query');
|
|
22
21
|
}
|
|
23
22
|
getBaseUrl() {
|
|
24
23
|
return `${this.settings.url}/realms/${this.settings.realm}/protocol/openid-connect`;
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
return `${this.getBaseUrl()}/auth?${this.
|
|
25
|
+
popUpUrl() {
|
|
26
|
+
return `${this.getBaseUrl()}/auth?${this.getParams().toString()}`;
|
|
28
27
|
}
|
|
29
28
|
getProfile(token) {
|
|
30
29
|
return __awaiter(this, void 0, void 0, function* () {
|
package/esm/ma/MaAuth.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
-
|
|
6
|
+
popUpUrl(): string;
|
|
7
7
|
getProfile(token: string): Promise<T>;
|
|
8
8
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
9
9
|
}
|
package/esm/ma/MaAuth.js
CHANGED
|
@@ -14,11 +14,11 @@ import * as _ from 'lodash';
|
|
|
14
14
|
export class MaAuth extends OAuthBase {
|
|
15
15
|
constructor(logger, applicationId, window) {
|
|
16
16
|
super(logger, applicationId, window);
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
17
|
+
this.params.set('scope', 'userinfo');
|
|
18
|
+
this.params.set('state', RandomUtil.randomString(43));
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
return `https://oauth.mail.ru/login?${this.
|
|
20
|
+
popUpUrl() {
|
|
21
|
+
return `https://oauth.mail.ru/login?${this.getParams().toString()}`;
|
|
22
22
|
}
|
|
23
23
|
getProfile(token) {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
package/esm/public-api.d.ts
CHANGED
package/esm/public-api.js
CHANGED
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
|
+
popUpUrl(): 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
|
@@ -15,10 +15,10 @@ export class VkAuth extends OAuthBase {
|
|
|
15
15
|
constructor(logger, applicationId, window) {
|
|
16
16
|
super(logger, applicationId, window);
|
|
17
17
|
this.v = '5.131';
|
|
18
|
-
this.
|
|
18
|
+
this.params.set('scope', 'status,email');
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
return `https://oauth.vk.com/authorize?${this.
|
|
20
|
+
popUpUrl() {
|
|
21
|
+
return `https://oauth.vk.com/authorize?${this.getParams().toString()}`;
|
|
22
22
|
}
|
|
23
23
|
getProfile(token, fields) {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
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
|
+
popUpUrl(): 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,8 +12,8 @@ import { OAuthBase } from "../OAuthBase";
|
|
|
12
12
|
import { YaUser } from "./YaUser";
|
|
13
13
|
import * as _ from 'lodash';
|
|
14
14
|
export class YaAuth extends OAuthBase {
|
|
15
|
-
|
|
16
|
-
return `https://oauth.yandex.ru/authorize?${this.
|
|
15
|
+
popUpUrl() {
|
|
16
|
+
return `https://oauth.yandex.ru/authorize?${this.getParams().toString()}`;
|
|
17
17
|
}
|
|
18
18
|
getProfile(token) {
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-core/oauth",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Classes and utils for oauth",
|
|
5
5
|
"main": "./cjs/public-api.js",
|
|
6
6
|
"module": "./esm/public-api.js",
|
|
@@ -17,10 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ts-core/common": "~3.0.
|
|
21
|
-
},
|
|
22
|
-
"peerDependencies": {
|
|
23
|
-
"url": "^0.11.0"
|
|
20
|
+
"@ts-core/common": "~3.0.43"
|
|
24
21
|
},
|
|
25
22
|
"devDependencies": {
|
|
26
23
|
"@types/node": "^14.14.31",
|