Skip to content

Commit b2a0bc8

Browse files
author
IndominusByte
committed
Bump version: 0.3.0 -> 0.4.0
1 parent 70c6e88 commit b2a0bc8

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.4.0
2+
* Support set and unset cookies when returning a **Response** directly
3+
14
## 0.3.0
25
* **(Deprecated)** environment variable support
36
* Change name function **load_end()** -> **load_config()**

docs/api-doc.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,47 @@ In here you will find the API for everything exposed in this extension.
6565
* **user_claims**: Custom claims to include in this token. This data must be dictionary
6666
* Returns: An encoded refresh token
6767

68-
**set_access_cookies**(encoded_access_token, max_age=None)
68+
**set_access_cookies**(encoded_access_token, response=None, max_age=None)
6969
: *Configures the response to set access token in a cookie. This will also set the CSRF double submit values
7070
in a separate cookie.*
7171

7272
* Parameters:
7373
* **encoded_access_token**: The encoded access token to set in the cookies
74+
* **response**: The FastAPI response object to set the access cookies in
7475
* **max_age**: The max age of the cookie value should be `integer` the number of seconds
7576
* Returns: None
7677

77-
**set_refresh_cookies**(encoded_refresh_token, max_age=None)
78+
**set_refresh_cookies**(encoded_refresh_token, response=None, max_age=None)
7879
: *Configures the response to set refresh token in a cookie. This will also set the CSRF double submit values
7980
in a separate cookie.*
8081

8182
* Parameters:
8283
* **encoded_refresh_token**: The encoded refresh token to set in the cookies
84+
* **response**: The FastAPI response object to set the refresh cookies in
8385
* **max_age**: The max age of the cookie value should be `integer` the number of seconds
8486
* Returns: None
8587

86-
**unset_jwt_cookies**()
88+
**unset_jwt_cookies**(response=None)
8789
: *Unset (delete) all jwt stored in a cookies.*
8890

89-
**unset_access_cookies**()
91+
* Parameters:
92+
* **response**: The FastAPI response object to delete the JWT cookies in
93+
* Returns: None
94+
95+
**unset_access_cookies**(response=None)
9096
: *Remove access token and access CSRF double submit from the response cookies.*
9197

92-
**unset_refresh_cookies**()
98+
* Parameters:
99+
* **response**: The FastAPI response object to delete the access cookies in
100+
* Returns: None
101+
102+
**unset_refresh_cookies**(response=None)
93103
: *Remove refresh token and refresh CSRF double submit from the response cookies.*
94104

105+
* Parameters:
106+
* **response**: The FastAPI response object to delete the refresh cookies in
107+
* Returns: None
108+
95109
**get_raw_jwt**()
96110
: *This will return the python dictionary which has all of the claims of the JWT that is accessing the endpoint.
97111
If no JWT is currently present, return `None` instead.*

docs/usage/jwt-in-cookies.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ Highly recommended using JWT in cookies, if your frontend interacts with the bac
22

33
Here is a basic example of how to store JWT in cookies:
44

5+
!!! note
6+
You can also create cookies or unset cookies when returning a `Response` directly in your code.
7+
To do that, you can create a response then set the response in set cookies or unset cookies
8+
9+
``` python
10+
...
11+
response = JSONResponse(content={"msg":"Successfully login"})
12+
# Set the JWT and CSRF double submit cookies in the response
13+
Authorize.set_access_cookies(access_token,response)
14+
Authorize.set_refresh_cookies(refresh_token,response)
15+
return response
16+
```
17+
518
```python hl_lines="21 23 46-47 57 69"
619
{!../examples/jwt_in_cookies.py!}
720
```

fastapi_jwt_auth/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""FastAPI extension that provides JWT Auth support (secure, easy to use and lightweight)"""
22

3-
__version__ = "0.3.0"
3+
__version__ = "0.4.0"
44

55
from .auth_jwt import AuthJWT

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ markdown_extensions:
2525
- def_list
2626
- admonition
2727
- codehilite
28+
- pymdownx.tabbed
2829
- pymdownx.superfences
2930
- pymdownx.inlinehilite
3031

0 commit comments

Comments
 (0)