You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@attr.s(auto_attribs=True)
class AuthenticatedClient(Client):
"""A Client which has been authenticated for use on secured endpoints"""
token: str
def get_headers(self) -> Dict[str, str]:
"""Get headers to be used in authenticated endpoints"""
return {"Authorization": f"Bearer {self.token}", **self.headers}
The desired code is:
@attr.s(auto_attribs=True)
class AuthenticatedClient(Client):
"""A Client which has been authenticated for use on secured endpoints"""
token: str
def get_headers(self) -> Dict[str, str]:
"""Get headers to be used in authenticated endpoints"""
return {"Auth": self.token, **self.headers}
openapi-python-client does understand that the request should be an authenticated request, since it defines client parameter in the signature of sync/async/sync_detailed/async_detailed methods to be of the type AuthenticatedClient as opposed to just Client. But, the AuthenticatedClient seems to default to a bearer token (as @jrobbins-LiveData shows).
Maybe it would be a good idea to just pass through the auth parameter to httpx. This would allow one to easily customize authentication, or use existing "plugins", without modifying the client or template.
Here's the documentation on what is possible using that parameter, and an example of a plugin would be httpx-ntlm
Activity
scorgn commentedon May 15, 2022
I also am dealing with openapi docs that use Basic HTTP Authentication
I'm then adding to my request...
openapi-python-clientdoes understand that the request should be an authenticated request, since it defines client parameter in the signature ofsync/async/sync_detailed/async_detailedmethods to be of the typeAuthenticatedClientas opposed to justClient. But, theAuthenticatedClientseems to default to a bearer token (as @jrobbins-LiveData shows).Nov1kov commentedon Aug 15, 2022
Is it posible to fix by templates?
Nov1kov commentedon Aug 15, 2022
Yes, it is.
Workaround:
Please follow this https://github.com/openapi-generators/openapi-python-client#using-custom-templates
Edit this line in your custom template as you want.
openapi-python-client/openapi_python_client/templates/client.py.jinja
Line 45 in 5861c7c
dbanty commentedon Aug 17, 2022
Awesome, thanks for providing a workaround @Nov1kov !
philnagel commentedon Feb 6, 2023
Maybe it would be a good idea to just pass through the
authparameter tohttpx. This would allow one to easily customize authentication, or use existing "plugins", without modifying the client or template.Here's the documentation on what is possible using that parameter, and an example of a plugin would be httpx-ntlm
dbanty commentedon Feb 6, 2023
Sounds like another +1 for #202