fastapi-jwt 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. fastapi_jwt-0.3.1/LICENSE +21 -0
  2. fastapi_jwt-0.3.1/PKG-INFO +147 -0
  3. fastapi_jwt-0.3.1/README.md +97 -0
  4. fastapi_jwt-0.3.1/VERSION +1 -0
  5. fastapi_jwt-0.3.1/fastapi_jwt/__init__.py +2 -0
  6. fastapi_jwt-0.3.1/fastapi_jwt/jwt.py +448 -0
  7. fastapi_jwt-0.3.1/fastapi_jwt/jwt_backends/__init__.py +4 -0
  8. fastapi_jwt-0.3.1/fastapi_jwt/jwt_backends/abstract_backend.py +25 -0
  9. fastapi_jwt-0.3.1/fastapi_jwt/jwt_backends/authlib_backend.py +48 -0
  10. fastapi_jwt-0.3.1/fastapi_jwt/jwt_backends/python_jose_backend.py +46 -0
  11. fastapi_jwt-0.3.1/fastapi_jwt/py.typed +0 -0
  12. fastapi_jwt-0.3.1/fastapi_jwt.egg-info/PKG-INFO +147 -0
  13. fastapi_jwt-0.3.1/fastapi_jwt.egg-info/SOURCES.txt +27 -0
  14. fastapi_jwt-0.3.1/fastapi_jwt.egg-info/dependency_links.txt +1 -0
  15. fastapi_jwt-0.3.1/fastapi_jwt.egg-info/requires.txt +31 -0
  16. fastapi_jwt-0.3.1/fastapi_jwt.egg-info/top_level.txt +1 -0
  17. fastapi_jwt-0.3.1/pyproject.toml +121 -0
  18. fastapi_jwt-0.3.1/setup.cfg +17 -0
  19. fastapi_jwt-0.3.1/setup.py +3 -0
  20. fastapi_jwt-0.3.1/tests/test_security_jwt_bearer.py +163 -0
  21. fastapi_jwt-0.3.1/tests/test_security_jwt_bearer_optional.py +170 -0
  22. fastapi_jwt-0.3.1/tests/test_security_jwt_cookie.py +158 -0
  23. fastapi_jwt-0.3.1/tests/test_security_jwt_cookie_optional.py +166 -0
  24. fastapi_jwt-0.3.1/tests/test_security_jwt_general.py +235 -0
  25. fastapi_jwt-0.3.1/tests/test_security_jwt_general_optional.py +246 -0
  26. fastapi_jwt-0.3.1/tests/test_security_jwt_multiple_places.py +223 -0
  27. fastapi_jwt-0.3.1/tests/test_security_jwt_set_cookie.py +99 -0
  28. fastapi_jwt-0.3.1/tests/test_security_patch.py +95 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Konstantin Chernyshev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastapi-jwt
