Skip to content

Commit 3314a60

Browse files
committed
fixed import
1 parent 7ec6833 commit 3314a60

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

docs/security/authentication.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ class JWTAuthentication(HttpBearerAuthenticationHandler):
663663

664664
Let us make `JWTAuthentication` Handler available for ellar to use as shown below
665665

666-
```python title='server.py' linenums='1'
666+
```python title='project_name.server.py' linenums='1'
667667
import os
668668
from ellar.common.constants import ELLAR_CONFIG_MODULE
669669
from ellar.core.factory import AppFactory
@@ -693,7 +693,7 @@ Also, we need to remove `GlobalGuard` registration we did in `AuthModule`, so th
693693
Next, we register a simple guard `AuthenticationRequiredGuard` globally to the application. `AuthenticationRequiredGuard` is a simply guard
694694
that checks if a request has a valid user identity.
695695

696-
```python title='server.py' linenums='1'
696+
```python title='project_name.server.py' linenums='1'
697697
import os
698698
from ellar.common.constants import ELLAR_CONFIG_MODULE
699699
from ellar.core.factory import AppFactory
@@ -707,12 +707,13 @@ application = AppFactory.create_from_app_module(
707707
config_module=os.environ.get(
708708
ELLAR_CONFIG_MODULE, "project_name.config:DevelopmentConfig"
709709
),
710-
global_guards=[AuthenticatedRequiredGuard]
710+
global_guards=[AuthenticatedRequiredGuard('JWTAuthentication')]
711711
)
712712
application.add_authentication_schemes(JWTAuthentication)
713713
```
714714
We need to refactor auth controller and mark refresh and sign_in function as public routes
715-
```python
715+
716+
```python title='auth.controller.py' linenums='1'
716717
from ellar.common import Controller, ControllerBase, post, Body, get
717718
from ellar.auth import SkipAuth
718719
from ellar.openapi import ApiTags

ellar/auth/guard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import starlette.status
44
from ellar.common import GuardCanActivate, IExecutionContext, constants
5-
from ellar.core import Reflector
65

76

87
class AuthenticatedRequiredGuard(GuardCanActivate):
@@ -11,6 +10,8 @@ class AuthenticatedRequiredGuard(GuardCanActivate):
1110
def __init__(
1211
self, authentication_scheme: t.Optional[str], openapi_scope: t.List
1312
) -> None:
13+
from ellar.core import Reflector
14+
1415
self.authentication_scheme = authentication_scheme
1516
self.openapi_scope = openapi_scope or []
1617
self.reflector = Reflector()

0 commit comments

Comments
 (0)