@ts-core/oauth 3.0.28 → 3.0.29
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.
|
@@ -14,12 +14,14 @@ const common_1 = require("@ts-core/common");
|
|
|
14
14
|
const _ = require("lodash");
|
|
15
15
|
const OAuthBase_1 = require("../OAuthBase");
|
|
16
16
|
const KeyCloakUser_1 = require("./KeyCloakUser");
|
|
17
|
+
const url_1 = require("url");
|
|
17
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`;
|
|
@@ -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,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { OAuthUser } from "../OAuthUser";
|
|
2
2
|
export declare class KeyCloakUser extends OAuthUser {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
givenName: string;
|
|
4
|
+
familyName: string;
|
|
5
|
+
isEmailVerified: boolean;
|
|
6
|
+
preferredUsername: string;
|
|
7
7
|
parse(item: any): void;
|
|
8
8
|
}
|
|
@@ -4,15 +4,13 @@ exports.KeyCloakUser = void 0;
|
|
|
4
4
|
const OAuthUser_1 = require("../OAuthUser");
|
|
5
5
|
class KeyCloakUser extends OAuthUser_1.OAuthUser {
|
|
6
6
|
parse(item) {
|
|
7
|
-
this.id = item.
|
|
7
|
+
this.id = item.sub;
|
|
8
8
|
this.name = item.name;
|
|
9
9
|
this.email = item.email;
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.lastName = item.last_name;
|
|
15
|
-
this.firstName = item.first_name;
|
|
10
|
+
this.isEmailVerified = item.email_verified;
|
|
11
|
+
this.preferredUsername = item.preferred_username;
|
|
12
|
+
this.givenName = item.given_name;
|
|
13
|
+
this.familyName = item.family_name;
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
exports.KeyCloakUser = KeyCloakUser;
|
|
@@ -11,12 +11,14 @@ import { ExtendedError, RandomUtil } from "@ts-core/common";
|
|
|
11
11
|
import * as _ from 'lodash';
|
|
12
12
|
import { OAuthBase } from "../OAuthBase";
|
|
13
13
|
import { KeyCloakUser } from "./KeyCloakUser";
|
|
14
|
+
import { URLSearchParams } from "url";
|
|
14
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`;
|
|
@@ -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,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { OAuthUser } from "../OAuthUser";
|
|
2
2
|
export declare class KeyCloakUser extends OAuthUser {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
givenName: string;
|
|
4
|
+
familyName: string;
|
|
5
|
+
isEmailVerified: boolean;
|
|
6
|
+
preferredUsername: string;
|
|
7
7
|
parse(item: any): void;
|
|
8
8
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { OAuthUser } from "../OAuthUser";
|
|
2
2
|
export class KeyCloakUser extends OAuthUser {
|
|
3
3
|
parse(item) {
|
|
4
|
-
this.id = item.
|
|
4
|
+
this.id = item.sub;
|
|
5
5
|
this.name = item.name;
|
|
6
6
|
this.email = item.email;
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
this.lastName = item.last_name;
|
|
12
|
-
this.firstName = item.first_name;
|
|
7
|
+
this.isEmailVerified = item.email_verified;
|
|
8
|
+
this.preferredUsername = item.preferred_username;
|
|
9
|
+
this.givenName = item.given_name;
|
|
10
|
+
this.familyName = item.family_name;
|
|
13
11
|
}
|
|
14
12
|
}
|