kermitt2 / grobid_client_python

Python client for GROBID Web services
Apache License 2.0
275 stars 74 forks source link

Authenticate using the Authorization header in requests made by the cient #59

Open lucazav opened 1 year ago

lucazav commented 1 year ago

I published the GROBID server application in an Azure Web App. I added an authorisation layer using the one provided by Azure Web Apps. Now I need to authenticate the GROBID client by passing the bearer authentication token to its header requests. How can I do this?

kermitt2 commented 1 year ago

Hi @lucazav !

This client is a simple base to be adapted on the environment requirements and there is for the moment no mechanisms to pass a bearer, you need to add it.

One simple solution is to add the bearer token defined in the config file or as environment variable secret in the header argument when calling the post() method:

https://github.com/kermitt2/grobid_client_python/blob/master/grobid_client/grobid_client.py#L278

     the_headers={"Accept": "text/plain", "Authorization": "Bearer " + self.config["bearer"] }
     try:
            res, status = self.post(
                url=the_url, files=files, data=the_data, headers=the_headers, timeout=self.config['timeout']
            )

A PR to add this is very welcome !