@ts-core/oauth 3.0.28 → 3.0.30
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/keycloak/{KeyCloakAuth.d.ts → KeycloakAuth.d.ts} +6 -6
- package/cjs/keycloak/{KeyCloakAuth.js → KeycloakAuth.js} +13 -9
- package/cjs/keycloak/KeycloakUser.d.ts +8 -0
- package/cjs/keycloak/KeycloakUser.js +16 -0
- package/cjs/public-api.d.ts +2 -2
- package/cjs/public-api.js +2 -2
- package/esm/keycloak/{KeyCloakAuth.d.ts → KeycloakAuth.d.ts} +6 -6
- package/esm/keycloak/{KeyCloakAuth.js → KeycloakAuth.js} +11 -7
- package/esm/keycloak/KeycloakUser.d.ts +8 -0
- package/esm/keycloak/KeycloakUser.js +12 -0
- package/esm/public-api.d.ts +2 -2
- package/esm/public-api.js +2 -2
- package/package.json +4 -1
- package/cjs/keycloak/KeyCloakUser.d.ts +0 -8
- package/cjs/keycloak/KeyCloakUser.js +0 -18
- package/esm/keycloak/KeyCloakUser.d.ts +0 -8
- package/esm/keycloak/KeyCloakUser.js +0 -14
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { ILogger } from "@ts-core/common";
|
|
2
2
|
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
3
|
-
import {
|
|
4
|
-
export declare class
|
|
5
|
-
protected _settings:
|
|
6
|
-
constructor(logger: ILogger, settings:
|
|
3
|
+
import { KeycloakUser } from "./KeycloakUser";
|
|
4
|
+
export declare class KeycloakAuth<T extends KeycloakUser = KeycloakUser> extends OAuthBase<T> {
|
|
5
|
+
protected _settings: IKeycloakAuthSettings;
|
|
6
|
+
constructor(logger: ILogger, settings: IKeycloakAuthSettings, window?: Window);
|
|
7
7
|
protected getBaseUrl(): string;
|
|
8
8
|
getPopUpUrl(): string;
|
|
9
9
|
getProfile(token: string): Promise<T>;
|
|
10
10
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
11
11
|
destroy(): void;
|
|
12
|
-
get settings():
|
|
12
|
+
get settings(): IKeycloakAuthSettings;
|
|
13
13
|
}
|
|
14
|
-
export interface
|
|
14
|
+
export interface IKeycloakAuthSettings {
|
|
15
15
|
url: string;
|
|
16
16
|
realm: string;
|
|
17
17
|
applicationId: string;
|
|
@@ -9,17 +9,19 @@ 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.KeycloakAuth = void 0;
|
|
13
13
|
const common_1 = require("@ts-core/common");
|
|
14
|
-
const _ = require("lodash");
|
|
15
14
|
const OAuthBase_1 = require("../OAuthBase");
|
|
16
|
-
const
|
|
17
|
-
|
|
15
|
+
const KeycloakUser_1 = require("./KeycloakUser");
|
|
16
|
+
const url_1 = require("url");
|
|
17
|
+
const _ = require("lodash");
|
|
18
|
+
class KeycloakAuth extends OAuthBase_1.OAuthBase {
|
|
18
19
|
constructor(logger, settings, window) {
|
|
19
20
|
super(logger, settings.applicationId, window);
|
|
20
21
|
this._settings = settings;
|
|
22
|
+
this.urlParams.set('scope', 'openid');
|
|
23
|
+
this.urlParams.set('state', common_1.RandomUtil.randomString(10));
|
|
21
24
|
this.urlParams.set('response_mode', 'query');
|
|
22
|
-
this.urlParams.set('state', common_1.RandomUtil.randomString(43));
|
|
23
25
|
}
|
|
24
26
|
getBaseUrl() {
|
|
25
27
|
return `${this.settings.url}/realms/${this.settings.realm}/protocol/openid-connect`;
|
|
@@ -29,7 +31,7 @@ class KeyCloakAuth extends OAuthBase_1.OAuthBase {
|
|
|
29
31
|
}
|
|
30
32
|
getProfile(token) {
|
|
31
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
let item = new
|
|
34
|
+
let item = new KeycloakUser_1.KeycloakUser();
|
|
33
35
|
item.parse(yield this.http.call(`${this.getBaseUrl()}/userinfo`, { headers: { Authorization: `Bearer ${token}` } }));
|
|
34
36
|
return item;
|
|
35
37
|
});
|
|
@@ -37,13 +39,13 @@ class KeyCloakAuth extends OAuthBase_1.OAuthBase {
|
|
|
37
39
|
getTokenByCode(dto, secret) {
|
|
38
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
41
|
let item = yield this.http.call(`${this.getBaseUrl()}/token`, {
|
|
40
|
-
data: {
|
|
42
|
+
data: new url_1.URLSearchParams({
|
|
41
43
|
code: dto.codeOrToken,
|
|
42
44
|
client_id: this.applicationId,
|
|
43
45
|
client_secret: secret,
|
|
44
46
|
redirect_uri: dto.redirectUri,
|
|
45
47
|
grant_type: 'authorization_code'
|
|
46
|
-
},
|
|
48
|
+
}),
|
|
47
49
|
method: 'post',
|
|
48
50
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
|
49
51
|
});
|
|
@@ -51,6 +53,8 @@ class KeyCloakAuth extends OAuthBase_1.OAuthBase {
|
|
|
51
53
|
throw new common_1.ExtendedError(item.error_description);
|
|
52
54
|
}
|
|
53
55
|
return {
|
|
56
|
+
scope: item.scope,
|
|
57
|
+
state: item.session_state,
|
|
54
58
|
tokenType: item.token_type,
|
|
55
59
|
expiresIn: item.expires_in,
|
|
56
60
|
accessToken: item.access_token,
|
|
@@ -70,4 +74,4 @@ class KeyCloakAuth extends OAuthBase_1.OAuthBase {
|
|
|
70
74
|
return this._settings;
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
|
-
exports.
|
|
77
|
+
exports.KeycloakAuth = KeycloakAuth;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeycloakUser = void 0;
|
|
4
|
+
const OAuthUser_1 = require("../OAuthUser");
|
|
5
|
+
class KeycloakUser extends OAuthUser_1.OAuthUser {
|
|
6
|
+
parse(item) {
|
|
7
|
+
this.id = item.sub;
|
|
8
|
+
this.name = item.name;
|
|
9
|
+
this.email = item.email;
|
|
10
|
+
this.isEmailVerified = item.email_verified;
|
|
11
|
+
this.preferredUsername = item.preferred_username;
|
|
12
|
+
this.givenName = item.given_name;
|
|
13
|
+
this.familyName = item.family_name;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.KeycloakUser = KeycloakUser;
|
package/cjs/public-api.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ 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 './keycloak/
|
|
13
|
-
export * from './keycloak/
|
|
12
|
+
export * from './keycloak/KeycloakAuth';
|
|
13
|
+
export * from './keycloak/KeycloakUser';
|
|
14
14
|
export * from './external/browser';
|
|
15
15
|
export * from './external/cordovaOAuthPlugin';
|
|
16
16
|
export * from './external/cordovaInAppBrowserPlugin';
|
package/cjs/public-api.js
CHANGED
|
@@ -25,8 +25,8 @@ __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("./keycloak/
|
|
29
|
-
__exportStar(require("./keycloak/
|
|
28
|
+
__exportStar(require("./keycloak/KeycloakAuth"), exports);
|
|
29
|
+
__exportStar(require("./keycloak/KeycloakUser"), exports);
|
|
30
30
|
__exportStar(require("./external/browser"), exports);
|
|
31
31
|
__exportStar(require("./external/cordovaOAuthPlugin"), exports);
|
|
32
32
|
__exportStar(require("./external/cordovaInAppBrowserPlugin"), exports);
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { ILogger } from "@ts-core/common";
|
|
2
2
|
import { IOAuthDto, IOAuthToken, OAuthBase } from "../OAuthBase";
|
|
3
|
-
import {
|
|
4
|
-
export declare class
|
|
5
|
-
protected _settings:
|
|
6
|
-
constructor(logger: ILogger, settings:
|
|
3
|
+
import { KeycloakUser } from "./KeycloakUser";
|
|
4
|
+
export declare class KeycloakAuth<T extends KeycloakUser = KeycloakUser> extends OAuthBase<T> {
|
|
5
|
+
protected _settings: IKeycloakAuthSettings;
|
|
6
|
+
constructor(logger: ILogger, settings: IKeycloakAuthSettings, window?: Window);
|
|
7
7
|
protected getBaseUrl(): string;
|
|
8
8
|
getPopUpUrl(): string;
|
|
9
9
|
getProfile(token: string): Promise<T>;
|
|
10
10
|
getTokenByCode(dto: IOAuthDto, secret: string): Promise<IOAuthToken>;
|
|
11
11
|
destroy(): void;
|
|
12
|
-
get settings():
|
|
12
|
+
get settings(): IKeycloakAuthSettings;
|
|
13
13
|
}
|
|
14
|
-
export interface
|
|
14
|
+
export interface IKeycloakAuthSettings {
|
|
15
15
|
url: string;
|
|
16
16
|
realm: string;
|
|
17
17
|
applicationId: string;
|
|
@@ -8,15 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { ExtendedError, RandomUtil } from "@ts-core/common";
|
|
11
|
-
import * as _ from 'lodash';
|
|
12
11
|
import { OAuthBase } from "../OAuthBase";
|
|
13
|
-
import {
|
|
14
|
-
|
|
12
|
+
import { KeycloakUser } from "./KeycloakUser";
|
|
13
|
+
import { URLSearchParams } from "url";
|
|
14
|
+
import * as _ from 'lodash';
|
|
15
|
+
export class KeycloakAuth extends OAuthBase {
|
|
15
16
|
constructor(logger, settings, window) {
|
|
16
17
|
super(logger, settings.applicationId, window);
|
|
17
18
|
this._settings = settings;
|
|
19
|
+
this.urlParams.set('scope', 'openid');
|
|
20
|
+
this.urlParams.set('state', RandomUtil.randomString(10));
|
|
18
21
|
this.urlParams.set('response_mode', 'query');
|
|
19
|
-
this.urlParams.set('state', RandomUtil.randomString(43));
|
|
20
22
|
}
|
|
21
23
|
getBaseUrl() {
|
|
22
24
|
return `${this.settings.url}/realms/${this.settings.realm}/protocol/openid-connect`;
|
|
@@ -26,7 +28,7 @@ export class KeyCloakAuth extends OAuthBase {
|
|
|
26
28
|
}
|
|
27
29
|
getProfile(token) {
|
|
28
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
let item = new
|
|
31
|
+
let item = new KeycloakUser();
|
|
30
32
|
item.parse(yield this.http.call(`${this.getBaseUrl()}/userinfo`, { headers: { Authorization: `Bearer ${token}` } }));
|
|
31
33
|
return item;
|
|
32
34
|
});
|
|
@@ -34,13 +36,13 @@ export class KeyCloakAuth extends OAuthBase {
|
|
|
34
36
|
getTokenByCode(dto, secret) {
|
|
35
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
38
|
let item = yield this.http.call(`${this.getBaseUrl()}/token`, {
|
|
37
|
-
data: {
|
|
39
|
+
data: new URLSearchParams({
|
|
38
40
|
code: dto.codeOrToken,
|
|
39
41
|
client_id: this.applicationId,
|
|
40
42
|
client_secret: secret,
|
|
41
43
|
redirect_uri: dto.redirectUri,
|
|
42
44
|
grant_type: 'authorization_code'
|
|
43
|
-
},
|
|
45
|
+
}),
|
|
44
46
|
method: 'post',
|
|
45
47
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
|
46
48
|
});
|
|
@@ -48,6 +50,8 @@ export class KeyCloakAuth extends OAuthBase {
|
|
|
48
50
|
throw new ExtendedError(item.error_description);
|
|
49
51
|
}
|
|
50
52
|
return {
|
|
53
|
+
scope: item.scope,
|
|
54
|
+
state: item.session_state,
|
|
51
55
|
tokenType: item.token_type,
|
|
52
56
|
expiresIn: item.expires_in,
|
|
53
57
|
accessToken: item.access_token,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OAuthUser } from "../OAuthUser";
|
|
2
|
+
export class KeycloakUser extends OAuthUser {
|
|
3
|
+
parse(item) {
|
|
4
|
+
this.id = item.sub;
|
|
5
|
+
this.name = item.name;
|
|
6
|
+
this.email = item.email;
|
|
7
|
+
this.isEmailVerified = item.email_verified;
|
|
8
|
+
this.preferredUsername = item.preferred_username;
|
|
9
|
+
this.givenName = item.given_name;
|
|
10
|
+
this.familyName = item.family_name;
|
|
11
|
+
}
|
|
12
|
+
}
|
package/esm/public-api.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ 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 './keycloak/
|
|
13
|
-
export * from './keycloak/
|
|
12
|
+
export * from './keycloak/KeycloakAuth';
|
|
13
|
+
export * from './keycloak/KeycloakUser';
|
|
14
14
|
export * from './external/browser';
|
|
15
15
|
export * from './external/cordovaOAuthPlugin';
|
|
16
16
|
export * from './external/cordovaInAppBrowserPlugin';
|
package/esm/public-api.js
CHANGED
|
@@ -9,8 +9,8 @@ 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 './keycloak/
|
|
13
|
-
export * from './keycloak/
|
|
12
|
+
export * from './keycloak/KeycloakAuth';
|
|
13
|
+
export * from './keycloak/KeycloakUser';
|
|
14
14
|
export * from './external/browser';
|
|
15
15
|
export * from './external/cordovaOAuthPlugin';
|
|
16
16
|
export * from './external/cordovaInAppBrowserPlugin';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-core/oauth",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.30",
|
|
4
4
|
"description": "Classes and utils for oauth",
|
|
5
5
|
"main": "./cjs/public-api.js",
|
|
6
6
|
"module": "./esm/public-api.js",
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@ts-core/common": "~3.0.14"
|
|
21
21
|
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"url": "^0.11.0"
|
|
24
|
+
},
|
|
22
25
|
"devDependencies": {
|
|
23
26
|
"@types/node": "^14.14.31",
|
|
24
27
|
"gulp-npm-module-publisher": "^3.0.0"
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeyCloakUser = void 0;
|
|
4
|
-
const OAuthUser_1 = require("../OAuthUser");
|
|
5
|
-
class KeyCloakUser extends OAuthUser_1.OAuthUser {
|
|
6
|
-
parse(item) {
|
|
7
|
-
this.id = item.id;
|
|
8
|
-
this.name = item.name;
|
|
9
|
-
this.email = item.email;
|
|
10
|
-
this.locale = item.locale;
|
|
11
|
-
this.picture = item.image;
|
|
12
|
-
this.clientId = item.clientId;
|
|
13
|
-
this.nickname = item.nickname;
|
|
14
|
-
this.lastName = item.last_name;
|
|
15
|
-
this.firstName = item.first_name;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.KeyCloakUser = KeyCloakUser;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { OAuthUser } from "../OAuthUser";
|
|
2
|
-
export class KeyCloakUser extends OAuthUser {
|
|
3
|
-
parse(item) {
|
|
4
|
-
this.id = item.id;
|
|
5
|
-
this.name = item.name;
|
|
6
|
-
this.email = item.email;
|
|
7
|
-
this.locale = item.locale;
|
|
8
|
-
this.picture = item.image;
|
|
9
|
-
this.clientId = item.clientId;
|
|
10
|
-
this.nickname = item.nickname;
|
|
11
|
-
this.lastName = item.last_name;
|
|
12
|
-
this.firstName = item.first_name;
|
|
13
|
-
}
|
|
14
|
-
}
|