From 77d7811210845fbbf68fa2298443c1ab505cacee Mon Sep 17 00:00:00 2001 From: jeanelkhoury Date: Tue, 19 Mar 2024 11:54:18 +0100 Subject: [PATCH 1/4] [master]: config.py changed to support pydantic 2.* --- fastapi_jwt_auth/config.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fastapi_jwt_auth/config.py b/fastapi_jwt_auth/config.py index c81b50c..1840c78 100644 --- a/fastapi_jwt_auth/config.py +++ b/fastapi_jwt_auth/config.py @@ -1,5 +1,5 @@ from datetime import timedelta -from typing import Optional, Union, Sequence, List +from typing import Optional, Union, List from pydantic import ( BaseModel, validator, @@ -9,7 +9,7 @@ ) class LoadConfig(BaseModel): - authjwt_token_location: Optional[Sequence[StrictStr]] = {'headers'} + authjwt_token_location: Optional[List[StrictStr]] = {'headers'} authjwt_secret_key: Optional[StrictStr] = None authjwt_public_key: Optional[StrictStr] = None authjwt_private_key: Optional[StrictStr] = None @@ -18,9 +18,9 @@ class LoadConfig(BaseModel): authjwt_decode_leeway: Optional[Union[StrictInt,timedelta]] = 0 authjwt_encode_issuer: Optional[StrictStr] = None authjwt_decode_issuer: Optional[StrictStr] = None - authjwt_decode_audience: Optional[Union[StrictStr,Sequence[StrictStr]]] = None + authjwt_decode_audience: Optional[Union[StrictStr,List[StrictStr]]] = None authjwt_denylist_enabled: Optional[StrictBool] = False - authjwt_denylist_token_checks: Optional[Sequence[StrictStr]] = {'access','refresh'} + authjwt_denylist_token_checks: Optional[List[StrictStr]] = {'access','refresh'} authjwt_header_name: Optional[StrictStr] = "Authorization" authjwt_header_type: Optional[StrictStr] = "Bearer" authjwt_access_token_expires: Optional[Union[StrictBool,StrictInt,timedelta]] = timedelta(minutes=15) @@ -42,7 +42,7 @@ class LoadConfig(BaseModel): authjwt_refresh_csrf_cookie_path: Optional[StrictStr] = "/" authjwt_access_csrf_header_name: Optional[StrictStr] = "X-CSRF-Token" authjwt_refresh_csrf_header_name: Optional[StrictStr] = "X-CSRF-Token" - authjwt_csrf_methods: Optional[Sequence[StrictStr]] = {'POST','PUT','PATCH','DELETE'} + authjwt_csrf_methods: Optional[List[StrictStr]] = {'POST','PUT','PATCH','DELETE'} @validator('authjwt_access_token_expires') def validate_access_token_expires(cls, v): @@ -81,5 +81,5 @@ def validate_csrf_methods(cls, v): return v.upper() class Config: - min_anystr_length = 1 - anystr_strip_whitespace = True + str_min_length = 1 + str_strip_whitespace = True From ad90264ee419ae05ad382e94c93448859af7c1d7 Mon Sep 17 00:00:00 2001 From: jeanelkhoury Date: Tue, 19 Mar 2024 12:51:12 +0100 Subject: [PATCH 2/4] [master]: library uploaded to pipy --- .gitignore | 1 + CHANGELOG.md | 41 ---------------------------------- mkdocs.yml | 60 -------------------------------------------------- pyproject.toml | 54 --------------------------------------------- 4 files changed, 1 insertion(+), 155 deletions(-) delete mode 100644 CHANGELOG.md delete mode 100644 mkdocs.yml delete mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index e3ea440..de79400 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ var/ .installed.cfg *.egg .pytest_cache +setup.py # coverage .coverage diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 04a87a4..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,41 +0,0 @@ -## 0.5.0 -* Support for WebSocket authorization *(Thanks to @SelfhostedPro for make issues)* -* Function **get_raw_jwt()** can pass parameter encoded_token - -## 0.4.0 -* Support set and unset cookies when returning a **Response** directly - -## 0.3.0 -* **(Deprecated)** environment variable support -* Change name function **load_end()** -> **load_config()** -* Change name function **get_jwt_identity()** -> **get_jwt_subject()** -* Change name identity claims to standard claims sub *(Thanks to @rassie for suggestion)* -* Additional headers in claims -* Get additional headers claims from request or parsing token directly -* Leeway exp claim decode token -* Dynamic token expires time -* Change name **blacklist** -> **denylist** -* Denylist custom check refresh and access tokens -* Issuer claim -* Audience claim -* Jwt decode algorithms -* Dynamic algorithm create token -* Token multiple location -* Support RSA encryption *(Thanks to @jet10000 for make issues)* -* Custom header name and type -* Custom error message key and status code -* JWT in cookies *(Thanks to @m4nuC for make issues)* -* Add Additional claims -* Add Documentation PR #9 by @paulussimanjuntak - -## 0.2.0 - -* Call create_token and get_jti function must be from dependency injection -* Improve blacklist loader -* Can load env from pydantic -* Add docs on readme how to use without dependency injection and example on multiple files -* Fix raise jwt exception PR #1 by @ironslob - -## 0.1.0 - -* Initial release. diff --git a/mkdocs.yml b/mkdocs.yml deleted file mode 100644 index a89a921..0000000 --- a/mkdocs.yml +++ /dev/null @@ -1,60 +0,0 @@ -site_name: FastAPI JWT Auth -site_description: FastAPI extension that provides JWT Auth support (secure, easy to use, and lightweight) -theme: - name: material - palette: - primary: black - -repo_name: IndominusByte/fastapi-jwt-auth -repo_url: https://github.com/IndominusByte/fastapi-jwt-auth - -markdown_extensions: - - markdown_include.include: - base_path: docs - - toc: - permalink: true - - pymdownx.highlight: - linenums_style: pymdownx.inline - - pymdownx.magiclink: - user: IndominusByte - repo: fastapi-jwt-auth - repo_url_shorthand: true - - pymdownx.emoji: - emoji_index: !!python/name:pymdownx.emoji.twemoji - - attr_list - - def_list - - admonition - - codehilite - - pymdownx.tabbed - - pymdownx.superfences - - pymdownx.inlinehilite - -nav: - - About: index.md - - Usage: - - Basic Usage: usage/basic.md - - Partially Protecting: usage/optional.md - - Refresh Tokens: usage/refresh.md - - Freshness Tokens: usage/freshness.md - - Revoking Tokens: usage/revoking.md - - JWT in Cookies: usage/jwt-in-cookies.md - - Advanced Usage: - - Additional claims: advanced-usage/additional-claims.md - - Asymmetric Algorithm: advanced-usage/asymmetric.md - - Dynamic Token Expires: advanced-usage/dynamic-expires.md - - Dynamic Token Algorithm: advanced-usage/dynamic-algorithm.md - - WebSocket Protecting: advanced-usage/websocket.md - - Bigger Applications: advanced-usage/bigger-app.md - - Generate Documentation: advanced-usage/generate-docs.md - - Configuration Options: - - General Options: configuration/general.md - - Headers Options: configuration/headers.md - - Denylist Options: configuration/denylist.md - - Cookies Options: configuration/cookies.md - - CSRF Options: configuration/csrf.md - - API Documentation: api-doc.md - - Development - Contributing: contributing.md - - Release Notes: release-notes.md - -extra_css: - - 'css/custom.css' diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 6c4acab..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,54 +0,0 @@ -[build-system] -requires = ["flit_core>=2,<4"] -build-backend = "flit_core.buildapi" - -[tool.flit.metadata] -module = "fastapi_jwt_auth" -dist-name = "fastapi-jwt-auth" -author = "Nyoman Pradipta Dewantara" -author-email = "nyomanpradipta120@gmail.com" -home-page = "https://github.com/IndominusByte/fastapi-jwt-auth" - -classifiers = [ - "Environment :: Web Environment", - "Intended Audience :: Developers", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Topic :: Internet :: WWW/HTTP :: Dynamic Content", - "Topic :: Software Development :: Libraries :: Python Modules" -] - -requires = [ - "fastapi>=0.61.0", - "PyJWT>=1.7.1,<2.0.0" -] - -description-file = "README.md" -requires-python = ">=3.6" - -[tool.flit.metadata.urls] -Documentation = "https://indominusbyte.github.io/fastapi-jwt-auth/" - -[tool.flit.metadata.requires-extra] -test = [ - "pytest==6.0.1", - "pytest-cov==2.10.0", - "coveralls==2.1.2" -] - -doc = [ - "mkdocs>=1.1.2,<2.0.0", - "mkdocs-material>=5.5.0,<6.0.0", - "markdown-include>=0.5.1,<0.6.0" -] - -dev = [ - "cryptography>=2.6,<4.0.0", - "uvicorn>=0.11.5,<0.12.0" -] - -asymmetric = ["cryptography>=2.6,<4.0.0"] From a78cbf4a46d1ab8050564a6b7f65721189d3f6b9 Mon Sep 17 00:00:00 2001 From: Jean El Khoury Date: Tue, 19 Mar 2024 12:58:00 +0100 Subject: [PATCH 3/4] Update README.md --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a7735e6..577e521 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,19 @@ **Documentation**: https://indominusbyte.github.io/fastapi-jwt-auth -**Source Code**: https://github.com/IndominusByte/fastapi-jwt-auth +**Source Code**: https://github.com/jean-ek/fastapi-jwt-authV2 + +**Original Legacy Library** https://github.com/IndominusByte/fastapi-jwt-auth --- +## Notes: + This is a modified version of the original fastapi-jwt-auth library to add compatibility with pydantic versions 2.* + ## Features FastAPI extension that provides JWT Auth support (secure, easy to use and lightweight), if you were familiar with flask-jwt-extended this extension suitable for you, cause this extension inspired by flask-jwt-extended 😀 +- Compatible with pydantic 2.* versions - Access tokens and refresh tokens - Freshness Tokens - Revoking Tokens @@ -29,12 +35,7 @@ FastAPI extension that provides JWT Auth support (secure, easy to use and lightw The easiest way to start working with this extension with pip ```bash -pip install fastapi-jwt-auth -``` - -If you want to use asymmetric (public/private) key signing algorithms, include the asymmetric extra requirements. -```bash -pip install 'fastapi-jwt-auth[asymmetric]' +pip install fastapi-jwt-auth-compat ``` ## License From 50a45f5dfb22d4a236307bb6e619eba6822a13a4 Mon Sep 17 00:00:00 2001 From: Jean El Khoury Date: Tue, 19 Mar 2024 12:58:18 +0100 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 577e521..f93ad25 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ **Source Code**: https://github.com/jean-ek/fastapi-jwt-authV2 -**Original Legacy Library** https://github.com/IndominusByte/fastapi-jwt-auth +**Original Legacy Library**: https://github.com/IndominusByte/fastapi-jwt-auth ---