nestjs-security-cli 1.5.3 → 1.5.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/README.md +14 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,17 +18,16 @@ import { SecurityModule, BlacklistedIp, BlacklistedIpSchema, SecurityMiddleware
|
|
|
18
18
|
@Module( {
|
|
19
19
|
imports: [
|
|
20
20
|
SecurityModule.forRootAsync( {
|
|
21
|
-
enableAdminPanel: true,
|
|
21
|
+
enableAdminPanel: true, // enables the admin panel for the `/security endpoints`
|
|
22
22
|
useFactory: () => ({
|
|
23
23
|
enableDatabase: true,
|
|
24
24
|
defaultBlockDurationHours: 24,
|
|
25
25
|
enableAutoBlocking: true
|
|
26
26
|
}),
|
|
27
27
|
inject: [],
|
|
28
|
-
//
|
|
29
|
-
// This should be your mongoose connection
|
|
30
|
-
|
|
31
|
-
providers: [ ...IpBlockerProvider ] // Required if enableDatabase is true
|
|
28
|
+
// Below required if enableDatabase is true
|
|
29
|
+
imports: [ MongoDbModule ], // This should be your mongoose connection
|
|
30
|
+
providers: [ ...IpBlockerProvider ]
|
|
32
31
|
} )
|
|
33
32
|
]
|
|
34
33
|
} )
|
|
@@ -102,8 +101,8 @@ export class AppModule {
|
|
|
102
101
|
|
|
103
102
|
## SecurityService
|
|
104
103
|
|
|
105
|
-
Since this has switched to using
|
|
106
|
-
IpBlockerProvider, it will automatically register the model.
|
|
104
|
+
Since this has switched to using the `@Inject('IP_BLOCKER')` model to be registered in your app. So by passing the
|
|
105
|
+
IpBlockerProvider, it will automatically register the model. More on this down below.
|
|
107
106
|
|
|
108
107
|
## Clean up cron
|
|
109
108
|
|
|
@@ -193,12 +192,14 @@ And then in your controllers simply use the `@UseGuards(IpBlacklistGuard)` decor
|
|
|
193
192
|
field called "Roles" which is an array of strings.
|
|
194
193
|
|
|
195
194
|
To use the `AdminGuard` just add the decorator to your controller method.
|
|
195
|
+
|
|
196
196
|
```typescript
|
|
197
|
-
@UseGuards(AdminGuard)
|
|
198
|
-
@Controller('my-contoller')
|
|
197
|
+
@UseGuards( AdminGuard )
|
|
198
|
+
@Controller( 'my-contoller' )
|
|
199
199
|
```
|
|
200
200
|
|
|
201
201
|
To use the `RoleGuard` just add the decorator to your controller method.
|
|
202
|
+
|
|
202
203
|
```typescript
|
|
203
204
|
@Roles( 'Admin', 'User' )
|
|
204
205
|
@UseGuards( RoleGuard )
|
|
@@ -216,9 +217,10 @@ const user = await this.jwtService.verifyAsync( token, {
|
|
|
216
217
|
} )
|
|
217
218
|
```
|
|
218
219
|
|
|
219
|
-
## The "
|
|
220
|
+
## The "admin panel" (e.g. security controller/endpoints):
|
|
220
221
|
|
|
221
|
-
To use the built in admin panel, you can
|
|
222
|
+
To use the built in admin panel, you can set the `enableAdminPanel: true` in the
|
|
223
|
+
configs [as shown in the](#quick-start), to set the available endpoints.
|
|
222
224
|
|
|
223
225
|
Available endpoints:
|
|
224
226
|
|
|
@@ -229,32 +231,7 @@ Available endpoints:
|
|
|
229
231
|
- GET `/security/blacklist`. This will return a list of all blacklisted IPs
|
|
230
232
|
- GET `/security/blacklist/:ip`. This will return the details of a specific IP address
|
|
231
233
|
- DELETE `/security/blacklist/:ip`. This will delete a specific IP address
|
|
232
|
-
-
|
|
233
|
-
|
|
234
|
-
Example of importing the controller and adding it to your AppModule:
|
|
235
|
-
|
|
236
|
-
```typescript
|
|
237
|
-
import { MiddlewareConsumer, Module, RequestMethod } from '@nestjs/common'
|
|
238
|
-
/* other imports */
|
|
239
|
-
import {
|
|
240
|
-
/* other imports */
|
|
241
|
-
SecurityController
|
|
242
|
-
} from 'nestjs-security-cli'
|
|
243
|
-
|
|
244
|
-
@Module( {
|
|
245
|
-
imports: [ /* other imports */ ],
|
|
246
|
-
controllers: [ /* other controllers */ SecurityController ], // Add this
|
|
247
|
-
providers: [ /* other providers */ ]
|
|
248
|
-
} )
|
|
249
|
-
export class AppModule {
|
|
250
|
-
configure(consumer: MiddlewareConsumer): void {
|
|
251
|
-
consumer
|
|
252
|
-
.apply( SecurityMiddleware )
|
|
253
|
-
.forRoutes( { path: '*', method: RequestMethod.ALL } )
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
```
|
|
234
|
+
- GET `/security/analytics`. This will return analytics for the last 24 hours
|
|
258
235
|
|
|
259
236
|
## Features
|
|
260
237
|
|
package/package.json
CHANGED