mblabs-roccato-backend-commons 1.0.84 → 1.0.86
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/dist/database/entities/group.js +2 -1
- package/dist/database/entities/profile.js +2 -1
- package/dist/interfaces/keycloak.d.ts +35 -0
- package/dist/services/keycloak.d.ts +1 -0
- package/dist/services/keycloak.js +17 -0
- package/package.json +1 -1
- package/src/database/entities/group.ts +2 -1
- package/src/database/entities/profile.ts +2 -1
- package/src/interfaces/keycloak.ts +37 -0
- package/src/services/keycloak.ts +24 -0
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const typeorm_1 = require("typeorm");
|
|
16
|
+
const constants_1 = require("../../constants");
|
|
16
17
|
const account_group_1 = __importDefault(require("./account-group"));
|
|
17
18
|
const base_1 = __importDefault(require("./base"));
|
|
18
19
|
const group_module_1 = __importDefault(require("./group-module"));
|
|
@@ -56,7 +57,7 @@ __decorate([
|
|
|
56
57
|
__metadata("design:type", Boolean)
|
|
57
58
|
], GroupEntity.prototype, "isDefault", void 0);
|
|
58
59
|
__decorate([
|
|
59
|
-
(0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
|
|
60
|
+
(0, typeorm_1.Column)({ type: 'varchar', nullable: true, default: constants_1.LOCALES.PORTUGUESE }),
|
|
60
61
|
__metadata("design:type", String)
|
|
61
62
|
], GroupEntity.prototype, "locale", void 0);
|
|
62
63
|
__decorate([
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const typeorm_1 = require("typeorm");
|
|
16
|
+
const constants_1 = require("../../constants");
|
|
16
17
|
const base_1 = __importDefault(require("./base"));
|
|
17
18
|
const profile_module_1 = __importDefault(require("./profile-module"));
|
|
18
19
|
let ProfileEntity = class ProfileEntity extends base_1.default {
|
|
@@ -54,7 +55,7 @@ __decorate([
|
|
|
54
55
|
__metadata("design:type", Boolean)
|
|
55
56
|
], ProfileEntity.prototype, "isDefault", void 0);
|
|
56
57
|
__decorate([
|
|
57
|
-
(0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
|
|
58
|
+
(0, typeorm_1.Column)({ type: 'varchar', nullable: true, default: constants_1.LOCALES.PORTUGUESE }),
|
|
58
59
|
__metadata("design:type", String)
|
|
59
60
|
], ProfileEntity.prototype, "locale", void 0);
|
|
60
61
|
__decorate([
|
|
@@ -55,6 +55,40 @@ export declare namespace Keycloak {
|
|
|
55
55
|
scope?: string;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
namespace GetSession {
|
|
59
|
+
interface Request {
|
|
60
|
+
url: string;
|
|
61
|
+
data: {
|
|
62
|
+
accessToken: string;
|
|
63
|
+
};
|
|
64
|
+
credentials: Credentials;
|
|
65
|
+
}
|
|
66
|
+
interface Response {
|
|
67
|
+
id: string;
|
|
68
|
+
sub: string;
|
|
69
|
+
firstName: string;
|
|
70
|
+
lastName: string;
|
|
71
|
+
email: string;
|
|
72
|
+
enabled: boolean;
|
|
73
|
+
attributes: {
|
|
74
|
+
isFirstAccess: boolean;
|
|
75
|
+
};
|
|
76
|
+
scope?: string;
|
|
77
|
+
totp?: boolean;
|
|
78
|
+
emailVerified?: boolean;
|
|
79
|
+
disableableCredentialTypes?: Set<string>;
|
|
80
|
+
requiredActions?: string[];
|
|
81
|
+
notBefore?: number;
|
|
82
|
+
createdTimestamp: number;
|
|
83
|
+
access?: {
|
|
84
|
+
manageGroupMembership?: boolean;
|
|
85
|
+
view?: boolean;
|
|
86
|
+
mapRoles?: boolean;
|
|
87
|
+
impersonate?: boolean;
|
|
88
|
+
manage?: boolean;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
58
92
|
namespace RefreshAccess {
|
|
59
93
|
interface Request {
|
|
60
94
|
url: string;
|
|
@@ -286,6 +320,7 @@ export declare namespace Keycloak {
|
|
|
286
320
|
export interface IKeycloakService {
|
|
287
321
|
authenticate(req: Keycloak.Authenticate.Request): Promise<Keycloak.Authenticate.Response>;
|
|
288
322
|
authenticateServer(req: Keycloak.AuthenticateServer.Request): Promise<Keycloak.AuthenticateServer.Response>;
|
|
323
|
+
getSession(req: Keycloak.GetSession.Request): Promise<Keycloak.GetSession.Response>;
|
|
289
324
|
refreshAccess(req: Keycloak.RefreshAccess.Request): Promise<Keycloak.RefreshAccess.Response>;
|
|
290
325
|
revokeAccess(req: Keycloak.RevokeAccess.Request): Promise<void>;
|
|
291
326
|
createUser(req: Keycloak.CreateUser.Request): Promise<void>;
|
|
@@ -2,6 +2,7 @@ import { IKeycloakService, Keycloak } from '../interfaces';
|
|
|
2
2
|
declare class KeycloakService implements IKeycloakService {
|
|
3
3
|
authenticate({ credentials, data, url, }: Keycloak.Authenticate.Request): Promise<Keycloak.Authenticate.Response>;
|
|
4
4
|
authenticateServer({ credentials, url, }: Keycloak.AuthenticateServer.Request): Promise<Keycloak.AuthenticateServer.Response>;
|
|
5
|
+
getSession({ credentials, data, url, }: Keycloak.GetSession.Request): Promise<Keycloak.GetSession.Response>;
|
|
5
6
|
refreshAccess({ credentials, data, url, }: Keycloak.RefreshAccess.Request): Promise<Keycloak.RefreshAccess.Response>;
|
|
6
7
|
revokeAccess({ credentials, data, url, }: Keycloak.RevokeAccess.Request): Promise<void>;
|
|
7
8
|
createUser({ credentials, data, url, }: Keycloak.CreateUser.Request): Promise<void>;
|
|
@@ -41,6 +41,23 @@ class KeycloakService {
|
|
|
41
41
|
});
|
|
42
42
|
return response;
|
|
43
43
|
}
|
|
44
|
+
async getSession({ credentials, data, url, }) {
|
|
45
|
+
const { data: response } = await http_1.default.request({
|
|
46
|
+
baseURL: url,
|
|
47
|
+
method: 'post',
|
|
48
|
+
resourcePath: `/auth/realms/${credentials.realm}/protocol/openid-connect/token/introspect/`,
|
|
49
|
+
headers: {
|
|
50
|
+
'Cache-Control': 'no-cache',
|
|
51
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
52
|
+
},
|
|
53
|
+
body: new URLSearchParams({
|
|
54
|
+
client_id: credentials.clientId,
|
|
55
|
+
client_secret: credentials.clientSecret,
|
|
56
|
+
token: data.accessToken,
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
return response;
|
|
60
|
+
}
|
|
44
61
|
async refreshAccess({ credentials, data, url, }) {
|
|
45
62
|
const { data: response } = await http_1.default.request({
|
|
46
63
|
baseURL: url,
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
Relation,
|
|
6
6
|
} from 'typeorm';
|
|
7
7
|
|
|
8
|
+
import { LOCALES } from '../../constants';
|
|
8
9
|
import AccountGroupEntity from './account-group';
|
|
9
10
|
import BaseEntity from './base';
|
|
10
11
|
import GroupModuleEntity from './group-module';
|
|
@@ -29,7 +30,7 @@ export default class GroupEntity extends BaseEntity {
|
|
|
29
30
|
@Column({ type: 'boolean', nullable: true })
|
|
30
31
|
public isDefault?: boolean;
|
|
31
32
|
|
|
32
|
-
@Column({ type: 'varchar', nullable: true })
|
|
33
|
+
@Column({ type: 'varchar', nullable: true, default: LOCALES.PORTUGUESE })
|
|
33
34
|
public locale?: string;
|
|
34
35
|
|
|
35
36
|
@OneToMany(() => AccountGroupEntity, ag => ag.group)
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
Relation,
|
|
6
6
|
} from 'typeorm';
|
|
7
7
|
|
|
8
|
+
import { LOCALES } from '../../constants';
|
|
8
9
|
import BaseEntity from './base';
|
|
9
10
|
import ProfileModuleEntity from './profile-module';
|
|
10
11
|
|
|
@@ -28,7 +29,7 @@ export default class ProfileEntity extends BaseEntity {
|
|
|
28
29
|
@Column({ type: 'boolean', nullable: true })
|
|
29
30
|
public isDefault?: boolean;
|
|
30
31
|
|
|
31
|
-
@Column({ type: 'varchar', nullable: true })
|
|
32
|
+
@Column({ type: 'varchar', nullable: true, default: LOCALES.PORTUGUESE })
|
|
32
33
|
public locale?: string;
|
|
33
34
|
|
|
34
35
|
@OneToMany(() => ProfileModuleEntity, pm => pm.profile)
|
|
@@ -61,6 +61,42 @@ export namespace Keycloak {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
export namespace GetSession {
|
|
65
|
+
export interface Request {
|
|
66
|
+
url: string;
|
|
67
|
+
data: {
|
|
68
|
+
accessToken: string;
|
|
69
|
+
};
|
|
70
|
+
credentials: Credentials;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface Response {
|
|
74
|
+
id: string;
|
|
75
|
+
sub: string;
|
|
76
|
+
firstName: string;
|
|
77
|
+
lastName: string;
|
|
78
|
+
email: string;
|
|
79
|
+
enabled: boolean;
|
|
80
|
+
attributes: {
|
|
81
|
+
isFirstAccess: boolean;
|
|
82
|
+
};
|
|
83
|
+
scope?: string;
|
|
84
|
+
totp?: boolean;
|
|
85
|
+
emailVerified?: boolean;
|
|
86
|
+
disableableCredentialTypes?: Set<string>;
|
|
87
|
+
requiredActions?: string[];
|
|
88
|
+
notBefore?: number;
|
|
89
|
+
createdTimestamp: number;
|
|
90
|
+
access?: {
|
|
91
|
+
manageGroupMembership?: boolean;
|
|
92
|
+
view?: boolean;
|
|
93
|
+
mapRoles?: boolean;
|
|
94
|
+
impersonate?: boolean;
|
|
95
|
+
manage?: boolean;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
64
100
|
export namespace RefreshAccess {
|
|
65
101
|
export interface Request {
|
|
66
102
|
url: string;
|
|
@@ -309,6 +345,7 @@ export namespace Keycloak {
|
|
|
309
345
|
export interface IKeycloakService {
|
|
310
346
|
authenticate(req: Keycloak.Authenticate.Request): Promise<Keycloak.Authenticate.Response>;
|
|
311
347
|
authenticateServer(req: Keycloak.AuthenticateServer.Request): Promise<Keycloak.AuthenticateServer.Response>;
|
|
348
|
+
getSession(req: Keycloak.GetSession.Request): Promise<Keycloak.GetSession.Response>;
|
|
312
349
|
refreshAccess(req: Keycloak.RefreshAccess.Request): Promise<Keycloak.RefreshAccess.Response>;
|
|
313
350
|
revokeAccess(req: Keycloak.RevokeAccess.Request): Promise<void>;
|
|
314
351
|
createUser(req: Keycloak.CreateUser.Request): Promise<void>;
|
package/src/services/keycloak.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { IKeycloakService, Keycloak, Roles } from '../interfaces';
|
|
|
2
2
|
import HttpService from './http';
|
|
3
3
|
|
|
4
4
|
class KeycloakService implements IKeycloakService {
|
|
5
|
+
|
|
5
6
|
async authenticate ({
|
|
6
7
|
credentials,
|
|
7
8
|
data,
|
|
@@ -49,6 +50,29 @@ class KeycloakService implements IKeycloakService {
|
|
|
49
50
|
return response;
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
async getSession ({
|
|
54
|
+
credentials,
|
|
55
|
+
data,
|
|
56
|
+
url,
|
|
57
|
+
}: Keycloak.GetSession.Request): Promise<Keycloak.GetSession.Response> {
|
|
58
|
+
const { data: response } = await HttpService.request<Keycloak.GetSession.Response>({
|
|
59
|
+
baseURL: url,
|
|
60
|
+
method: 'post',
|
|
61
|
+
resourcePath: `/auth/realms/${credentials.realm}/protocol/openid-connect/token/introspect/`,
|
|
62
|
+
headers: {
|
|
63
|
+
'Cache-Control': 'no-cache',
|
|
64
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
65
|
+
},
|
|
66
|
+
body: new URLSearchParams({
|
|
67
|
+
client_id: credentials.clientId,
|
|
68
|
+
client_secret: credentials.clientSecret,
|
|
69
|
+
token: data.accessToken,
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return response;
|
|
74
|
+
}
|
|
75
|
+
|
|
52
76
|
async refreshAccess ({
|
|
53
77
|
credentials,
|
|
54
78
|
data,
|