Skip to content

added optional global AppAPIAuth middleware #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2024
Merged

Conversation

bigcat88
Copy link
Member

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.

Copy link

codecov bot commented Jan 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #205   +/-   ##
=======================================
  Coverage   99.85%   99.85%           
=======================================
  Files          40       40           
  Lines        4701     4726   +25     
=======================================
+ Hits         4694     4719   +25     
  Misses          7        7           
Files Coverage Δ
nc_py_api/_session.py 100.00% <100.00%> (ø)
nc_py_api/_version.py 100.00% <100.00%> (ø)
nc_py_api/ex_app/__init__.py 100.00% <ø> (ø)
nc_py_api/ex_app/integration_fastapi.py 100.00% <100.00%> (ø)
nc_py_api/nextcloud.py 98.67% <100.00%> (ø)

Signed-off-by: Alexander Piskun <[email protected]>
@bigcat88 bigcat88 merged commit 0657830 into main Jan 13, 2024
@bigcat88 bigcat88 deleted the AppAPIAuthMiddleware branch January 13, 2024 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant