mirror of https://github.com/tiangolo/fastapi.git
📝 Update includes in `docs/en/docs/tutorial/security/oauth2-jwt.md` (#12650)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
parent
65f512052c
commit
1fc9a9ad3a
|
|
@ -116,57 +116,7 @@ And another utility to verify if a received password matches the hash stored.
|
|||
|
||||
And another one to authenticate and return a user.
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python hl_lines="8 49 56-57 60-61 70-76"
|
||||
{!> ../../docs_src/security/tutorial004_an_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="8 49 56-57 60-61 70-76"
|
||||
{!> ../../docs_src/security/tutorial004_an_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="8 50 57-58 61-62 71-77"
|
||||
{!> ../../docs_src/security/tutorial004_an.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.10+ non-Annotated
|
||||
|
||||
/// tip
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="7 48 55-56 59-60 69-75"
|
||||
{!> ../../docs_src/security/tutorial004_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="8 49 56-57 60-61 70-76"
|
||||
{!> ../../docs_src/security/tutorial004.py!}
|
||||
```
|
||||
|
||||
////
|
||||
{* ../../docs_src/security/tutorial004_an_py310.py hl[8,49,56:57,60:61,70:76] *}
|
||||
|
||||
/// note
|
||||
|
||||
|
|
@ -202,57 +152,7 @@ Define a Pydantic Model that will be used in the token endpoint for the response
|
|||
|
||||
Create a utility function to generate a new access token.
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python hl_lines="4 7 13-15 29-31 79-87"
|
||||
{!> ../../docs_src/security/tutorial004_an_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="4 7 13-15 29-31 79-87"
|
||||
{!> ../../docs_src/security/tutorial004_an_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="4 7 14-16 30-32 80-88"
|
||||
{!> ../../docs_src/security/tutorial004_an.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.10+ non-Annotated
|
||||
|
||||
/// tip
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="3 6 12-14 28-30 78-86"
|
||||
{!> ../../docs_src/security/tutorial004_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="4 7 13-15 29-31 79-87"
|
||||
{!> ../../docs_src/security/tutorial004.py!}
|
||||
```
|
||||
|
||||
////
|
||||
{* ../../docs_src/security/tutorial004_an_py310.py hl[4,7,13:15,29:31,79:87] *}
|
||||
|
||||
## Update the dependencies
|
||||
|
||||
|
|
@ -262,57 +162,7 @@ Decode the received token, verify it, and return the current user.
|
|||
|
||||
If the token is invalid, return an HTTP error right away.
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python hl_lines="90-107"
|
||||
{!> ../../docs_src/security/tutorial004_an_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="90-107"
|
||||
{!> ../../docs_src/security/tutorial004_an_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="91-108"
|
||||
{!> ../../docs_src/security/tutorial004_an.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.10+ non-Annotated
|
||||
|
||||
/// tip
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="89-106"
|
||||
{!> ../../docs_src/security/tutorial004_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="90-107"
|
||||
{!> ../../docs_src/security/tutorial004.py!}
|
||||
```
|
||||
|
||||
////
|
||||
{* ../../docs_src/security/tutorial004_an_py310.py hl[90:107] *}
|
||||
|
||||
## Update the `/token` *path operation*
|
||||
|
||||
|
|
@ -320,57 +170,7 @@ Create a `timedelta` with the expiration time of the token.
|
|||
|
||||
Create a real JWT access token and return it.
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python hl_lines="118-133"
|
||||
{!> ../../docs_src/security/tutorial004_an_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="118-133"
|
||||
{!> ../../docs_src/security/tutorial004_an_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="119-134"
|
||||
{!> ../../docs_src/security/tutorial004_an.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.10+ non-Annotated
|
||||
|
||||
/// tip
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="115-130"
|
||||
{!> ../../docs_src/security/tutorial004_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="116-131"
|
||||
{!> ../../docs_src/security/tutorial004.py!}
|
||||
```
|
||||
|
||||
////
|
||||
{* ../../docs_src/security/tutorial004_an_py310.py hl[118:133] *}
|
||||
|
||||
### Technical details about the JWT "subject" `sub`
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue