pynautobot icon indicating copy to clipboard operation
pynautobot copied to clipboard

WiP: Add support for generic auth headers

Open sklemer1 opened this issue 1 year ago • 4 comments

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).

sklemer1 avatar Nov 26 '23 17:11 sklemer1

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

jvanderaa avatar Nov 27 '23 14:11 jvanderaa

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}"}

joewesch avatar Nov 27 '23 14:11 joewesch

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.

sklemer1 avatar Nov 28 '23 12:11 sklemer1

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.

joewesch avatar Nov 28 '23 13:11 joewesch