Skip to content

Commit e67db4b

Browse files
author
IndominusByte
committed
dev cookie jwt
1 parent 975baeb commit e67db4b

File tree

5 files changed

+430
-105
lines changed

5 files changed

+430
-105
lines changed

fastapi_jwt_auth/auth_config.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
class AuthConfig:
77
_token = None
8+
_token_location = {'headers'}
9+
_response = None
10+
_request = None
11+
812
_secret_key = None
913
_public_key = None
1014
_private_key = None
@@ -22,6 +26,34 @@ class AuthConfig:
2226
_access_token_expires = timedelta(minutes=15)
2327
_refresh_token_expires = timedelta(days=30)
2428

29+
# option for create cookies
30+
_access_cookie_key = "access_token_cookie"
31+
_refresh_cookie_key = "refresh_token_cookie"
32+
_access_cookie_path = "/"
33+
_refresh_cookie_path = "/"
34+
_cookie_max_age = None
35+
_cookie_domain = None
36+
_cookie_secure = False
37+
_cookie_samesite = "lax"
38+
39+
# option for double submit csrf protection
40+
_cookie_csrf_protect = True
41+
_access_csrf_cookie_key = "csrf_access_token"
42+
_refresh_csrf_cookie_key = "csrf_refresh_token"
43+
_access_csrf_cookie_path = "/"
44+
_refresh_csrf_cookie_path = "/"
45+
_access_csrf_header_name = "X-CSRF-Token"
46+
_refresh_csrf_header_name = "X-CSRF-Token"
47+
_csrf_methods = {'POST','PUT','PATCH','DELETE'}
48+
49+
@property
50+
def jwt_in_cookies(self) -> bool:
51+
return 'cookies' in self._token_location
52+
53+
@property
54+
def jwt_in_headers(self) -> bool:
55+
return 'headers' in self._token_location
56+
2557
@classmethod
2658
def load_config(cls, settings: Callable[...,List[tuple]]) -> "AuthConfig":
2759
try:

0 commit comments

Comments
 (0)