Add support of Bearer Basic Authorization to Ruby client (#2856)

* Support for Bearer in Ruby Client

* Update README.mustache

* Update README.mustache

* Update api_doc.mustache

* Update api_doc.mustache

* Update api_doc.mustache

* samples

* Uncommited changes

* Formatting

* More Formatting

* Fomatting

* More formatting

* More formatting

* Even more formatting

* Even more formatting

* More formatting

* Even more formatting

* More formatting

* More formatting
This commit is contained in:
Sergey Moiseev 2019-05-15 16:17:57 +03:00 committed by William Cheng
parent c353f79342
commit 87414352a5
6 changed files with 33 additions and 12 deletions

View File

@ -65,10 +65,12 @@ Please follow the [installation](#installation) procedure and then run the follo
require '{{{gemName}}}' require '{{{gemName}}}'
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}} {{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}
# Setup authorization # Setup authorization
{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}} {{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{^isBasicBearer}}
# Configure HTTP basic authorization: {{{name}}} # Configure HTTP basic authorization: {{{name}}}
config.username = 'YOUR USERNAME' 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}}} # Configure API key authorization: {{{name}}}
config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY' 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) # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
@ -128,7 +130,10 @@ Class | Method | HTTP request | Description
- **API key parameter name**: {{keyParamName}} - **API key parameter name**: {{keyParamName}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}} {{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication {{#isBasic}}
{{^isBasicBearer}}- **Type**: HTTP basic authentication
{{/isBasicBearer}}{{#isBasicBearer}}- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
{{/isBasicBearer}}
{{/isBasic}} {{/isBasic}}
{{#isOAuth}} {{#isOAuth}}

View File

@ -27,10 +27,12 @@ Method | HTTP request | Description
require '{{{gemName}}}' require '{{{gemName}}}'
{{#hasAuthMethods}} {{#hasAuthMethods}}
# setup authorization # setup authorization
{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}} {{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{^isBasicBearer}}
# Configure HTTP basic authorization: {{{name}}} # Configure HTTP basic authorization: {{{name}}}
config.username = 'YOUR USERNAME' 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}}} # Configure API key authorization: {{{name}}}
config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY' 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) # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)

View File

@ -199,6 +199,7 @@ module {{moduleName}}
}, },
{{/isApiKey}} {{/isApiKey}}
{{#isBasic}} {{#isBasic}}
{{^isBasicBearer}}
'{{name}}' => '{{name}}' =>
{ {
type: 'basic', type: 'basic',
@ -206,6 +207,19 @@ module {{moduleName}}
key: 'Authorization', key: 'Authorization',
value: basic_auth_token value: basic_auth_token
}, },
{{/isBasicBearer}}
{{#isBasicBearer}}
'{{name}}' =>
{
type: 'bearer',
in: 'header',
{{#bearerFormat}}
format: '{{{.}}}',
{{/bearerFormat}}
key: 'Authorization',
value: "Bearer #{access_token}"
},
{{/isBasicBearer}}
{{/isBasic}} {{/isBasic}}
{{#isOAuth}} {{#isOAuth}}
'{{name}}' => '{{name}}' =>

View File

@ -180,7 +180,7 @@ Class | Method | HTTP request | Description
### bearer_test ### bearer_test
- **Type**: HTTP basic authentication - **Type**: Bearer authentication (JWT)
### http_basic_test ### http_basic_test

View File

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

View File

@ -212,10 +212,11 @@ module Petstore
}, },
'bearer_test' => 'bearer_test' =>
{ {
type: 'basic', type: 'bearer',
in: 'header', in: 'header',
format: 'JWT',
key: 'Authorization', key: 'Authorization',
value: basic_auth_token value: "Bearer #{access_token}"
}, },
'http_basic_test' => 'http_basic_test' =>
{ {