@drax/identity-back 0.37.2 → 0.37.5
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 +35 -3
- package/dist/middleware/apiKeyMiddleware.js +7 -0
- package/dist/models/UserLoginFailModel.js +8 -8
- package/dist/models/UserSessionModel.js +8 -8
- package/package.json +3 -3
- package/src/index.ts +73 -0
- package/src/middleware/apiKeyMiddleware.ts +8 -0
- package/src/models/UserLoginFailModel.ts +8 -8
- package/src/models/UserSessionModel.ts +8 -8
- package/tsconfig.tsbuildinfo +1 -1
- package/types/index.d.ts +30 -2
- package/types/index.d.ts.map +1 -1
- package/types/middleware/apiKeyMiddleware.d.ts.map +1 -1
- package/types/models/UserLoginFailModel.d.ts +2 -2
- package/types/models/UserLoginFailModel.d.ts.map +1 -1
- package/types/models/UserSessionModel.d.ts +2 -2
- package/types/models/UserSessionModel.d.ts.map +1 -1
- package/types/schemas/UserLoginFailSchema.d.ts +1 -1
- package/types/schemas/UserSessionSchema.d.ts +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,24 @@ 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 { RoleModel, RoleMongoSchema } from "./models/RoleModel.js";
|
|
34
|
+
import { TenantModel, TenantMongoSchema } from "./models/TenantModel.js";
|
|
35
|
+
import { UserModel, UserMongoSchema } from "./models/UserModel.js";
|
|
36
|
+
import { UserApiKeyModel, UserApiKeyMongoSchema } from "./models/UserApiKeyModel.js";
|
|
37
|
+
import { UserSessionModel, UserSessionMongoSchema } from "./models/UserSessionModel.js";
|
|
38
|
+
import { UserLoginFailModel, UserLoginFailMongoSchema } from "./models/UserLoginFailModel.js";
|
|
39
|
+
import RoleMongoRepository from "./repository/mongo/RoleMongoRepository.js";
|
|
40
|
+
import TenantMongoRepository from "./repository/mongo/TenantMongoRepository.js";
|
|
41
|
+
import UserMongoRepository from "./repository/mongo/UserMongoRepository.js";
|
|
42
|
+
import UserApiKeyMongoRepository from "./repository/mongo/UserApiKeyMongoRepository.js";
|
|
43
|
+
import UserSessionMongoRepository from "./repository/mongo/UserSessionMongoRepository.js";
|
|
44
|
+
import UserLoginFailMongoRepository from "./repository/mongo/UserLoginFailMongoRepository.js";
|
|
45
|
+
import RoleSqliteRepository from "./repository/sqlite/RoleSqliteRepository.js";
|
|
46
|
+
import TenantSqliteRepository from "./repository/sqlite/TenantSqliteRepository.js";
|
|
47
|
+
import UserSqliteRepository from "./repository/sqlite/UserSqliteRepository.js";
|
|
48
|
+
import UserApiKeySqliteRepository from "./repository/sqlite/UserApiKeySqliteRepository.js";
|
|
49
|
+
import UserLoginFailSqliteRepository from "./repository/sqlite/UserLoginFailSqliteRepository.js";
|
|
50
|
+
import UserSessionSqliteRepository from "./repository/sqlite/UserSessionSqliteRepository.js";
|
|
27
51
|
import { RolePermissions } from "./permissions/RolePermissions.js";
|
|
28
52
|
import { TenantPermissions } from "./permissions/TenantPermissions.js";
|
|
29
53
|
import { UserPermissions } from "./permissions/UserPermissions.js";
|
|
@@ -34,16 +58,18 @@ import { UserSchema, UserBaseSchema } from "./schemas/UserSchema.js";
|
|
|
34
58
|
import { TenantSchema, TenantBaseSchema } from "./schemas/TenantSchema.js";
|
|
35
59
|
import { RoleSchema, RoleBaseSchema } from "./schemas/RoleSchema.js";
|
|
36
60
|
import { UserApiKeySchema, UserApiKeyBaseSchema } from "./schemas/UserApiKeySchema.js";
|
|
61
|
+
import { UserLoginFailBaseSchema } from "./schemas/UserLoginFailSchema.js";
|
|
62
|
+
import { UserSessionBaseSchema } from "./schemas/UserSessionSchema.js";
|
|
37
63
|
const graphqlMergeResult = await GraphqlMerge();
|
|
38
64
|
const identityTypeDefs = await graphqlMergeResult.typeDefs;
|
|
39
65
|
const identityResolvers = await graphqlMergeResult.resolvers;
|
|
40
66
|
export {
|
|
41
67
|
//Schemas
|
|
42
|
-
UserSchema, UserBaseSchema, TenantSchema, TenantBaseSchema, RoleSchema, RoleBaseSchema, UserApiKeyBaseSchema, UserApiKeySchema,
|
|
68
|
+
UserSchema, UserBaseSchema, TenantSchema, TenantBaseSchema, RoleSchema, RoleBaseSchema, UserApiKeyBaseSchema, UserApiKeySchema, UserLoginFailBaseSchema, UserSessionBaseSchema,
|
|
43
69
|
//Service
|
|
44
|
-
UserService, RoleService, TenantService, PermissionService, Rbac,
|
|
70
|
+
UserService, RoleService, TenantService, UserApiKeyService, UserSessionService, UserLoginFailService, PermissionService, Rbac,
|
|
45
71
|
//Factories
|
|
46
|
-
UserServiceFactory, RoleServiceFactory, TenantServiceFactory,
|
|
72
|
+
UserServiceFactory, RoleServiceFactory, TenantServiceFactory, UserApiKeyServiceFactory, UserSessionServiceFactory, UserLoginFailServiceFactory,
|
|
47
73
|
//GQL
|
|
48
74
|
identityTypeDefs, identityResolvers,
|
|
49
75
|
//API REST
|
|
@@ -52,6 +78,12 @@ UserRoutes, RoleRoutes, TenantRoutes, UserApiKeyRoutes, UserSessionRoutes, UserL
|
|
|
52
78
|
jwtMiddleware, rbacMiddleware, apiKeyMiddleware,
|
|
53
79
|
//Permissions
|
|
54
80
|
RolePermissions, TenantPermissions, UserPermissions, UserApiKeyPermissions, UserSessionPermissions, UserLoginFailPermissions,
|
|
81
|
+
//Mongo Repositories
|
|
82
|
+
RoleMongoRepository, TenantMongoRepository, UserMongoRepository, UserApiKeyMongoRepository, UserSessionMongoRepository, UserLoginFailMongoRepository,
|
|
83
|
+
//Mongo Models
|
|
84
|
+
RoleModel, TenantModel, UserModel, UserApiKeyModel, UserSessionModel, UserLoginFailModel, RoleMongoSchema, TenantMongoSchema, UserMongoSchema, UserApiKeyMongoSchema, UserSessionMongoSchema, UserLoginFailMongoSchema,
|
|
85
|
+
//Sqlite Repositories
|
|
86
|
+
RoleSqliteRepository, TenantSqliteRepository, UserSqliteRepository, UserApiKeySqliteRepository, UserLoginFailSqliteRepository, UserSessionSqliteRepository,
|
|
55
87
|
//Config
|
|
56
88
|
IdentityConfig,
|
|
57
89
|
//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) {
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { mongoose } from '@drax/common-back';
|
|
2
2
|
import uniqueValidator from 'mongoose-unique-validator';
|
|
3
3
|
import mongoosePaginate from 'mongoose-paginate-v2';
|
|
4
|
-
const
|
|
4
|
+
const UserLoginFailMongoSchema = new mongoose.Schema({
|
|
5
5
|
username: { type: String, required: false, index: false, unique: false },
|
|
6
6
|
userAgent: { type: String, required: false, index: false, unique: false },
|
|
7
7
|
ip: { type: String, required: false, index: false, unique: false },
|
|
8
8
|
}, { timestamps: true });
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
UserLoginFailMongoSchema.plugin(uniqueValidator, { message: 'validation.unique' });
|
|
10
|
+
UserLoginFailMongoSchema.plugin(mongoosePaginate);
|
|
11
|
+
UserLoginFailMongoSchema.virtual("id").get(function () {
|
|
12
12
|
return this._id.toString();
|
|
13
13
|
});
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
UserLoginFailMongoSchema.set('toJSON', { getters: true, virtuals: true });
|
|
15
|
+
UserLoginFailMongoSchema.set('toObject', { getters: true, virtuals: true });
|
|
16
16
|
const MODEL_NAME = 'UserLoginFail';
|
|
17
17
|
const COLLECTION_NAME = 'UserLoginFail';
|
|
18
|
-
const UserLoginFailModel = mongoose.model(MODEL_NAME,
|
|
19
|
-
export {
|
|
18
|
+
const UserLoginFailModel = mongoose.model(MODEL_NAME, UserLoginFailMongoSchema, COLLECTION_NAME);
|
|
19
|
+
export { UserLoginFailMongoSchema, UserLoginFailModel };
|
|
20
20
|
export default UserLoginFailModel;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { mongoose } from '@drax/common-back';
|
|
2
2
|
import uniqueValidator from 'mongoose-unique-validator';
|
|
3
3
|
import mongoosePaginate from 'mongoose-paginate-v2';
|
|
4
|
-
const
|
|
4
|
+
const UserSessionMongoSchema = new mongoose.Schema({
|
|
5
5
|
uuid: { type: String, required: true, index: true, unique: false },
|
|
6
6
|
user: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true, index: true, unique: false },
|
|
7
7
|
userAgent: { type: String, required: false, index: false, unique: false },
|
|
8
8
|
ip: { type: String, required: false, index: false, unique: false },
|
|
9
9
|
}, { timestamps: true });
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
UserSessionMongoSchema.plugin(uniqueValidator, { message: 'validation.unique' });
|
|
11
|
+
UserSessionMongoSchema.plugin(mongoosePaginate);
|
|
12
|
+
UserSessionMongoSchema.virtual("id").get(function () {
|
|
13
13
|
return this._id.toString();
|
|
14
14
|
});
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
UserSessionMongoSchema.set('toJSON', { getters: true, virtuals: true });
|
|
16
|
+
UserSessionMongoSchema.set('toObject', { getters: true, virtuals: true });
|
|
17
17
|
const MODEL_NAME = 'UserSession';
|
|
18
18
|
const COLLECTION_NAME = 'UserSession';
|
|
19
|
-
const UserSessionModel = mongoose.model(MODEL_NAME,
|
|
20
|
-
export {
|
|
19
|
+
const UserSessionModel = mongoose.model(MODEL_NAME, UserSessionMongoSchema, COLLECTION_NAME);
|
|
20
|
+
export { UserSessionMongoSchema, UserSessionModel };
|
|
21
21
|
export default UserSessionModel;
|
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.5",
|
|
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.5",
|
|
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": "2fd3d1fa98a875f67691ea4524682985a52cba17"
|
|
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,30 @@ 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
|
+
import {RoleModel, RoleMongoSchema} from "./models/RoleModel.js";
|
|
48
|
+
import {TenantModel, TenantMongoSchema} from "./models/TenantModel.js";
|
|
49
|
+
import {UserModel, UserMongoSchema} from "./models/UserModel.js";
|
|
50
|
+
import {UserApiKeyModel, UserApiKeyMongoSchema} from "./models/UserApiKeyModel.js";
|
|
51
|
+
import {UserSessionModel,UserSessionMongoSchema} from "./models/UserSessionModel.js";
|
|
52
|
+
import {UserLoginFailModel,UserLoginFailMongoSchema} from "./models/UserLoginFailModel.js";
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
import RoleMongoRepository from "./repository/mongo/RoleMongoRepository.js";
|
|
56
|
+
import TenantMongoRepository from "./repository/mongo/TenantMongoRepository.js";
|
|
57
|
+
import UserMongoRepository from "./repository/mongo/UserMongoRepository.js";
|
|
58
|
+
import UserApiKeyMongoRepository from "./repository/mongo/UserApiKeyMongoRepository.js";
|
|
59
|
+
import UserSessionMongoRepository from "./repository/mongo/UserSessionMongoRepository.js";
|
|
60
|
+
import UserLoginFailMongoRepository from "./repository/mongo/UserLoginFailMongoRepository.js";
|
|
61
|
+
|
|
62
|
+
import RoleSqliteRepository from "./repository/sqlite/RoleSqliteRepository.js";
|
|
63
|
+
import TenantSqliteRepository from "./repository/sqlite/TenantSqliteRepository.js";
|
|
64
|
+
import UserSqliteRepository from "./repository/sqlite/UserSqliteRepository.js";
|
|
65
|
+
import UserApiKeySqliteRepository from "./repository/sqlite/UserApiKeySqliteRepository.js";
|
|
66
|
+
import UserLoginFailSqliteRepository from "./repository/sqlite/UserLoginFailSqliteRepository.js";
|
|
67
|
+
import UserSessionSqliteRepository from "./repository/sqlite/UserSessionSqliteRepository.js";
|
|
38
68
|
|
|
39
69
|
|
|
40
70
|
import {RolePermissions} from "./permissions/RolePermissions.js";
|
|
@@ -48,6 +78,8 @@ import {UserSchema, UserBaseSchema} from "./schemas/UserSchema.js";
|
|
|
48
78
|
import {TenantSchema,TenantBaseSchema} from "./schemas/TenantSchema.js";
|
|
49
79
|
import {RoleSchema, RoleBaseSchema} from "./schemas/RoleSchema.js";
|
|
50
80
|
import {UserApiKeySchema, UserApiKeyBaseSchema} from "./schemas/UserApiKeySchema.js";
|
|
81
|
+
import {UserLoginFailBaseSchema, UserLoginFailSchema} from "./schemas/UserLoginFailSchema.js";
|
|
82
|
+
import {UserSessionBaseSchema, UserSessionSchema} from "./schemas/UserSessionSchema.js";
|
|
51
83
|
|
|
52
84
|
|
|
53
85
|
const graphqlMergeResult = await GraphqlMerge()
|
|
@@ -60,6 +92,8 @@ export type {
|
|
|
60
92
|
ITenantRepository,
|
|
61
93
|
IUserRepository,
|
|
62
94
|
IUserApiKeyRepository,
|
|
95
|
+
IUserLoginFailRepository,
|
|
96
|
+
IUserSessionRepository,
|
|
63
97
|
}
|
|
64
98
|
|
|
65
99
|
export {
|
|
@@ -73,11 +107,16 @@ export {
|
|
|
73
107
|
RoleBaseSchema,
|
|
74
108
|
UserApiKeyBaseSchema,
|
|
75
109
|
UserApiKeySchema,
|
|
110
|
+
UserLoginFailBaseSchema,
|
|
111
|
+
UserSessionBaseSchema,
|
|
76
112
|
|
|
77
113
|
//Service
|
|
78
114
|
UserService,
|
|
79
115
|
RoleService,
|
|
80
116
|
TenantService,
|
|
117
|
+
UserApiKeyService,
|
|
118
|
+
UserSessionService,
|
|
119
|
+
UserLoginFailService,
|
|
81
120
|
PermissionService,
|
|
82
121
|
Rbac,
|
|
83
122
|
|
|
@@ -85,6 +124,9 @@ export {
|
|
|
85
124
|
UserServiceFactory,
|
|
86
125
|
RoleServiceFactory,
|
|
87
126
|
TenantServiceFactory,
|
|
127
|
+
UserApiKeyServiceFactory,
|
|
128
|
+
UserSessionServiceFactory,
|
|
129
|
+
UserLoginFailServiceFactory,
|
|
88
130
|
|
|
89
131
|
//GQL
|
|
90
132
|
identityTypeDefs,
|
|
@@ -113,6 +155,37 @@ export {
|
|
|
113
155
|
UserSessionPermissions,
|
|
114
156
|
UserLoginFailPermissions,
|
|
115
157
|
|
|
158
|
+
//Mongo Repositories
|
|
159
|
+
RoleMongoRepository,
|
|
160
|
+
TenantMongoRepository,
|
|
161
|
+
UserMongoRepository,
|
|
162
|
+
UserApiKeyMongoRepository,
|
|
163
|
+
UserSessionMongoRepository,
|
|
164
|
+
UserLoginFailMongoRepository,
|
|
165
|
+
|
|
166
|
+
//Mongo Models
|
|
167
|
+
RoleModel,
|
|
168
|
+
TenantModel,
|
|
169
|
+
UserModel,
|
|
170
|
+
UserApiKeyModel,
|
|
171
|
+
UserSessionModel,
|
|
172
|
+
UserLoginFailModel,
|
|
173
|
+
|
|
174
|
+
RoleMongoSchema,
|
|
175
|
+
TenantMongoSchema,
|
|
176
|
+
UserMongoSchema,
|
|
177
|
+
UserApiKeyMongoSchema,
|
|
178
|
+
UserSessionMongoSchema,
|
|
179
|
+
UserLoginFailMongoSchema,
|
|
180
|
+
|
|
181
|
+
//Sqlite Repositories
|
|
182
|
+
RoleSqliteRepository,
|
|
183
|
+
TenantSqliteRepository,
|
|
184
|
+
UserSqliteRepository,
|
|
185
|
+
UserApiKeySqliteRepository,
|
|
186
|
+
UserLoginFailSqliteRepository,
|
|
187
|
+
UserSessionSqliteRepository,
|
|
188
|
+
|
|
116
189
|
//Config
|
|
117
190
|
IdentityConfig,
|
|
118
191
|
|
|
@@ -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){
|
|
@@ -4,30 +4,30 @@ import uniqueValidator from 'mongoose-unique-validator';
|
|
|
4
4
|
import mongoosePaginate from 'mongoose-paginate-v2'
|
|
5
5
|
import type {IUserLoginFail} from '@drax/identity-share'
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const UserLoginFailMongoSchema = new mongoose.Schema<IUserLoginFail>({
|
|
8
8
|
username: {type: String, required: false, index: false, unique: false },
|
|
9
9
|
userAgent: {type: String, required: false, index: false, unique: false },
|
|
10
10
|
ip: {type: String, required: false, index: false, unique: false },
|
|
11
11
|
}, {timestamps: true});
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
UserLoginFailMongoSchema.plugin(uniqueValidator, {message: 'validation.unique'});
|
|
14
|
+
UserLoginFailMongoSchema.plugin(mongoosePaginate);
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
UserLoginFailMongoSchema.virtual("id").get(function () {
|
|
17
17
|
return this._id.toString();
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
UserLoginFailMongoSchema.set('toJSON', {getters: true, virtuals: true});
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
UserLoginFailMongoSchema.set('toObject', {getters: true, virtuals: true});
|
|
24
24
|
|
|
25
25
|
const MODEL_NAME = 'UserLoginFail';
|
|
26
26
|
const COLLECTION_NAME = 'UserLoginFail';
|
|
27
|
-
const UserLoginFailModel = mongoose.model<IUserLoginFail, PaginateModel<IUserLoginFail>>(MODEL_NAME,
|
|
27
|
+
const UserLoginFailModel = mongoose.model<IUserLoginFail, PaginateModel<IUserLoginFail>>(MODEL_NAME, UserLoginFailMongoSchema,COLLECTION_NAME);
|
|
28
28
|
|
|
29
29
|
export {
|
|
30
|
-
|
|
30
|
+
UserLoginFailMongoSchema,
|
|
31
31
|
UserLoginFailModel
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -5,31 +5,31 @@ import uniqueValidator from 'mongoose-unique-validator';
|
|
|
5
5
|
import mongoosePaginate from 'mongoose-paginate-v2'
|
|
6
6
|
import type {IUserSession} from '@drax/identity-share'
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const UserSessionMongoSchema = new mongoose.Schema<IUserSession>({
|
|
9
9
|
uuid: {type: String, required: true, index: true, unique: false },
|
|
10
10
|
user: {type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true, index: true, unique: false },
|
|
11
11
|
userAgent: {type: String, required: false, index: false, unique: false },
|
|
12
12
|
ip: {type: String, required: false, index: false, unique: false },
|
|
13
13
|
}, {timestamps: true});
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
UserSessionMongoSchema.plugin(uniqueValidator, {message: 'validation.unique'});
|
|
16
|
+
UserSessionMongoSchema.plugin(mongoosePaginate);
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
UserSessionMongoSchema.virtual("id").get(function () {
|
|
19
19
|
return this._id.toString();
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
UserSessionMongoSchema.set('toJSON', {getters: true, virtuals: true});
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
UserSessionMongoSchema.set('toObject', {getters: true, virtuals: true});
|
|
26
26
|
|
|
27
27
|
const MODEL_NAME = 'UserSession';
|
|
28
28
|
const COLLECTION_NAME = 'UserSession';
|
|
29
|
-
const UserSessionModel = mongoose.model<IUserSession, PaginateModel<IUserSession>>(MODEL_NAME,
|
|
29
|
+
const UserSessionModel = mongoose.model<IUserSession, PaginateModel<IUserSession>>(MODEL_NAME, UserSessionMongoSchema,COLLECTION_NAME);
|
|
30
30
|
|
|
31
31
|
export {
|
|
32
|
-
|
|
32
|
+
UserSessionMongoSchema,
|
|
33
33
|
UserSessionModel
|
|
34
34
|
}
|
|
35
35
|
|