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

Add support of Bearer Basic Authorization to Ruby client #2856

Merged
merged 19 commits into from
May 15, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,15 @@ require '{{{gemName}}}'
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}
# Setup authorization
{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}
# Configure HTTP basic authorization: {{{name}}}
config.username = 'YOUR USERNAME'
config.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}}
{{^isBasicBearer}}
bopm marked this conversation as resolved.
Show resolved Hide resolved
# Configure HTTP basic authorization: {{{name}}}
config.username = 'YOUR_USERNAME'
config.password = 'YOUR_PASSWORD'
{{/isBasicBearer}}
{{#isBasicBearer}}
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
config.access_token = 'YOUR_BEARER_TOKEN'
{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
bopm marked this conversation as resolved.
Show resolved Hide resolved
# Configure API key authorization: {{{name}}}
config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
Expand Down Expand Up @@ -128,7 +134,13 @@ Class | Method | HTTP request | Description
- **API key parameter name**: {{keyParamName}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{#isBasic}}
{{^isBasicBearer}}
- **Type**: HTTP basic authentication
{{/isBasicBearer}}
{{#isBasicBearer}}
- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
{{/isBasicBearer}}
{{/isBasic}}
{{#isOAuth}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ Method | HTTP request | Description
require '{{{gemName}}}'
{{#hasAuthMethods}}
# setup authorization
{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}
{{{moduleName}}}.configure do |config|{{#authMethods}}
{{#isBasic}}
{{^isBasicBearer}}
# Configure HTTP basic authorization: {{{name}}}
config.username = 'YOUR USERNAME'
config.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}}
config.password = 'YOUR PASSWORD'
{{/isBasicBearer}}
{{#isBasicBearer}}
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
config.access_token = 'YOUR_BEARER_TOKEN'
{{/isBasicBearer}}
{{/isBasic}}
{{#isApiKey}}
# Configure API key authorization: {{{name}}}
config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,27 @@ module {{moduleName}}
},
{{/isApiKey}}
{{#isBasic}}
'{{name}}' =>
{
type: 'basic',
in: 'header',
key: 'Authorization',
value: basic_auth_token
},
{{^isBasicBearer}}
'{{name}}' =>
bopm marked this conversation as resolved.
Show resolved Hide resolved
{
type: 'basic',
in: 'header',
key: 'Authorization',
value: basic_auth_token
},
{{/isBasicBearer}}
{{#isBasicBearer}}
'{{name}}' =>
{
type: 'bearer',
in: 'header',
{{#bearerFormat}}
format: '{{{.}}}',
{{/bearerFormat}}
key: 'Authorization',
value: "Bearer #{access_token}"
},
{{/isBasicBearer}}
{{/isBasic}}
{{#isOAuth}}
'{{name}}' =>
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/ruby/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ Petstore.configure do |config|
# Configure HTTP basic authorization: http_basic_test
config.username = 'YOUR USERNAME'
config.password = 'YOUR PASSWORD'

end

api_instance = Petstore::FakeApi.new
Expand Down
8 changes: 8 additions & 0 deletions samples/client/petstore/ruby/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Add a new pet to the store
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -78,6 +79,7 @@ Deletes a pet
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -133,6 +135,7 @@ Multiple status values can be provided with comma separated strings
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -185,6 +188,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -289,6 +293,7 @@ Update an existing pet
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -338,6 +343,7 @@ Updates a pet in the store with form data
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -393,6 +399,7 @@ uploads an image
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -449,6 +456,7 @@ uploads an image (required)
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down
14 changes: 7 additions & 7 deletions samples/client/petstore/ruby/lib/petstore/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ def auth_settings
key: 'api_key_query',
value: api_key_with_prefix('api_key_query')
},
'http_basic_test' =>
{
type: 'basic',
in: 'header',
key: 'Authorization',
value: basic_auth_token
},
'http_basic_test' =>
{
type: 'basic',
in: 'header',
key: 'Authorization',
value: basic_auth_token
},
'petstore_auth' =>
{
type: 'oauth2',
Expand Down
2 changes: 1 addition & 1 deletion samples/openapi3/client/petstore/ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Class | Method | HTTP request | Description

### bearer_test

- **Type**: HTTP basic authentication
- **Type**: Bearer authentication (JWT)

### http_basic_test

Expand Down
7 changes: 4 additions & 3 deletions samples/openapi3/client/petstore/ruby/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ Petstore.configure do |config|
# Configure HTTP basic authorization: http_basic_test
config.username = 'YOUR USERNAME'
config.password = 'YOUR PASSWORD'

end

api_instance = Petstore::FakeApi.new
Expand Down Expand Up @@ -547,9 +548,9 @@ Fake endpoint to test group parameters (optional)
require 'petstore'
# setup authorization
Petstore.configure do |config|
# Configure HTTP basic authorization: bearer_test
config.username = 'YOUR USERNAME'
config.password = 'YOUR PASSWORD'
# Configure Bearer authorization (JWT): bearer_test
config.access_token = 'YOUR_BEARER_TOKEN'

end

api_instance = Petstore::FakeApi.new
Expand Down
8 changes: 8 additions & 0 deletions samples/openapi3/client/petstore/ruby/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Add a new pet to the store
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -78,6 +79,7 @@ Deletes a pet
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -133,6 +135,7 @@ Multiple status values can be provided with comma separated strings
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -185,6 +188,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -289,6 +293,7 @@ Update an existing pet
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -338,6 +343,7 @@ Updates a pet in the store with form data
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -393,6 +399,7 @@ uploads an image
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down Expand Up @@ -449,6 +456,7 @@ uploads an image (required)
require 'petstore'
# setup authorization
Petstore.configure do |config|

# Configure OAuth2 access token for authorization: petstore_auth
config.access_token = 'YOUR ACCESS TOKEN'
end
Expand Down
29 changes: 15 additions & 14 deletions samples/openapi3/client/petstore/ruby/lib/petstore/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,21 @@ def auth_settings
key: 'api_key_query',
value: api_key_with_prefix('api_key_query')
},
'bearer_test' =>
{
type: 'basic',
in: 'header',
key: 'Authorization',
value: basic_auth_token
},
'http_basic_test' =>
{
type: 'basic',
in: 'header',
key: 'Authorization',
value: basic_auth_token
},
'bearer_test' =>
{
type: 'bearer',
in: 'header',
format: 'JWT',
key: 'Authorization',
value: "Bearer #{access_token}"
},
'http_basic_test' =>
{
type: 'basic',
in: 'header',
key: 'Authorization',
value: basic_auth_token
},
'petstore_auth' =>
{
type: 'oauth2',
Expand Down