Home / File/ test_security_oauth2_authorization_code_bearer_scopes_openapi.py — fastapi Source File

test_security_oauth2_authorization_code_bearer_scopes_openapi.py — fastapi Source File

Architecture documentation for test_security_oauth2_authorization_code_bearer_scopes_openapi.py, a python file in the fastapi codebase. 5 imports, 0 dependents.

File python FastAPI Responses 5 imports 12 functions

Entity Profile

Dependency Diagram

graph LR
  07370cbc_9a3c_ae5f_2d85_610944db9a0b["test_security_oauth2_authorization_code_bearer_scopes_openapi.py"]
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  07370cbc_9a3c_ae5f_2d85_610944db9a0b --> 0dda2280_3359_8460_301c_e98c77e78185
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  07370cbc_9a3c_ae5f_2d85_610944db9a0b --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  35c4ea20_c454_5afd_6cda_f0818bbcc650["__init__.py"]
  07370cbc_9a3c_ae5f_2d85_610944db9a0b --> 35c4ea20_c454_5afd_6cda_f0818bbcc650
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  07370cbc_9a3c_ae5f_2d85_610944db9a0b --> a7c04dee_ee23_5891_b185_47ff6bed036d
  a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"]
  07370cbc_9a3c_ae5f_2d85_610944db9a0b --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a
  style 07370cbc_9a3c_ae5f_2d85_610944db9a0b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

# Ref: https://github.com/fastapi/fastapi/issues/14454

from typing import Annotated, Optional

from fastapi import APIRouter, Depends, FastAPI, Security
from fastapi.security import OAuth2AuthorizationCodeBearer
from fastapi.testclient import TestClient
from inline_snapshot import snapshot

oauth2_scheme = OAuth2AuthorizationCodeBearer(
    authorizationUrl="authorize",
    tokenUrl="token",
    auto_error=True,
    scopes={"read": "Read access", "write": "Write access"},
)


async def get_token(token: Annotated[str, Depends(oauth2_scheme)]) -> str:
    return token


app = FastAPI(dependencies=[Depends(get_token)])


@app.get("/")
async def root():
    return {"message": "Hello World"}


@app.get(
    "/with-oauth2-scheme",
    dependencies=[Security(oauth2_scheme, scopes=["read", "write"])],
)
async def read_with_oauth2_scheme():
    return {"message": "Admin Access"}


@app.get(
    "/with-get-token", dependencies=[Security(get_token, scopes=["read", "write"])]
)
async def read_with_get_token():
    return {"message": "Admin Access"}


router = APIRouter(dependencies=[Security(oauth2_scheme, scopes=["read"])])


@router.get("/items/")
async def read_items(token: Optional[str] = Depends(oauth2_scheme)):
    return {"token": token}


@router.post("/items/")
async def create_item(
    token: Optional[str] = Security(oauth2_scheme, scopes=["read", "write"]),
):
    return {"token": token}


app.include_router(router)
// ... (138 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_security_oauth2_authorization_code_bearer_scopes_openapi.py do?
test_security_oauth2_authorization_code_bearer_scopes_openapi.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Responses subdomain.
What functions are defined in test_security_oauth2_authorization_code_bearer_scopes_openapi.py?
test_security_oauth2_authorization_code_bearer_scopes_openapi.py defines 12 function(s): create_item, get_token, read_items, read_with_get_token, read_with_oauth2_scheme, root, test_create_token, test_openapi_schema, test_read_token, test_read_with_get_token, and 2 more.
What does test_security_oauth2_authorization_code_bearer_scopes_openapi.py depend on?
test_security_oauth2_authorization_code_bearer_scopes_openapi.py imports 5 module(s): __init__.py, __init__.py, inline_snapshot, testclient.py, typing.
Where is test_security_oauth2_authorization_code_bearer_scopes_openapi.py in the architecture?
test_security_oauth2_authorization_code_bearer_scopes_openapi.py is located at tests/test_security_oauth2_authorization_code_bearer_scopes_openapi.py (domain: FastAPI, subdomain: Responses, directory: tests).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free