nautobot / pynautobot

Nautobot Python SDK
https://pynautobot.readthedocs.io/en/latest/index.html
Apache License 2.0
37 stars 32 forks source link

WiP: Add support for generic auth headers #158

Open sklemer1 opened 10 months ago

sklemer1 commented 10 months ago

Add a auth_header attribute that is used verbatim as Authorization header (i.e. without prefixing Token). We use this to support oauth2 flows with Bearer tokens (patch for nautobot will come soon).

jvanderaa commented 10 months ago

I'm not seeing requests having an auth_headers parameter. Is there something that is undocumented there? https://requests.readthedocs.io/en/latest/api/

joewesch commented 10 months ago

I think a better implementation is to just accept headers and if it's None set the default.

if headers is not None:
    self.headers = headers
else:
    self.headers = {"Authorization": f"Token {self.token}"}
sklemer1 commented 10 months ago

I'm not seeing requests having an auth_headers parameter. Is there something that is undocumented there? https://requests.readthedocs.io/en/latest/api/

Nope, there is no such thing -- but I don't use it like this. The argument auth_header is only ever used in pynautobots 'Request' object and as before we hand a complete 'headers' dictionary to the requests request.

I think a better implementation is to just accept headers and if it's None set the default.

Sure. Would you accept a PR if we write it like this? Would be a tiny little bit more code change as headers are added here and there and the dicts have to be merged then.

joewesch commented 10 months ago

Sure. Would you accept a PR if we write it like this? Would be a tiny little bit more code change as headers are added here and there and the dicts have to be merged then.

Yes. I would suggest using something like self.headers.update() for the times we need to merge headers.