After middleware
|
v
+-------------------------------------------+
| Global guards |
| array order from createApp |
+-------------------------------------------+
|
v
+-------------------------------------------+
| Controller guards |
| @UseGuards on the class |
+-------------------------------------------+
|
v
+-------------------------------------------+
| Method guards |
| @UseGuards on the method |
+-------------------------------------------+
|
v
+-------------------------------------------+
| Security guards |
| applied for @Security routes |
+-------------------------------------------+
|
+--> false -> 403 Forbidden
+--> Response -> short-circuit
+--> throw -> errorFormatter
|
v
Continue to interceptors
Guards are evaluated sequentially. If any guard denies access, the remaining guards and the controller method are skipped.
When a route has @Security("bearerAuth"), the framework instantiates BearerAuthGuard in the request scope and calls canActivate() with the scheme name and scopes.