Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Update usage of Token model in security docs #9313

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/em/docs/advanced/security/oauth2-scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Oauth2️⃣ 🔧 🔬 "↔" 📇 🎻 🎏 🚀.

🥇, ➡️ 🔜 👀 🍕 👈 🔀 ⚪️➡️ 🖼 👑 **🔰 - 👩‍💻 🦮** [Oauth2️⃣ ⏮️ 🔐 (& 🔁), 📨 ⏮️ 🥙 🤝](../../tutorial/security/oauth2-jwt.md){.internal-link target=_blank}. 🔜 ⚙️ Oauth2️⃣ ↔:

```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 153"
```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 155"
{!../../../docs_src/security/tutorial005.py!}
```

Expand Down Expand Up @@ -93,7 +93,7 @@ Oauth2️⃣ 🔧 🔬 "↔" 📇 🎻 🎏 🚀.

✋️ 👆 🈸, 💂‍♂, 👆 🔜 ⚒ 💭 👆 🕴 🚮 ↔ 👈 👩‍💻 🤙 💪 ✔️, ⚖️ 🕐 👆 ✔️ 🔁.

```Python hl_lines="153"
```Python hl_lines="155"
{!../../../docs_src/security/tutorial005.py!}
```

Expand All @@ -118,7 +118,7 @@ Oauth2️⃣ 🔧 🔬 "↔" 📇 🎻 🎏 🚀.

👥 🔨 ⚫️ 📥 🎦 ❔ **FastAPI** 🍵 ↔ 📣 🎏 🎚.

```Python hl_lines="4 139 166"
```Python hl_lines="4 139 168"
{!../../../docs_src/security/tutorial005.py!}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/em/docs/tutorial/security/oauth2-jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ $ openssl rand -hex 32

=== "🐍 3️⃣.6️⃣ & 🔛"

```Python hl_lines="115-128"
```Python hl_lines="115-130"
{!> ../../../docs_src/security/tutorial004.py!}
```

=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"

```Python hl_lines="114-127"
```Python hl_lines="114-129"
{!> ../../../docs_src/security/tutorial004_py310.py!}
```

Expand Down
18 changes: 9 additions & 9 deletions docs/en/docs/advanced/security/oauth2-scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ First, let's quickly see the parts that change from the examples in the main **T
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="3 7 11 45 63 104 106-114 120-123 127-133 138 152"
```Python hl_lines="3 7 11 45 63 104 106-114 120-123 127-133 138 154"
{!> ../../../docs_src/security/tutorial005_py310.py!}
```

Expand All @@ -88,7 +88,7 @@ First, let's quickly see the parts that change from the examples in the main **T
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 153"
```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 155"
{!> ../../../docs_src/security/tutorial005_py39.py!}
```

Expand All @@ -97,7 +97,7 @@ First, let's quickly see the parts that change from the examples in the main **T
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 153"
```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 155"
{!> ../../../docs_src/security/tutorial005.py!}
```

Expand Down Expand Up @@ -199,7 +199,7 @@ And we return the scopes as part of the JWT token.
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="152"
```Python hl_lines="154"
{!> ../../../docs_src/security/tutorial005_py310.py!}
```

Expand All @@ -208,7 +208,7 @@ And we return the scopes as part of the JWT token.
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="153"
```Python hl_lines="155"
{!> ../../../docs_src/security/tutorial005_py39.py!}
```

Expand All @@ -217,7 +217,7 @@ And we return the scopes as part of the JWT token.
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="153"
```Python hl_lines="155"
{!> ../../../docs_src/security/tutorial005.py!}
```

Expand Down Expand Up @@ -265,7 +265,7 @@ In this case, it requires the scope `me` (it could require more than one scope).
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="3 138 165"
```Python hl_lines="3 138 167"
{!> ../../../docs_src/security/tutorial005_py310.py!}
```

Expand All @@ -274,7 +274,7 @@ In this case, it requires the scope `me` (it could require more than one scope).
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="4 139 166"
```Python hl_lines="4 139 168"
{!> ../../../docs_src/security/tutorial005_py39.py!}
```

Expand All @@ -283,7 +283,7 @@ In this case, it requires the scope `me` (it could require more than one scope).
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="4 139 166"
```Python hl_lines="4 139 168"
{!> ../../../docs_src/security/tutorial005.py!}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/en/docs/tutorial/security/oauth2-jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Create a real JWT access token and return it
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="114-127"
```Python hl_lines="114-129"
{!> ../../../docs_src/security/tutorial004_py310.py!}
```

Expand All @@ -294,7 +294,7 @@ Create a real JWT access token and return it
!!! tip
Prefer to use the `Annotated` version if possible.

```Python hl_lines="115-128"
```Python hl_lines="115-130"
{!> ../../../docs_src/security/tutorial004.py!}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/ja/docs/tutorial/security/oauth2-jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ JWTトークンの署名に使用するアルゴリズム`"HS256"`を指定し

JWTアクセストークンを作成し、それを返します。

```Python hl_lines="115-128"
```Python hl_lines="115-130"
{!../../../docs_src/security/tutorial004.py!}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/zh/docs/tutorial/security/oauth2-jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ $ openssl rand -hex 32

创建并返回真正的 JWT 访问令牌。

```Python hl_lines="115-128"
```Python hl_lines="115-130"
{!../../../docs_src/security/tutorial004.py!}
```

