openapi-generator: [BUG] [Ruby] [Python] Client generation doesn't support Bearer Authentication

Description

If you declare a bearer auth as security scheme and apply to the whole OpenAPI spec:

security:
  - bearerAuth: []
components:
  securitySchemes:
      bearerAuth:
        type: http
        scheme: bearer

And try to generate a ruby or python client (I didn’t test on other languages), the readme generated use basic authentication as an example and if you set config.access_token parameter, the request sends:

Host: contoso.com
User-Agent: OpenAPI-Generator/1.0.0/ruby
Content-Type: application/json
Accept: application/json
Authorization: Basic Og==

Then you need to go manually and change the client in order to have it suitable for the application.

openapi-generator version

3.3.4

Fix

The solution for me was to change the method in lib/package-name/configuration.rb from

def basic_auth_token
  'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
end

to

def basic_auth_token
  'Bearer ' + access_token
end

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (11 by maintainers)

Most upvoted comments

Yup, that fixes it.

@rhuanbarreto Perhaps consult again with https://swagger.io/docs/specification/authentication/bearer-authentication/ as this is what helped me just now find out what was missing.