@drax/identity-back 0.37.2 → 0.37.4
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/index.js +27 -3
- package/dist/middleware/apiKeyMiddleware.js +7 -0
- package/package.json +3 -3
- package/src/index.ts +53 -0
- package/src/middleware/apiKeyMiddleware.ts +8 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/types/index.d.ts +24 -2
- package/types/index.d.ts.map +1 -1
- package/types/middleware/apiKeyMiddleware.d.ts.map +1 -1
package/dist/index.js
CHANGED
|
@@ -2,10 +2,16 @@ import GraphqlMerge from "./graphql/index.js";
|
|
|
2
2
|
import UserServiceFactory from "./factory/UserServiceFactory.js";
|
|
3
3
|
import RoleServiceFactory from "./factory/RoleServiceFactory.js";
|
|
4
4
|
import TenantServiceFactory from "./factory/TenantServiceFactory.js";
|
|
5
|
+
import UserApiKeyServiceFactory from "./factory/UserApiKeyServiceFactory.js";
|
|
6
|
+
import UserLoginFailServiceFactory from "./factory/UserLoginFailServiceFactory.js";
|
|
7
|
+
import UserSessionServiceFactory from "./factory/UserSessionServiceFactory.js";
|
|
5
8
|
import RoleService from "./services/RoleService.js";
|
|
6
9
|
import UserService from "./services/UserService.js";
|
|
7
10
|
import TenantService from "./services/TenantService.js";
|
|
8
11
|
import PermissionService from "./services/PermissionService.js";
|
|
12
|
+
import UserApiKeyService from "./services/UserApiKeyService.js";
|
|
13
|
+
import UserSessionService from "./services/UserSessionService.js";
|
|
14
|
+
import UserLoginFailService from "./services/UserLoginFailService.js";
|
|
9
15
|
import Rbac from "./rbac/Rbac.js";
|
|
10
16
|
import { UserRoutes } from "./routes/UserRoutes.js";
|
|
11
17
|
import { RoleRoutes } from "./routes/RoleRoutes.js";
|
|
@@ -24,6 +30,18 @@ import CreateOrUpdateRole from "./setup/CreateOrUpdateRole.js";
|
|
|
24
30
|
import LoadPermissions from "./setup/LoadPermissions.js";
|
|
25
31
|
import LoadIdentityConfigFromEnv from "./setup/LoadIdentityConfigFromEnv.js";
|
|
26
32
|
import RecoveryUserPassword from "./setup/RecoveryUserPassword.js";
|
|
33
|
+
import RoleMongoRepository from "./repository/mongo/RoleMongoRepository.js";
|
|
34
|
+
import TenantMongoRepository from "./repository/mongo/TenantMongoRepository.js";
|
|
35
|
+
import UserMongoRepository from "./repository/mongo/UserMongoRepository.js";
|
|
36
|
+
import UserApiKeyMongoRepository from "./repository/mongo/UserApiKeyMongoRepository.js";
|
|
37
|
+
import UserSessionMongoRepository from "./repository/mongo/UserSessionMongoRepository.js";
|
|
38
|
+
import UserLoginFailMongoRepository from "./repository/mongo/UserLoginFailMongoRepository.js";
|
|
39
|
+
import RoleSqliteRepository from "./repository/sqlite/RoleSqliteRepository.js";
|
|
40
|
+
import TenantSqliteRepository from "./repository/sqlite/TenantSqliteRepository.js";
|
|
41
|
+
import UserSqliteRepository from "./repository/sqlite/UserSqliteRepository.js";
|
|
42
|
+
import UserApiKeySqliteRepository from "./repository/sqlite/UserApiKeySqliteRepository.js";
|
|
43
|
+
import UserLoginFailSqliteRepository from "./repository/sqlite/UserLoginFailSqliteRepository.js";
|
|
44
|
+
import UserSessionSqliteRepository from "./repository/sqlite/UserSessionSqliteRepository.js";
|
|
27
45
|
import { RolePermissions } from "./permissions/RolePermissions.js";
|
|
28
46
|
import { TenantPermissions } from "./permissions/TenantPermissions.js";
|
|
29
47
|
import { UserPermissions } from "./permissions/UserPermissions.js";
|
|
@@ -34,16 +52,18 @@ import { UserSchema, UserBaseSchema } from "./schemas/UserSchema.js";
|
|
|
34
52
|
import { TenantSchema, TenantBaseSchema } from "./schemas/TenantSchema.js";
|
|
35
53
|
import { RoleSchema, RoleBaseSchema } from "./schemas/RoleSchema.js";
|
|
36
54
|
import { UserApiKeySchema, UserApiKeyBaseSchema } from "./schemas/UserApiKeySchema.js";
|
|
55
|
+
import { UserLoginFailBaseSchema, UserLoginFailSchema } from "./schemas/UserLoginFailSchema.js";
|
|
56
|
+
import { UserSessionBaseSchema, UserSessionSchema } from "./schemas/UserSessionSchema.js";
|
|
37
57
|
const graphqlMergeResult = await GraphqlMerge();
|
|
38
58
|
const identityTypeDefs = await graphqlMergeResult.typeDefs;
|
|
39
59
|
const identityResolvers = await graphqlMergeResult.resolvers;
|
|
40
60
|
export {
|
|
41
61
|
//Schemas
|
|
42
|
-
UserSchema, UserBaseSchema, TenantSchema, TenantBaseSchema, RoleSchema, RoleBaseSchema, UserApiKeyBaseSchema, UserApiKeySchema,
|
|
62
|
+
UserSchema, UserBaseSchema, TenantSchema, TenantBaseSchema, RoleSchema, RoleBaseSchema, UserApiKeyBaseSchema, UserApiKeySchema, UserLoginFailBaseSchema, UserLoginFailSchema, UserSessionBaseSchema, UserSessionSchema,
|
|
43
63
|
//Service
|
|
44
|
-
UserService, RoleService, TenantService, PermissionService, Rbac,
|
|
64
|
+
UserService, RoleService, TenantService, UserApiKeyService, UserSessionService, UserLoginFailService, PermissionService, Rbac,
|
|
45
65
|
//Factories
|
|
46
|
-
UserServiceFactory, RoleServiceFactory, TenantServiceFactory,
|
|
66
|
+
UserServiceFactory, RoleServiceFactory, TenantServiceFactory, UserApiKeyServiceFactory, UserSessionServiceFactory, UserLoginFailServiceFactory,
|
|
47
67
|
//GQL
|
|
48
68
|
identityTypeDefs, identityResolvers,
|
|
49
69
|
//API REST
|
|
@@ -52,6 +72,10 @@ UserRoutes, RoleRoutes, TenantRoutes, UserApiKeyRoutes, UserSessionRoutes, UserL
|
|
|
52
72
|
jwtMiddleware, rbacMiddleware, apiKeyMiddleware,
|
|
53
73
|
//Permissions
|
|
54
74
|
RolePermissions, TenantPermissions, UserPermissions, UserApiKeyPermissions, UserSessionPermissions, UserLoginFailPermissions,
|
|
75
|
+
//Mongo Repositories
|
|
76
|
+
RoleMongoRepository, TenantMongoRepository, UserMongoRepository, UserApiKeyMongoRepository, UserSessionMongoRepository, UserLoginFailMongoRepository,
|
|
77
|
+
//Sqlite Repositories
|
|
78
|
+
RoleSqliteRepository, TenantSqliteRepository, UserSqliteRepository, UserApiKeySqliteRepository, UserLoginFailSqliteRepository, UserSessionSqliteRepository,
|
|
55
79
|
//Config
|
|
56
80
|
IdentityConfig,
|
|
57
81
|
//Errors
|
|
@@ -11,13 +11,20 @@ async function userApiKeyLoader(k) {
|
|
|
11
11
|
async function apiKeyMiddleware(request, reply) {
|
|
12
12
|
try {
|
|
13
13
|
let apiKey;
|
|
14
|
+
//Por header 'x-api-key'
|
|
14
15
|
if (request.headers['x-api-key']) {
|
|
15
16
|
apiKey = request.headers['x-api-key'];
|
|
16
17
|
}
|
|
18
|
+
//Por authorization 'ApiKey <uuid-key>'
|
|
17
19
|
const apiKeyRegExp = /^ApiKey (.*)$/i;
|
|
18
20
|
if (request.headers['authorization'] && apiKeyRegExp.test(request.headers['authorization'])) {
|
|
19
21
|
apiKey = request.headers?.authorization?.replace(/ApiKey /i, "");
|
|
20
22
|
}
|
|
23
|
+
//Por authorization '<uuid-key>'
|
|
24
|
+
const uuidRegex = /^[0-9a-fA-F]{24}$/i;
|
|
25
|
+
if (request.headers['authorization'] && uuidRegex.test(request.headers['authorization'])) {
|
|
26
|
+
apiKey = request.headers['authorization'];
|
|
27
|
+
}
|
|
21
28
|
if (apiKey) {
|
|
22
29
|
const userApiKey = await draxCache.getOrLoad(apiKey, userApiKeyLoader);
|
|
23
30
|
if (userApiKey && userApiKey.user) {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.37.
|
|
6
|
+
"version": "0.37.4",
|
|
7
7
|
"description": "Identity module for user management, authentication and authorization.",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "types/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"license": "ISC",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@drax/common-back": "^0.37.2",
|
|
32
|
-
"@drax/crud-back": "^0.37.
|
|
32
|
+
"@drax/crud-back": "^0.37.4",
|
|
33
33
|
"@drax/crud-share": "^0.37.0",
|
|
34
34
|
"@drax/email-back": "^0.37.0",
|
|
35
35
|
"@drax/identity-share": "^0.37.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"debug": "0"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "d30963a38a3efec693b589bcc55ae286f4a04386"
|
|
67
67
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,11 +2,17 @@ import GraphqlMerge from "./graphql/index.js"
|
|
|
2
2
|
import UserServiceFactory from "./factory/UserServiceFactory.js";
|
|
3
3
|
import RoleServiceFactory from "./factory/RoleServiceFactory.js";
|
|
4
4
|
import TenantServiceFactory from "./factory/TenantServiceFactory.js";
|
|
5
|
+
import UserApiKeyServiceFactory from "./factory/UserApiKeyServiceFactory.js";
|
|
6
|
+
import UserLoginFailServiceFactory from "./factory/UserLoginFailServiceFactory.js";
|
|
7
|
+
import UserSessionServiceFactory from "./factory/UserSessionServiceFactory.js";
|
|
5
8
|
|
|
6
9
|
import RoleService from "./services/RoleService.js";
|
|
7
10
|
import UserService from "./services/UserService.js";
|
|
8
11
|
import TenantService from "./services/TenantService.js";
|
|
9
12
|
import PermissionService from "./services/PermissionService.js";
|
|
13
|
+
import UserApiKeyService from "./services/UserApiKeyService.js";
|
|
14
|
+
import UserSessionService from "./services/UserSessionService.js";
|
|
15
|
+
import UserLoginFailService from "./services/UserLoginFailService.js";
|
|
10
16
|
|
|
11
17
|
import Rbac from "./rbac/Rbac.js";
|
|
12
18
|
|
|
@@ -35,6 +41,23 @@ import type {IRoleRepository} from "./interfaces/IRoleRepository";
|
|
|
35
41
|
import type {ITenantRepository} from "./interfaces/ITenantRepository";
|
|
36
42
|
import type {IUserRepository} from "./interfaces/IUserRepository";
|
|
37
43
|
import type {IUserApiKeyRepository} from "./interfaces/IUserApiKeyRepository";
|
|
44
|
+
import type {IUserLoginFailRepository} from "./interfaces/IUserLoginFailRepository";
|
|
45
|
+
import type {IUserSessionRepository} from "./interfaces/IUserSessionRepository";
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
import RoleMongoRepository from "./repository/mongo/RoleMongoRepository.js";
|
|
49
|
+
import TenantMongoRepository from "./repository/mongo/TenantMongoRepository.js";
|
|
50
|
+
import UserMongoRepository from "./repository/mongo/UserMongoRepository.js";
|
|
51
|
+
import UserApiKeyMongoRepository from "./repository/mongo/UserApiKeyMongoRepository.js";
|
|
52
|
+
import UserSessionMongoRepository from "./repository/mongo/UserSessionMongoRepository.js";
|
|
53
|
+
import UserLoginFailMongoRepository from "./repository/mongo/UserLoginFailMongoRepository.js";
|
|
54
|
+
|
|
55
|
+
import RoleSqliteRepository from "./repository/sqlite/RoleSqliteRepository.js";
|
|
56
|
+
import TenantSqliteRepository from "./repository/sqlite/TenantSqliteRepository.js";
|
|
57
|
+
import UserSqliteRepository from "./repository/sqlite/UserSqliteRepository.js";
|
|
58
|
+
import UserApiKeySqliteRepository from "./repository/sqlite/UserApiKeySqliteRepository.js";
|
|
59
|
+
import UserLoginFailSqliteRepository from "./repository/sqlite/UserLoginFailSqliteRepository.js";
|
|
60
|
+
import UserSessionSqliteRepository from "./repository/sqlite/UserSessionSqliteRepository.js";
|
|
38
61
|
|
|
39
62
|
|
|
40
63
|
import {RolePermissions} from "./permissions/RolePermissions.js";
|
|
@@ -48,6 +71,8 @@ import {UserSchema, UserBaseSchema} from "./schemas/UserSchema.js";
|
|
|
48
71
|
import {TenantSchema,TenantBaseSchema} from "./schemas/TenantSchema.js";
|
|
49
72
|
import {RoleSchema, RoleBaseSchema} from "./schemas/RoleSchema.js";
|
|
50
73
|
import {UserApiKeySchema, UserApiKeyBaseSchema} from "./schemas/UserApiKeySchema.js";
|
|
74
|
+
import {UserLoginFailBaseSchema, UserLoginFailSchema} from "./schemas/UserLoginFailSchema.js";
|
|
75
|
+
import {UserSessionBaseSchema, UserSessionSchema} from "./schemas/UserSessionSchema.js";
|
|
51
76
|
|
|
52
77
|
|
|
53
78
|
const graphqlMergeResult = await GraphqlMerge()
|
|
@@ -60,6 +85,8 @@ export type {
|
|
|
60
85
|
ITenantRepository,
|
|
61
86
|
IUserRepository,
|
|
62
87
|
IUserApiKeyRepository,
|
|
88
|
+
IUserLoginFailRepository,
|
|
89
|
+
IUserSessionRepository,
|
|
63
90
|
}
|
|
64
91
|
|
|
65
92
|
export {
|
|
@@ -73,11 +100,18 @@ export {
|
|
|
73
100
|
RoleBaseSchema,
|
|
74
101
|
UserApiKeyBaseSchema,
|
|
75
102
|
UserApiKeySchema,
|
|
103
|
+
UserLoginFailBaseSchema,
|
|
104
|
+
UserLoginFailSchema,
|
|
105
|
+
UserSessionBaseSchema,
|
|
106
|
+
UserSessionSchema,
|
|
76
107
|
|
|
77
108
|
//Service
|
|
78
109
|
UserService,
|
|
79
110
|
RoleService,
|
|
80
111
|
TenantService,
|
|
112
|
+
UserApiKeyService,
|
|
113
|
+
UserSessionService,
|
|
114
|
+
UserLoginFailService,
|
|
81
115
|
PermissionService,
|
|
82
116
|
Rbac,
|
|
83
117
|
|
|
@@ -85,6 +119,9 @@ export {
|
|
|
85
119
|
UserServiceFactory,
|
|
86
120
|
RoleServiceFactory,
|
|
87
121
|
TenantServiceFactory,
|
|
122
|
+
UserApiKeyServiceFactory,
|
|
123
|
+
UserSessionServiceFactory,
|
|
124
|
+
UserLoginFailServiceFactory,
|
|
88
125
|
|
|
89
126
|
//GQL
|
|
90
127
|
identityTypeDefs,
|
|
@@ -113,6 +150,22 @@ export {
|
|
|
113
150
|
UserSessionPermissions,
|
|
114
151
|
UserLoginFailPermissions,
|
|
115
152
|
|
|
153
|
+
//Mongo Repositories
|
|
154
|
+
RoleMongoRepository,
|
|
155
|
+
TenantMongoRepository,
|
|
156
|
+
UserMongoRepository,
|
|
157
|
+
UserApiKeyMongoRepository,
|
|
158
|
+
UserSessionMongoRepository,
|
|
159
|
+
UserLoginFailMongoRepository,
|
|
160
|
+
|
|
161
|
+
//Sqlite Repositories
|
|
162
|
+
RoleSqliteRepository,
|
|
163
|
+
TenantSqliteRepository,
|
|
164
|
+
UserSqliteRepository,
|
|
165
|
+
UserApiKeySqliteRepository,
|
|
166
|
+
UserLoginFailSqliteRepository,
|
|
167
|
+
UserSessionSqliteRepository,
|
|
168
|
+
|
|
116
169
|
//Config
|
|
117
170
|
IdentityConfig,
|
|
118
171
|
|
|
@@ -17,15 +17,23 @@ async function apiKeyMiddleware (request, reply) {
|
|
|
17
17
|
try{
|
|
18
18
|
let apiKey: string
|
|
19
19
|
|
|
20
|
+
//Por header 'x-api-key'
|
|
20
21
|
if(request.headers['x-api-key']){
|
|
21
22
|
apiKey = request.headers['x-api-key']
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
//Por authorization 'ApiKey <uuid-key>'
|
|
24
26
|
const apiKeyRegExp = /^ApiKey (.*)$/i;
|
|
25
27
|
if(request.headers['authorization'] && apiKeyRegExp.test(request.headers['authorization'])){
|
|
26
28
|
apiKey = request.headers?.authorization?.replace(/ApiKey /i, "")
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
//Por authorization '<uuid-key>'
|
|
32
|
+
const uuidRegex = /^[0-9a-fA-F]{24}$/i;
|
|
33
|
+
if(request.headers['authorization'] && uuidRegex.test(request.headers['authorization'])){
|
|
34
|
+
apiKey = request.headers['authorization']
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
if(apiKey){
|
|
30
38
|
const userApiKey = await draxCache.getOrLoad(apiKey, userApiKeyLoader)
|
|
31
39
|
if(userApiKey && userApiKey.user){
|