cloud-py-api / nc_py_api

Nextcloud Python Framework
https://cloud-py-api.github.io/nc_py_api/
Other
92 stars 6 forks source link

added optional global AppAPIAuth middleware #205

Closed bigcat88 closed 9 months ago

bigcat88 commented 9 months ago

For some applications it will be useful to simply set global authentication to all endpoints and not write in each endpoint:

New:

APP = FastAPI(lifespan=lifespan)
APP.add_middleware(ex_app.AppAPIAuthMiddleware)

Old:


@APP.post("/verify_initial_value")
async def verify_initial_value(
    _nc: typing.Annotated[NextcloudApp, Depends(nc_app)],   # <---- this is no needed when using new Global Middleware
    input1: Button1Format,
):
    print("Old value: ", input1.initial_value)
    return responses.JSONResponse(content={"initial_value": str(random.randint(0, 100))}, status_code=200)

Limitations:

Talk bots endpoints using another Auth type, and they should be added to disable_for parameter of AppAPIAuthMiddleware.

codecov[bot] commented 9 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (1061622) 99.85% compared to head (027f6ed) 99.85%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #205 +/- ## ======================================= Coverage 99.85% 99.85% ======================================= Files 40 40 Lines 4701 4726 +25 ======================================= + Hits 4694 4719 +25 Misses 7 7 ``` | [Files](https://app.codecov.io/gh/cloud-py-api/nc_py_api/pull/205?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloud-py-api) | Coverage Δ | | |---|---|---| | [nc\_py\_api/\_session.py](https://app.codecov.io/gh/cloud-py-api/nc_py_api/pull/205?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloud-py-api#diff-bmNfcHlfYXBpL19zZXNzaW9uLnB5) | `100.00% <100.00%> (ø)` | | | [nc\_py\_api/\_version.py](https://app.codecov.io/gh/cloud-py-api/nc_py_api/pull/205?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloud-py-api#diff-bmNfcHlfYXBpL192ZXJzaW9uLnB5) | `100.00% <100.00%> (ø)` | | | [nc\_py\_api/ex\_app/\_\_init\_\_.py](https://app.codecov.io/gh/cloud-py-api/nc_py_api/pull/205?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloud-py-api#diff-bmNfcHlfYXBpL2V4X2FwcC9fX2luaXRfXy5weQ==) | `100.00% <ø> (ø)` | | | [nc\_py\_api/ex\_app/integration\_fastapi.py](https://app.codecov.io/gh/cloud-py-api/nc_py_api/pull/205?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloud-py-api#diff-bmNfcHlfYXBpL2V4X2FwcC9pbnRlZ3JhdGlvbl9mYXN0YXBpLnB5) | `100.00% <100.00%> (ø)` | | | [nc\_py\_api/nextcloud.py](https://app.codecov.io/gh/cloud-py-api/nc_py_api/pull/205?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloud-py-api#diff-bmNfcHlfYXBpL25leHRjbG91ZC5weQ==) | `98.67% <100.00%> (ø)` | |