From 079f6bcfdc6702b7f19f8a2c122880c352e7e080 Mon Sep 17 00:00:00 2001 From: yeskela Date: Tue, 17 Dec 2024 17:32:29 +0300 Subject: [PATCH] upd validator for pydanticv2 --- fastapi_jwt_auth/config.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fastapi_jwt_auth/config.py b/fastapi_jwt_auth/config.py index c81b50c..231f8ed 100644 --- a/fastapi_jwt_auth/config.py +++ b/fastapi_jwt_auth/config.py @@ -5,7 +5,8 @@ validator, StrictBool, StrictInt, - StrictStr + StrictStr, + field_validator ) class LoadConfig(BaseModel): @@ -44,37 +45,37 @@ class LoadConfig(BaseModel): authjwt_refresh_csrf_header_name: Optional[StrictStr] = "X-CSRF-Token" authjwt_csrf_methods: Optional[Sequence[StrictStr]] = {'POST','PUT','PATCH','DELETE'} - @validator('authjwt_access_token_expires') + @field_validator('authjwt_access_token_expires') def validate_access_token_expires(cls, v): if v is True: raise ValueError("The 'authjwt_access_token_expires' only accept value False (bool)") return v - @validator('authjwt_refresh_token_expires') + @field_validator('authjwt_refresh_token_expires') def validate_refresh_token_expires(cls, v): if v is True: raise ValueError("The 'authjwt_refresh_token_expires' only accept value False (bool)") return v - @validator('authjwt_denylist_token_checks', each_item=True) + @field_validator('authjwt_denylist_token_checks', mode='before') def validate_denylist_token_checks(cls, v): if v not in ['access','refresh']: raise ValueError("The 'authjwt_denylist_token_checks' must be between 'access' or 'refresh'") return v - @validator('authjwt_token_location', each_item=True) + @field_validator('authjwt_token_location', mode='before') def validate_token_location(cls, v): if v not in ['headers','cookies']: raise ValueError("The 'authjwt_token_location' must be between 'headers' or 'cookies'") return v - @validator('authjwt_cookie_samesite') + @field_validator('authjwt_cookie_samesite') def validate_cookie_samesite(cls, v): if v not in ['strict','lax','none']: raise ValueError("The 'authjwt_cookie_samesite' must be between 'strict', 'lax', 'none'") return v - @validator('authjwt_csrf_methods', each_item=True) + @field_validator('authjwt_csrf_methods', mode='before') def validate_csrf_methods(cls, v): if v.upper() not in {"GET", "HEAD", "POST", "PUT", "DELETE", "PATCH"}: raise ValueError("The 'authjwt_csrf_methods' must be between http request methods")