HDFGroup / h5pyd

h5py distributed - Python client library for HDF Rest API
Other
110 stars 39 forks source link

Passing 'Bearer' token to h5pyd instead of fixed keycloak config #121

Closed vedina closed 1 year ago

vedina commented 1 year ago

I would like to pass existing and valid Authorization: Bearer token to h5pyd , and not rely on predefined user credentials to obtain it .

Is this possible (without touching h5pyd code) ?

Context: h5pyd is used in a Flask RESTfull application which supports multiple users, the bearer token is obtained by the application and is specific to the user; the token shall be passed to h5pyd ; the user passwords are not accessible (they are managed by а Keycloak instance).

jreadey commented 1 year ago

Hey @vedina - I think if you use: h5pyd.File(domain_path, api_key=bearer_token), it should just work. See: https://github.com/HDFGroup/h5pyd/blob/master/h5pyd/_hl/httpconn.py#L330. The api_key param can be just a string that is passed to the server or a dict with openid params to prompt the user to authenticate.

I haven't tried this myself, so let me know how it goes.

vedina commented 1 year ago

Thanks, passing the token as api_key works.

jreadey commented 1 year ago

Awesome! Glad that works!