pynautobot
pynautobot copied to clipboard
WiP: Add support for generic auth headers
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).
I'm not seeing requests having an auth_headers
parameter. Is there something that is undocumented there? https://requests.readthedocs.io/en/latest/api/
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}"}
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.
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.