crim-ca / weaver

Weaver: Workflow Execution Management Service (EMS); Application, Deployment and Execution Service (ADES); OGC API - Processes; WPS; CWL Application Package
https://pavics-weaver.readthedocs.io
Apache License 2.0
24 stars 6 forks source link

add SessionAuthHandler #599

Closed mishaschwartz closed 7 months ago

mishaschwartz commented 7 months ago

Add weaver.cli.SessionAuthHandler class which uses the cookies stored in a pre-existing requests.Session instance to authenticate.

Alternative to #597 as discussed in https://github.com/crim-ca/weaver/pull/597#discussion_r1480537709

Closes #597

mishaschwartz commented 7 months ago

Ok, here's the new usage:

CLI:

weaver processes -aC weaver.cli.CookieAuthHandler -aT 'auth=thecookievaluethattshouldbeincluded' --url https://example.com/weaver

Client

s = requests.Session()
# add cookies to the session
client = WeaverClient("https://example.com/weaver", auth=CookieAuthHandler(token=s.cookies.get_dict()))
mishaschwartz commented 7 months ago

Note that because I made the changes in the RequestAuthHandler as discussed:

It would be fine with adding a pre-check to RequestAuthHandler that skips request_auth call when the token/cookie is predefined in the handler

it is possible to send a token to the BearerAuthHandler as well in a similar way (if you have the bearer token already)

fmigneault commented 7 months ago

@mishaschwartz You can add yourself to the contributors list in https://github.com/crim-ca/weaver/blob/master/AUTHORS.rst if you desire.

codecov[bot] commented 7 months ago

Codecov Report

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

Comparison is base (d234e11) 85.65% compared to head (e7e3670) 85.66%. Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #599 +/- ## ========================================== + Coverage 85.65% 85.66% +0.01% ========================================== Files 79 79 Lines 18559 18580 +21 Branches 2844 2847 +3 ========================================== + Hits 15896 15917 +21 Misses 1926 1926 Partials 737 737 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

fmigneault commented 6 months ago

@mishaschwartz FYI https://github.com/crim-ca/weaver/tree/5.1.0

fmigneault commented 6 months ago

@mishaschwartz Due to a CI issue with https://github.com/crim-ca/weaver/tree/5.1.0, I pushed another https://github.com/crim-ca/weaver/tree/5.1.1. The docker image for it should be ready soon.