You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -550,13 +549,10 @@ Let us define a mechanism for declaring routes as anonymous or public.
550
549
from ellar.common.serializer.guard import (
551
550
HTTPAuthorizationCredentials,
552
551
)
553
-
from ellar.common import IExecutionContext, set_metadata, constants, GuardCanActivate
552
+
from ellar.common import IExecutionContext, set_metadata, constants, GuardCanActivate, logger
554
553
from ellar.core.guards import GuardHttpBearerAuth
555
-
from ellar.core import Reflector
556
554
from ellar.di import injectable
557
555
from ellar_jwt import JWTService
558
-
from ellar.common.logger import logger
559
-
from ellar.common import logger, IExecutionContext
560
556
561
557
562
558
def allow_any() -> t.Callable:
@@ -619,3 +615,145 @@ class AuthController(ControllerBase):
619
615
```
620
616
621
617
## **2. Authentication Schemes**
618
+
619
+
Authentication scheme is another strategy for identifying the user who is using the application. The difference between it and
620
+
and Guard strategy is your identification executed at middleware layer when processing incoming request while guard execution
621
+
happens just before route function is executed.
622
+
623
+
Ellar provides `BaseAuthenticationHandler` contract which defines what is required to set up any authentication strategy.
624
+
We are going to make some modifications on the existing project to see how we can achieve the same result and to show how authentication handlers in ellar.
625
+
626
+
### Creating a JWT Authentication Handler
627
+
Just like AuthGuard, we need to create its equivalent. But first we need to create a `auth_scheme.py` at the root level
628
+
of your application for us to define a `JWTAuthentication` handler.
Unlike guards, Authentication handlers are registered global by default as shown in the above illustration.
683
+
Also, we need to remove `GlobalGuard` registration we did in `AuthModule`, so that we dont have too user identification checks.
684
+
685
+
!!!note
686
+
In the above illustration, we added JWTAuthentication as a type. This means JWTAuthentication instance will be created by DI. We can using this method because we want to inject `JWTService`.
687
+
But if you don't have any need for DI injection, you can use the below.
0 commit comments