3
+ Version: 0.3.1
4
+ Summary: `FastAPI` extension for JTW Auth
5
+ Author: Konstantin Chernyshev
6
+ License: MIT License
7
+ Project-URL: homepage, https://github.com/k4black/fastapi-jwt
8
+ Project-URL: documentation, https://k4black.github.io/fastapi-jwt/
9
+ Project-URL: Security advisories, https://github.com/k4black/fastapi-jwt/security/advisories
10
+ Project-URL: Report a vulnerability, https://github.com/k4black/fastapi-jwt/security/advisories/new
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Information Technology
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: fastapi>=0.50.0
23
+ Provides-Extra: authlib
24
+ Requires-Dist: Authlib>=1.3.0; extra == "authlib"
25
+ Provides-Extra: python-jose
26
+ Requires-Dist: python-jose[cryptography]>=3.3.0; extra == "python-jose"
27
+ Provides-Extra: test
28
+ Requires-Dist: Authlib>=1.3.0; extra == "test"
29
+ Requires-Dist: python-jose[cryptography]>=3.3.0; extra == "test"
30
+ Requires-Dist: httpx<1.0.0,>=0.23.0; extra == "test"
31
+ Requires-Dist: pytest<9.0.0,>=7.0.0; extra == "test"
32
+ Requires-Dist: pytest-cov<6.0.0,>=4.0.0; extra == "test"
33
+ Requires-Dist: pytest-mock<4.0.0,>=3.0.0; extra == "test"
34
+ Requires-Dist: requests<3.0.0,>=2.28.0; extra == "test"
35
+ Requires-Dist: black==24.4.2; extra == "test"
36
+ Requires-Dist: mypy<2.0.0,>=1.0.0; extra == "test"
37
+ Requires-Dist: flake8<8.0.0,>=6.0.0; extra == "test"
38
+ Requires-Dist: ruff<1.0.0,>=0.1.0; extra == "test"
39
+ Requires-Dist: isort<6.0.0,>=5.11.0; extra == "test"
40
+ Requires-Dist: types-python-jose==3.3.4.8; extra == "test"
41
+ Provides-Extra: docs
42
+ Requires-Dist: mkdocs<2.0.0,>=1.4.0; extra == "docs"
43
+ Requires-Dist: mkdocs-material<10.0.0,>=9.0.0; extra == "docs"
44
+ Requires-Dist: MkAutoDoc<1.0.0,>=0.2.0; extra == "docs"
45
+ Requires-Dist: lazydocs<1.0.0,>=0.4.5; extra == "docs"
46
+ Requires-Dist: mkdocs-include-markdown-plugin<7.0.0,>=4.0.0; extra == "docs"
47
+ Requires-Dist: mkdocs-awesome-pages-plugin<3.0.0,>=2.8.0; extra == "docs"
48
+ Requires-Dist: mike<3.0.0,>=1.1.0; extra == "docs"
49
+ Dynamic: license-file
50
+
51
+ # fastapi-jwt
52
+
53
+ [![Test](https://github.com/k4black/fastapi-jwt/actions/workflows/test.yml/badge.svg)](https://github.com/k4black/fastapi-jwt/actions/workflows/test.yml)
54
+ [![Publish](https://github.com/k4black/fastapi-jwt/actions/workflows/publish.yml/badge.svg)](https://github.com/k4black/fastapi-jwt/actions/workflows/publish.yml)
55
+ [![codecov](https://codecov.io/gh/k4black/fastapi-jwt/branch/master/graph/badge.svg?token=3F9J850FX2)](https://codecov.io/gh/k4black/fastapi-jwt)
56
+ [![pypi](https://img.shields.io/pypi/v/fastapi-jwt)](https://pypi.org/project/fastapi-jwt/)
57
+
58
+ FastAPI native extension, easy and simple JWT auth
59
+
60
+ ---
61
+
62
+
63
+ **Documentation:** [k4black.github.io/fastapi-jwt](https://k4black.github.io/fastapi-jwt/)
64
+ **Source Code:** [github.com/k4black/fastapi-jwt](https://github.com/k4black/fastapi-jwt/)
65
+
66
+ **Security:** [Published advisories](https://github.com/k4black/fastapi-jwt/security/advisories) · [Report a vulnerability privately](https://github.com/k4black/fastapi-jwt/security/advisories/new)
67
+
68
+
69
+ ## Features
70
+ * OpenAPI schema generation
71
+ * Native integration with FastAPI
72
+ * Access/Refresh JWT
73
+ * JTI
74
+ * Cookie setting
75
+
76
+
77
+ ## Installation
78
+ You can access package [fastapi-jwt in pypi](https://pypi.org/project/fastapi-jwt/)
79
+ ```shell
80
+ pip install fastapi-jwt[authlib]
81
+ # or
82
+ pip install fastapi-jwt[python_jose]
83
+ ```
84
+
85
+ The fastapi-jwt will choose the backend automatically if library is installed with the following priority:
86
+ 1. authlib
87
+ 2. python_jose (deprecated)
88
+
89
+ ## Usage
90
+ This library made in fastapi style, so it can be used as standard security features
91
+
92
+ ```python
93
+ from fastapi import FastAPI, Security, Response
94
+ from fastapi_jwt import JwtAuthorizationCredentials, JwtAccessBearer
95
+
96
+
97
+ app = FastAPI()
98
+ access_security = JwtAccessBearer(secret_key="secret_key", auto_error=True)
99
+
100
+
101
+ @app.post("/auth")
102
+ def auth():
103
+ subject = {"username": "username", "role": "user"}
104
+ return {"access_token": access_security.create_access_token(subject=subject)}
105
+
106
+ @app.post("/auth_cookie")
107
+ def auth(response: Response):
108
+ subject = {"username": "username", "role": "user"}
109
+ access_token = access_security.create_access_token(subject=subject)
110
+ access_security.set_access_cookie(response, access_token)
111
+ return {"access_token": access_token}
112
+
113
+
114
+ @app.get("/users/me")
115
+ def read_current_user(
116
+ credentials: JwtAuthorizationCredentials = Security(access_security),
117
+ ):
118
+ return {"username": credentials["username"], "role": credentials["role"]}
119
+ ```
120
+
121
+ For more examples see usage docs
122
+
123
+
124
+ ## Alternatives
125
+
126
+ * FastAPI docs suggest [writing it manually](https://fastapi.tiangolo.com/tutorial/security/oauth2-jwt/), but
127
+ * code duplication
128
+ * opportunity for bugs
129
+
130
+ * There is nice [fastapi-jwt-auth](https://github.com/IndominusByte/fastapi-jwt-auth/), but
131
+ * poorly supported
132
+ * not "FastAPI-style" (not native functions parameters)
133
+
134
+ ## FastAPI Integration
135
+
136
+ [FastAPI PR #3305](https://github.com/fastapi/fastapi/pull/3305) is closed.
137
+ FastAPI declined built-in JWT support because token handling belongs in an external package.
138
+ The maintainer also declined the additional python-jose dependency.
139
+ See the [maintainer response](https://github.com/fastapi/fastapi/pull/3305#issuecomment-3121608562).
140
+
141
+ ## Requirements
142
+
143
+ * `fastapi`
144
+ * `authlib` or `python-jose[cryptography]` (deprecated)
145
+
146
+ ## License
147
+ This project is licensed under the terms of the MIT license.
@@ -0,0 +1,97 @@
1
+ # fastapi-jwt
2
+
3
+ [![Test](https://github.com/k4black/fastapi-jwt/actions/workflows/test.yml/badge.svg)](https://github.com/k4black/fastapi-jwt/actions/workflows/test.yml)
4
+ [![Publish](https://github.com/k4black/fastapi-jwt/actions/workflows/publish.yml/badge.svg)](https://github.com/k4black/fastapi-jwt/actions/workflows/publish.yml)
5
+ [![codecov](https://codecov.io/gh/k4black/fastapi-jwt/branch/master/graph/badge.svg?token=3F9J850FX2)](https://codecov.io/gh/k4black/fastapi-jwt)
6
+ [![pypi](https://img.shields.io/pypi/v/fastapi-jwt)](https://pypi.org/project/fastapi-jwt/)
7
+
8
+ FastAPI native extension, easy and simple JWT auth
9
+
10
+ ---
11
+
12
+
13
+ **Documentation:** [k4black.github.io/fastapi-jwt](https://k4black.github.io/fastapi-jwt/)
14
+ **Source Code:** [github.com/k4black/fastapi-jwt](https://github.com/k4black/fastapi-jwt/)
15
+
16
+ **Security:** [Published advisories](https://github.com/k4black/fastapi-jwt/security/advisories) · [Report a vulnerability privately](https://github.com/k4black/fastapi-jwt/security/advisories/new)
17
+
18
+
19
+ ## Features
20
+ * OpenAPI schema generation
21
+ * Native integration with FastAPI
22
+ * Access/Refresh JWT
23
+ * JTI
24
+ * Cookie setting
25
+
26
+
27
+ ## Installation
28
+ You can access package [fastapi-jwt in pypi](https://pypi.org/project/fastapi-jwt/)
29
+ ```shell
30
+ pip install fastapi-jwt[authlib]
31
+ # or
32
+ pip install fastapi-jwt[python_jose]
33
+ ```
34
+
35
+ The fastapi-jwt will choose the backend automatically if library is installed with the following priority:
36
+ 1. authlib
37
+ 2. python_jose (deprecated)
38
+
39
+ ## Usage
40
+ This library made in fastapi style, so it can be used as standard security features
41
+
42
+ ```python
43
+ from fastapi import FastAPI, Security, Response
44
+ from fastapi_jwt import JwtAuthorizationCredentials, JwtAccessBearer
45
+
46
+
47
+ app = FastAPI()
48
+ access_security = JwtAccessBearer(secret_key="secret_key", auto_error=True)
49
+
50
+
51
+ @app.post("/auth")
52
+ def auth():
53
+ subject = {"username": "username", "role": "user"}
54
+ return {"access_token": access_security.create_access_token(subject=subject)}
55
+
56
+ @app.post("/auth_cookie")
57
+ def auth(response: Response):
58
+ subject = {"username": "username", "role": "user"}
59
+ access_token = access_security.create_access_token(subject=subject)
60
+ access_security.set_access_cookie(response, access_token)
61
+ return {"access_token": access_token}
62
+
63
+
64
+ @app.get("/users/me")
65
+ def read_current_user(
66
+ credentials: JwtAuthorizationCredentials = Security(access_security),
67
+ ):
68
+ return {"username": credentials["username"], "role": credentials["role"]}
69
+ ```
70
+
71
+ For more examples see usage docs
72
+
73
+
74
+ ## Alternatives
75
+
76
+ * FastAPI docs suggest [writing it manually](https://fastapi.tiangolo.com/tutorial/security/oauth2-jwt/), but
77
+ * code duplication
78
+ * opportunity for bugs
79
+
80
+ * There is nice [fastapi-jwt-auth](https://github.com/IndominusByte/fastapi-jwt-auth/), but
81
+ * poorly supported
82
+ * not "FastAPI-style" (not native functions parameters)
83
+
84
+ ## FastAPI Integration
85
+
86
+ [FastAPI PR #3305](https://github.com/fastapi/fastapi/pull/3305) is closed.
87
+ FastAPI declined built-in JWT support because token handling belongs in an external package.
88
+ The maintainer also declined the additional python-jose dependency.
89
+ See the [maintainer response](https://github.com/fastapi/fastapi/pull/3305#issuecomment-3121608562).
90
+
91
+ ## Requirements
92
+
93
+ * `fastapi`
94
+ * `authlib` or `python-jose[cryptography]` (deprecated)
95
+
96
+ ## License
97
+ This project is licensed under the terms of the MIT license.
@@ -0,0 +1 @@
1
+ 0.3.1
@@ -0,0 +1,2 @@
1
+ from .jwt import * # noqa: F401, F403
2
+ from .jwt_backends import * # noqa: F401, F403