Expand Down
8 changes: 5 additions & 3 deletions docs_src/security/tutorial004.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ async def get_current_active_user(current_user: User = Depends(get_current_user)
return current_user


@app.post("/token", response_model=Token)
async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
@app.post("/token")
async def login_for_access_token(
form_data: OAuth2PasswordRequestForm = Depends()
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(
Expand All @@ -125,7 +127,7 @@ async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
return {"access_token": access_token, "token_type": "bearer"}
return Token(access_token=access_token, token_type="bearer")


@app.get("/users/me/", response_model=User)
Expand Down
6 changes: 3 additions & 3 deletions docs_src/security/tutorial004_an.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ async def get_current_active_user(
return current_user


@app.post("/token", response_model=Token)
@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
):
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(
Expand All @@ -130,7 +130,7 @@ async def login_for_access_token(
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
return {"access_token": access_token, "token_type": "bearer"}
return Token(access_token=access_token, token_type="bearer")


@app.get("/users/me/", response_model=User)
Expand Down
6 changes: 3 additions & 3 deletions docs_src/security/tutorial004_an_py310.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ async def get_current_active_user(
return current_user


@app.post("/token", response_model=Token)
@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
):
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(
Expand All @@ -129,7 +129,7 @@ async def login_for_access_token(
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
return {"access_token": access_token, "token_type": "bearer"}
return Token(access_token=access_token, token_type="bearer")


@app.get("/users/me/", response_model=User)
Expand Down
6 changes: 3 additions & 3 deletions docs_src/security/tutorial004_an_py39.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ async def get_current_active_user(
return current_user


@app.post("/token", response_model=Token)
@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
):
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(
Expand All @@ -129,7 +129,7 @@ async def login_for_access_token(
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
return {"access_token": access_token, "token_type": "bearer"}
return Token(access_token=access_token, token_type="bearer")


@app.get("/users/me/", response_model=User)
Expand Down
8 changes: 5 additions & 3 deletions docs_src/security/tutorial004_py310.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ async def get_current_active_user(current_user: User = Depends(get_current_user)
return current_user


@app.post("/token", response_model=Token)
async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
@app.post("/token")
async def login_for_access_token(
form_data: OAuth2PasswordRequestForm = Depends()
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(
Expand All @@ -124,7 +126,7 @@ async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
return {"access_token": access_token, "token_type": "bearer"}
return Token(access_token=access_token, token_type="bearer")


@app.get("/users/me/", response_model=User)
Expand Down
8 changes: 5 additions & 3 deletions docs_src/security/tutorial005.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ async def get_current_active_user(
return current_user


@app.post("/token", response_model=Token)
async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
@app.post("/token")
async def login_for_access_token(
form_data: OAuth2PasswordRequestForm = Depends()
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
Expand All @@ -153,7 +155,7 @@ async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(
data={"sub": user.username, "scopes": form_data.scopes},
expires_delta=access_token_expires,
)
return {"access_token": access_token, "token_type": "bearer"}
return Token(access_token=access_token, token_type="bearer")


@app.get("/users/me/", response_model=User)
Expand Down
6 changes: 3 additions & 3 deletions docs_src/security/tutorial005_an.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ async def get_current_active_user(
return current_user


@app.post("/token", response_model=Token)
@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
):
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
Expand All @@ -156,7 +156,7 @@ async def login_for_access_token(
data={"sub": user.username, "scopes": form_data.scopes},
expires_delta=access_token_expires,
)
return {"access_token": access_token, "token_type": "bearer"}
return Token(access_token=access_token, token_type="bearer")


@app.get("/users/me/", response_model=User)
Expand Down
6 changes: 3 additions & 3 deletions docs_src/security/tutorial005_an_py310.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ async def get_current_active_user(
return current_user


@app.post("/token", response_model=Token)
@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
):
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
Expand All @@ -155,7 +155,7 @@ async def login_for_access_token(
data={"sub": user.username, "scopes": form_data.scopes},
expires_delta=access_token_expires,
)
return {"access_token": access_token, "token_type": "bearer"}
return Token(access_token=access_token, token_type="bearer")


@app.get("/users/me/", response_model=User)
Expand Down
6 changes: 3 additions & 3 deletions docs_src/security/tutorial005_an_py39.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ async def get_current_active_user(
return current_user


@app.post("/token", response_model=Token)
@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
):
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
Expand All @@ -155,7 +155,7 @@ async def login_for_access_token(
data={"sub": user.username, "scopes": form_data.scopes},
expires_delta=access_token_expires,
)
return {"access_token": access_token, "token_type": "bearer"}
return Token(access_token=access_token, token_type="bearer")


@app.get("/users/me/", response_model=User)
Expand Down
8 changes: 5 additions & 3 deletions docs_src/security/tutorial005_py310.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ async def get_current_active_user(
return current_user


@app.post("/token", response_model=Token)
async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
@app.post("/token")
async def login_for_access_token(
form_data: OAuth2PasswordRequestForm = Depends()
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
Expand All @@ -152,7 +154,7 @@ async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(
data={"sub": user.username, "scopes": form_data.scopes},
expires_delta=access_token_expires,
)
return {"access_token": access_token, "token_type": "bearer"}
return Token(access_token=access_token, token_type="bearer")


@app.get("/users/me/", response_model=User)
Expand Down