Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 66 for Optional (0.25 sec)

  1. tests/test_security_http_bearer_optional.py

    from typing import Optional
    
    from fastapi import FastAPI, Security
    from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
    from fastapi.testclient import TestClient
    
    app = FastAPI()
    
    security = HTTPBearer(auto_error=False)
    
    
    @app.get("/users/me")
    def read_current_user(
        credentials: Optional[HTTPAuthorizationCredentials] = Security(security),
    ):
        if credentials is None:
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Jun 30 18:25:16 GMT 2023
    - 2.1K bytes
    - Viewed (0)
  2. tests/test_security_http_digest_optional.py

    from typing import Optional
    
    from fastapi import FastAPI, Security
    from fastapi.security import HTTPAuthorizationCredentials, HTTPDigest
    from fastapi.testclient import TestClient
    
    app = FastAPI()
    
    security = HTTPDigest(auto_error=False)
    
    
    @app.get("/users/me")
    def read_current_user(
        credentials: Optional[HTTPAuthorizationCredentials] = Security(security),
    ):
        if credentials is None:
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Jun 30 18:25:16 GMT 2023
    - 2.2K bytes
    - Viewed (0)
  3. tests/test_security_oauth2_optional.py

    
    def get_current_user(oauth_header: Optional[str] = Security(reusable_oauth2)):
        if oauth_header is None:
            return None
        user = User(username=oauth_header)
        return user
    
    
    @app.post("/login")
    def login(form_data: OAuth2PasswordRequestFormStrict = Depends()):
        return form_data
    
    
    @app.get("/users/me")
    def read_users_me(current_user: Optional[User] = Depends(get_current_user)):
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:40:57 GMT 2024
    - 10.8K bytes
    - Viewed (0)
  4. tests/test_security_oauth2_optional_description.py

    
    def get_current_user(oauth_header: Optional[str] = Security(reusable_oauth2)):
        if oauth_header is None:
            return None
        user = User(username=oauth_header)
        return user
    
    
    @app.post("/login")
    def login(form_data: OAuth2PasswordRequestFormStrict = Depends()):
        return form_data
    
    
    @app.get("/users/me")
    def read_users_me(current_user: Optional[User] = Depends(get_current_user)):
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:40:57 GMT 2024
    - 10.9K bytes
    - Viewed (0)
  5. tests/test_security_api_key_header_optional.py

    from typing import Optional
    
    from fastapi import Depends, FastAPI, Security
    from fastapi.security import APIKeyHeader
    from fastapi.testclient import TestClient
    from pydantic import BaseModel
    
    app = FastAPI()
    
    api_key = APIKeyHeader(name="key", auto_error=False)
    
    
    class User(BaseModel):
        username: str
    
    
    def get_current_user(oauth_header: Optional[str] = Security(api_key)):
        if oauth_header is None:
            return None
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Jun 30 18:25:16 GMT 2023
    - 2K bytes
    - Viewed (0)
  6. tests/test_security_http_base_optional.py

    from typing import Optional
    
    from fastapi import FastAPI, Security
    from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBase
    from fastapi.testclient import TestClient
    
    app = FastAPI()
    
    security = HTTPBase(scheme="Other", auto_error=False)
    
    
    @app.get("/users/me")
    def read_current_user(
        credentials: Optional[HTTPAuthorizationCredentials] = Security(security),
    ):
        if credentials is None:
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Jun 30 18:25:16 GMT 2023
    - 1.9K bytes
    - Viewed (0)
  7. tests/test_security_openid_connect_optional.py

    from typing import Optional
    
    from fastapi import Depends, FastAPI, Security
    from fastapi.security.open_id_connect_url import OpenIdConnect
    from fastapi.testclient import TestClient
    from pydantic import BaseModel
    
    app = FastAPI()
    
    oid = OpenIdConnect(openIdConnectUrl="/openid", auto_error=False)
    
    
    class User(BaseModel):
        username: str
    
    
    def get_current_user(oauth_header: Optional[str] = Security(oid)):
        if oauth_header is None:
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Jun 30 18:25:16 GMT 2023
    - 2.4K bytes
    - Viewed (0)
  8. tests/test_security_http_basic_optional.py

    from base64 import b64encode
    from typing import Optional
    
    from fastapi import FastAPI, Security
    from fastapi.security import HTTPBasic, HTTPBasicCredentials
    from fastapi.testclient import TestClient
    
    app = FastAPI()
    
    security = HTTPBasic(auto_error=False)
    
    
    @app.get("/users/me")
    def read_current_user(credentials: Optional[HTTPBasicCredentials] = Security(security)):
        if credentials is None:
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Jun 30 18:25:16 GMT 2023
    - 2.6K bytes
    - Viewed (0)
  9. tests/test_security_oauth2_password_bearer_optional.py

    from typing import Optional
    
    from fastapi import FastAPI, Security
    from fastapi.security import OAuth2PasswordBearer
    from fastapi.testclient import TestClient
    
    app = FastAPI()
    
    oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/token", auto_error=False)
    
    
    @app.get("/items/")
    async def read_items(token: Optional[str] = Security(oauth2_scheme)):
        if token is None:
            return {"msg": "Create an account first"}
        return {"token": token}
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Jun 30 18:25:16 GMT 2023
    - 2.1K bytes
    - Viewed (0)
  10. tests/test_security_oauth2_password_bearer_optional_description.py

    from typing import Optional
    
    from fastapi import FastAPI, Security
    from fastapi.security import OAuth2PasswordBearer
    from fastapi.testclient import TestClient
    
    app = FastAPI()
    
    oauth2_scheme = OAuth2PasswordBearer(
        tokenUrl="/token",
        description="OAuth2PasswordBearer security scheme",
        auto_error=False,
    )
    
    
    @app.get("/items/")
    async def read_items(token: Optional[str] = Security(oauth2_scheme)):
        if token is None:
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Jun 30 18:25:16 GMT 2023
    - 2.2K bytes
    - Viewed (0)
Back to top