openapi-python-client icon indicating copy to clipboard operation
openapi-python-client copied to clipboard

Support other authentication methods

Open pawamoy opened this issue 4 years ago • 1 comments

Is your feature request related to a problem? Please describe. The clients I'm generating must authenticate with a cookie, which is not supported by openapi-python-client right now.

Describe the solution you'd like One of:

  • retrieving the authentication method from the spec (is this possible?) and generating the client accordingly
  • accept options on the command line to specify the authentication method

Describe alternatives you've considered Manually altering the generated client. This is what I currently have:

@dataclass
class AuthenticatedClient(Client):
    token: str

    def get_headers(self) -> Dict[str, str]:
        return {}

    def get_cookies(self) -> Dict[str, str]:
        return {"auth_cookie_name": self.token}

Then I added cookies=client.get_cookies() to every request made using httpx in the api modules.

pawamoy avatar Aug 12 '20 08:08 pawamoy

So in the long term, yeah we should totally parse as much info as possible about the security method via the OpenAPI Document and maybe generate a different AuthenticatedClient variant for each method.

In the near term, for 0.6.0, I'll add in a generic get_cookies() to the Clients so it's easier to pass things in in the future.

dbanty avatar Aug 18 '20 23:08 dbanty

There are other discussions tracking individual security scheme improvements, so closing this to defer to each implementation.

dbanty avatar Aug 13 '23 02:08 dbanty