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

Python SDK: BasicAuth not working #200

Open
3 of 6 tasks
pennersr opened this issue Jul 12, 2022 · 1 comment
Open
3 of 6 tasks

Python SDK: BasicAuth not working #200

pennersr opened this issue Jul 12, 2022 · 1 comment
Labels
bug Something is not working.

Comments

@pennersr
Copy link

Preflight checklist

Describe the bug

The configuration class allows for basic authentication credentials to be passed, yet, when actually issuing requests, the credentials that are configured are skipped, leading to 401 status codes.

Reproducing the bug

Instantiate a client as follows:

from ory_hydra_client.configuration import Configuration
from ory_hydra_client.api import admin_api
from ory_hydra_client.api_client import ApiClient

configuration = Configuration(host=host, username=username, password=password)
with ApiClient(configuration) as api_client:
    api = admin_api.AdminApi(api_client)

Try and issue a login request on a Hydra instance that is protected with BasicAuth, e.g.:

api.get_login_request(challenge)

Expected result: A properly authenticated request is executed.

Actual result: HTTP 401 due to missing authorization headers.

Why is this happening? Look at the endpoint definition:

        self.get_login_request_endpoint = _Endpoint(
            settings={
                'response_type': (LoginRequest,),
                'auth': [],
                'endpoint_path': '/oauth2/auth/requests/login',
                'operation_id': 'get_login_request',
                'http_method': 'GET',
                'servers': None,
            },

Note the empty auth. Now, the credentials are actually picked up by this piece of code -- self.configuration.auth_settings():

    def update_params_for_auth(self, headers, queries, auth_settings,
                               resource_path, method, body):
        """Updates header and query params based on authentication setting.

        :param headers: Header parameters dict to be updated.
        :param queries: Query parameters tuple list to be updated.
        :param auth_settings: Authentication setting identifiers list.
        :param resource_path: A string representation of the HTTP request resource path.
        :param method: A string representation of the HTTP request method.
        :param body: A object representing the body of the HTTP request.
            The object type is the return value of _encoder.default().
        """
        if not auth_settings:
            return

        for auth in auth_settings:
            auth_setting = self.configuration.auth_settings().get(auth)

But, that code does not kick in if auth_settings is empty, which is the case due to the login request endpoint definition above.

Workaround:

api.api_client.default_headers["authorization"] = api.api_client.configuration.get_basic_auth_token()

Related:

Relevant log output

No response

Relevant configuration

No response

Version

ory-hydra-client 1.11.8

On which operating system are you observing this issue?

Linux

In which environment are you deploying?

Kubernetes

Additional Context

No response

@pennersr pennersr added the bug Something is not working. label Jul 12, 2022
@aeneasr
Copy link
Member

aeneasr commented Dec 6, 2022

Can anyone check if this is still broken?

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

No branches or pull requests

2 participants