Update code and tests to use `oauth_scopes` instead of `scopes`

This commit is contained in:
Yurii Motov 2025-12-01 09:33:14 +01:00
parent 4c6fd06027
commit be6db923bf
4 changed files with 7 additions and 7 deletions

View File

@ -127,7 +127,7 @@ def get_parameterless_sub_dependant(*, depends: params.Depends, path: str) -> De
) )
own_oauth_scopes: List[str] = [] own_oauth_scopes: List[str] = []
if isinstance(depends, params.Security) and depends.oauth_scopes: if isinstance(depends, params.Security) and depends.oauth_scopes:
own_oauth_scopes.extend(depends.scopes) own_oauth_scopes.extend(depends.oauth_scopes)
return get_dependant( return get_dependant(
path=path, path=path,
call=depends.dependency, call=depends.dependency,

View File

@ -25,7 +25,7 @@ def app_fixture(call_counter: Dict[str, int]):
@app.get("/") @app.get("/")
def endpoint( def endpoint(
db: Annotated[str, Depends(get_db)], db: Annotated[str, Depends(get_db)],
user: Annotated[str, Security(get_user, scopes=["read"])], user: Annotated[str, Security(get_user, oauth_scopes=["read"])],
): ):
return {"db": db} return {"db": db}

View File

@ -17,8 +17,8 @@ async def security2(scopes: SecurityScopes):
async def dep3( async def dep3(
dep1: Annotated[List[str], Security(security1, scopes=["scope1"])], dep1: Annotated[List[str], Security(security1, oauth_scopes=["scope1"])],
dep2: Annotated[List[str], Security(security2, scopes=["scope2"])], dep2: Annotated[List[str], Security(security2, oauth_scopes=["scope2"])],
): ):
return {"dep1": dep1, "dep2": dep2} return {"dep1": dep1, "dep2": dep2}
@ -28,7 +28,7 @@ app = FastAPI()
@app.get("/scopes") @app.get("/scopes")
def get_scopes( def get_scopes(
dep3: Annotated[Dict[str, Any], Security(dep3, scopes=["scope3"])], dep3: Annotated[Dict[str, Any], Security(dep3, oauth_scopes=["scope3"])],
): ):
return dep3 return dep3

View File

@ -37,7 +37,7 @@ def app_fixture(call_counts: Dict[str, int]):
} }
def get_user_me( def get_user_me(
current_user: Annotated[dict, Security(get_current_user, scopes=["me"])], current_user: Annotated[dict, Security(get_current_user, oauth_scopes=["me"])],
): ):
call_counts["get_user_me"] += 1 call_counts["get_user_me"] += 1
return { return {
@ -59,7 +59,7 @@ def app_fixture(call_counts: Dict[str, int]):
@app.get("/") @app.get("/")
def path_operation( def path_operation(
user_me: Annotated[dict, Depends(get_user_me)], user_me: Annotated[dict, Depends(get_user_me)],
user_items: Annotated[dict, Security(get_user_items, scopes=["items"])], user_items: Annotated[dict, Security(get_user_items, oauth_scopes=["items"])],
): ):
return { return {
"user_me": user_me, "user_me": user_me,