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
While basic auth is often not ideal for production, during development basic auth can be quite handy. Currently it is not possible to directly use basic auth with the generated Python client.
Describe the solution you'd like
Detect if an API supports basic auth and provide it as an alternative AuthenticatedClient.
An example implementation:
frombase64importb64encodefromtypingimportDictimportattr@attr.s(auto_attribs=True)classBasicAuthAuthenticatedClient(Client):
"""A Client which has been authenticated for use on secured endpoints"""username: strpassword: strdefget_headers(self) ->Dict[str, str]:
"""Get headers to be used in authenticated endpoints"""encoded_credentials=b64encode(f"{self.username}:{self.password}".encode()).decode()
return {"Authorization": f"Basic {encoded_credentials}", **self.headers}
Describe alternatives you've considered
The AuthenticatedClient could be made to take either a token or username/password.
Activity