Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Is your feature request related to a problem? Please describe.

OpenAPI 3 supports expressing basic auth support: https://swagger.io/docs/specification/authentication/basic-authentication/

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:

from base64 import b64encode
from typing import Dict

import attr

@attr.s(auto_attribs=True)
class BasicAuthAuthenticatedClient(Client):
    """A Client which has been authenticated for use on secured endpoints"""

    username: str
    password: str

    def get_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.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or improvement 🍭 OpenAPI Compliance Supporting a new bit of the OpenAPI spec
1 participant
Converted from issue

This discussion was converted from issue #525 on August 13, 2023 01:56.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.