Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiP: Add support for generic auth headers #158

Open
wants to merge 2 commits into
base: ltm-1.6
Choose a base branch
from

Conversation

sklemer1
Copy link

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

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Author

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 sklemer1 changed the title Add support for generic auth headers WiP: Add support for generic auth headers Nov 28, 2023
@joewesch
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants