OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
22.02k stars 6.61k forks source link

[BUG] Unable to set 'access_token' on api Configuration #13315

Open fbl100 opened 2 years ago

fbl100 commented 2 years ago

Bug Report Checklist

Description

This is for the python-experimental client generator.

When working with a 'bearer' access token, I am unable to set the 'access_token' property in the Configuration() initializer. Instead, I have to do this:

configuration = client_api.Configuration(
    host=URL,
)
configuration.access_token = getToken()

ideally I would be able to do this:

configuration = client_api.Configuration(
    host=URL,
    access_token = getToken()
)
openapi-generator version

latest master (8/30/2022)

OpenAPI declaration file content or url

N/A

Related issues/PRs
Suggest a fix
wtrocki commented 2 years ago

I see the same issue right now. I think fixing it would be trivial. It will be faster to contribute that rather than wait for core team IMHO CC @dimakis

fbl100 commented 2 years ago

I tend to agree, but won't have the bandwidth for a fix until mid Sept. I wrote the issue so that it doesn't get forgotten about and would be happy to fix when I have time. The workaround is easy enough for now.

labrown commented 1 year ago

I just ran into this bug today. I see this bit of code and it is clear that setting access_token during the init of a Configuration object will be overwritten to 'None'. I am not familiar enough with the codebase to know the correct fix for this, but it should be simple.

        self.access_token = access_token
        """Access token
        """
{{#hasHttpSignatureMethods}}
        if signing_info is not None:
            signing_info.host = host
        self.signing_info = signing_info
        """The HTTP signing configuration
        """
{{/hasHttpSignatureMethods}}
{{#hasOAuthMethods}}
        self.access_token = None
        """access token for OAuth/Bearer
        """
{{/hasOAuthMethods}}
Neudrino commented 1 month ago

Our current workaround is to explicitly set the token in the override headers of each request.

Setting the token statically in the configuration would not be sufficient for us, as the token expire frequently. I.e. for the token to be set in the API client configuration, we would need a lazy evaluation, i.e. some sort of Promise to be set, such that the actual token value is only obtained once the request is made, such that in case a token refresh can be triggered before using the token.

Neudrino commented 1 month ago

This ticket might be related to: