Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX to Pydantic 2 #100

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions fastapi_jwt_auth/auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Callable, List
from datetime import timedelta


class AuthConfig:
_token = None
_token_location = {'headers'}
Expand All @@ -17,7 +18,7 @@ class AuthConfig:
_decode_issuer = None
_decode_audience = None
_denylist_enabled = False
_denylist_token_checks = {'access','refresh'}
_denylist_token_checks = {'access', 'refresh'}
_header_name = "Authorization"
_header_type = "Bearer"
_token_in_denylist_callback = None
Expand All @@ -42,7 +43,7 @@ class AuthConfig:
_refresh_csrf_cookie_path = "/"
_access_csrf_header_name = "X-CSRF-Token"
_refresh_csrf_header_name = "X-CSRF-Token"
_csrf_methods = {'POST','PUT','PATCH','DELETE'}
_csrf_methods = {'POST', 'PUT', 'PATCH', 'DELETE'}

@property
def jwt_in_cookies(self) -> bool:
Expand All @@ -53,9 +54,9 @@ def jwt_in_headers(self) -> bool:
return 'headers' in self._token_location

@classmethod
def load_config(cls, settings: Callable[...,List[tuple]]) -> "AuthConfig":
def load_config(cls, settings: Callable[..., List[tuple]]) -> "AuthConfig":
try:
config = LoadConfig(**{key.lower():value for key,value in settings()})
config = LoadConfig(**{key.lower(): value for key, value in settings()})

cls._token_location = config.authjwt_token_location
cls._secret_key = config.authjwt_secret_key
Expand Down Expand Up @@ -97,7 +98,7 @@ def load_config(cls, settings: Callable[...,List[tuple]]) -> "AuthConfig":
raise TypeError("Config must be pydantic 'BaseSettings' or list of tuple")

@classmethod
def token_in_denylist_loader(cls, callback: Callable[...,bool]) -> "AuthConfig":
def token_in_denylist_loader(cls, callback: Callable[..., bool]) -> "AuthConfig":
"""
This decorator sets the callback function that will be called when
a protected endpoint is accessed and will check if the JWT has been
Expand Down
Loading