mirror of https://github.com/tiangolo/fastapi.git
🎨 Auto format
This commit is contained in:
parent
53385c02e4
commit
0ccc4a233b
|
|
@ -1,5 +1,5 @@
|
|||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Annotated, Union
|
||||
from typing import Annotated
|
||||
|
||||
import jwt
|
||||
from fastapi import Depends, FastAPI, HTTPException, Security, status
|
||||
|
|
@ -43,15 +43,15 @@ class Token(BaseModel):
|
|||
|
||||
|
||||
class TokenData(BaseModel):
|
||||
username: Union[str, None] = None
|
||||
username: str | None = None
|
||||
scopes: list[str] = []
|
||||
|
||||
|
||||
class User(BaseModel):
|
||||
username: str
|
||||
email: Union[str, None] = None
|
||||
full_name: Union[str, None] = None
|
||||
disabled: Union[bool, None] = None
|
||||
email: str | None = None
|
||||
full_name: str | None = None
|
||||
disabled: bool | None = None
|
||||
|
||||
|
||||
class UserInDB(User):
|
||||
|
|
@ -91,7 +91,7 @@ def authenticate_user(fake_db, username: str, password: str):
|
|||
return user
|
||||
|
||||
|
||||
def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None):
|
||||
def create_access_token(data: dict, expires_delta: timedelta | None = None):
|
||||
to_encode = data.copy()
|
||||
if expires_delta:
|
||||
expire = datetime.now(timezone.utc) + expires_delta
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Union
|
||||
|
||||
import jwt
|
||||
from fastapi import Depends, FastAPI, HTTPException, Security, status
|
||||
|
|
@ -43,15 +42,15 @@ class Token(BaseModel):
|
|||
|
||||
|
||||
class TokenData(BaseModel):
|
||||
username: Union[str, None] = None
|
||||
username: str | None = None
|
||||
scopes: list[str] = []
|
||||
|
||||
|
||||
class User(BaseModel):
|
||||
username: str
|
||||
email: Union[str, None] = None
|
||||
full_name: Union[str, None] = None
|
||||
disabled: Union[bool, None] = None
|
||||
email: str | None = None
|
||||
full_name: str | None = None
|
||||
disabled: bool | None = None
|
||||
|
||||
|
||||
class UserInDB(User):
|
||||
|
|
@ -91,7 +90,7 @@ def authenticate_user(fake_db, username: str, password: str):
|
|||
return user
|
||||
|
||||
|
||||
def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None):
|
||||
def create_access_token(data: dict, expires_delta: timedelta | None = None):
|
||||
to_encode = data.copy()
|
||||
if expires_delta:
|
||||
expire = datetime.now(timezone.utc) + expires_delta
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Annotated, Union
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import FastAPI, HTTPException, Security
|
||||
from fastapi.security import (
|
||||
|
|
@ -13,7 +13,7 @@ oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
|||
|
||||
|
||||
def process_auth(
|
||||
credentials: Annotated[Union[str, None], Security(oauth2_scheme)],
|
||||
credentials: Annotated[str | None, Security(oauth2_scheme)],
|
||||
security_scopes: SecurityScopes,
|
||||
):
|
||||
# This is an incorrect way of using it, this is not checking if the scopes are
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Ref: https://github.com/fastapi/fastapi/issues/14454
|
||||
|
||||
from typing import Annotated, Optional
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Depends, FastAPI, Security
|
||||
from fastapi.security import OAuth2AuthorizationCodeBearer
|
||||
|
|
@ -47,13 +47,13 @@ router = APIRouter(dependencies=[Security(oauth2_scheme, oauth_scopes=["read"])]
|
|||
|
||||
|
||||
@router.get("/items/")
|
||||
async def read_items(token: Optional[str] = Depends(oauth2_scheme)):
|
||||
async def read_items(token: str | None = Depends(oauth2_scheme)):
|
||||
return {"token": token}
|
||||
|
||||
|
||||
@router.post("/items/")
|
||||
async def create_item(
|
||||
token: Optional[str] = Security(oauth2_scheme, oauth_scopes=["read", "write"]),
|
||||
token: str | None = Security(oauth2_scheme, oauth_scopes=["read", "write"]),
|
||||
):
|
||||
return {"token": token}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue