mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-09 11:26:12 +00:00
Add Http signature authentication test to fake petstore spec (#6054)
* add endpoint to test http signature * update plugin version
This commit is contained in:
@@ -46,7 +46,7 @@ Please follow the [installation procedure](#installation--usage) and then run th
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
|
||||
import datetime
|
||||
import time
|
||||
import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
@@ -84,6 +84,7 @@ Class | Method | HTTP request | Description
|
||||
*AnotherFakeApi* | [**call_123_test_special_tags**](docs/AnotherFakeApi.md#call_123_test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
|
||||
*DefaultApi* | [**foo_get**](docs/DefaultApi.md#foo_get) | **GET** /foo |
|
||||
*FakeApi* | [**fake_health_get**](docs/FakeApi.md#fake_health_get) | **GET** /fake/health | Health check endpoint
|
||||
*FakeApi* | [**fake_http_signature_test**](docs/FakeApi.md#fake_http_signature_test) | **GET** /fake/http-signature-test | test http signature authentication
|
||||
*FakeApi* | [**fake_outer_boolean_serialize**](docs/FakeApi.md#fake_outer_boolean_serialize) | **POST** /fake/outer/boolean |
|
||||
*FakeApi* | [**fake_outer_composite_serialize**](docs/FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite |
|
||||
*FakeApi* | [**fake_outer_number_serialize**](docs/FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number |
|
||||
@@ -201,6 +202,10 @@ Class | Method | HTTP request | Description
|
||||
- **Type**: HTTP basic authentication
|
||||
|
||||
|
||||
## http_signature_test
|
||||
|
||||
|
||||
|
||||
## petstore_auth
|
||||
|
||||
- **Type**: OAuth
|
||||
|
||||
@@ -5,6 +5,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
[**fake_health_get**](FakeApi.md#fake_health_get) | **GET** /fake/health | Health check endpoint
|
||||
[**fake_http_signature_test**](FakeApi.md#fake_http_signature_test) | **GET** /fake/http-signature-test | test http signature authentication
|
||||
[**fake_outer_boolean_serialize**](FakeApi.md#fake_outer_boolean_serialize) | **POST** /fake/outer/boolean |
|
||||
[**fake_outer_composite_serialize**](FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite |
|
||||
[**fake_outer_number_serialize**](FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number |
|
||||
@@ -76,6 +77,69 @@ No authorization required
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_http_signature_test**
|
||||
> fake_http_signature_test(pet, query_1=query_1, header_1=header_1)
|
||||
|
||||
test http signature authentication
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = petstore_api.Configuration(
|
||||
host = "http://petstore.swagger.io:80/v2"
|
||||
)
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient() as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.FakeApi(api_client)
|
||||
pet = petstore_api.Pet() # Pet | Pet object that needs to be added to the store
|
||||
query_1 = 'query_1_example' # str | query parameter (optional)
|
||||
header_1 = 'header_1_example' # str | header parameter (optional)
|
||||
|
||||
try:
|
||||
# test http signature authentication
|
||||
api_instance.fake_http_signature_test(pet, query_1=query_1, header_1=header_1)
|
||||
except ApiException as e:
|
||||
print("Exception when calling FakeApi->fake_http_signature_test: %s\n" % e)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
|
||||
**query_1** | **str**| query parameter | [optional]
|
||||
**header_1** | **str**| header parameter | [optional]
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: application/json, application/xml
|
||||
- **Accept**: Not defined
|
||||
|
||||
### HTTP response details
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
**200** | The instance started successfully | - |
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_outer_boolean_serialize**
|
||||
> bool fake_outer_boolean_serialize(body=body)
|
||||
|
||||
|
||||
@@ -139,6 +139,128 @@ class FakeApi(object):
|
||||
_request_timeout=local_var_params.get('_request_timeout'),
|
||||
collection_formats=collection_formats)
|
||||
|
||||
def fake_http_signature_test(self, pet, **kwargs): # noqa: E501
|
||||
"""test http signature authentication # noqa: E501
|
||||
|
||||
This method makes a synchronous HTTP request by default. To make an
|
||||
asynchronous HTTP request, please pass async_req=True
|
||||
>>> thread = api.fake_http_signature_test(pet, async_req=True)
|
||||
>>> result = thread.get()
|
||||
|
||||
:param async_req bool: execute request asynchronously
|
||||
:param Pet pet: Pet object that needs to be added to the store (required)
|
||||
:param str query_1: query parameter
|
||||
:param str header_1: header parameter
|
||||
:param _preload_content: if False, the urllib3.HTTPResponse object will
|
||||
be returned without reading/decoding response
|
||||
data. Default is True.
|
||||
:param _request_timeout: timeout setting for this request. If one
|
||||
number provided, it will be total request
|
||||
timeout. It can also be a pair (tuple) of
|
||||
(connection, read) timeouts.
|
||||
:return: None
|
||||
If the method is called asynchronously,
|
||||
returns the request thread.
|
||||
"""
|
||||
kwargs['_return_http_data_only'] = True
|
||||
return self.fake_http_signature_test_with_http_info(pet, **kwargs) # noqa: E501
|
||||
|
||||
def fake_http_signature_test_with_http_info(self, pet, **kwargs): # noqa: E501
|
||||
"""test http signature authentication # noqa: E501
|
||||
|
||||
This method makes a synchronous HTTP request by default. To make an
|
||||
asynchronous HTTP request, please pass async_req=True
|
||||
>>> thread = api.fake_http_signature_test_with_http_info(pet, async_req=True)
|
||||
>>> result = thread.get()
|
||||
|
||||
:param async_req bool: execute request asynchronously
|
||||
:param Pet pet: Pet object that needs to be added to the store (required)
|
||||
:param str query_1: query parameter
|
||||
:param str header_1: header parameter
|
||||
:param _return_http_data_only: response data without head status code
|
||||
and headers
|
||||
:param _preload_content: if False, the urllib3.HTTPResponse object will
|
||||
be returned without reading/decoding response
|
||||
data. Default is True.
|
||||
:param _request_timeout: timeout setting for this request. If one
|
||||
number provided, it will be total request
|
||||
timeout. It can also be a pair (tuple) of
|
||||
(connection, read) timeouts.
|
||||
:return: None
|
||||
If the method is called asynchronously,
|
||||
returns the request thread.
|
||||
"""
|
||||
|
||||
local_var_params = locals()
|
||||
|
||||
all_params = [
|
||||
'pet',
|
||||
'query_1',
|
||||
'header_1'
|
||||
]
|
||||
all_params.extend(
|
||||
[
|
||||
'async_req',
|
||||
'_return_http_data_only',
|
||||
'_preload_content',
|
||||
'_request_timeout'
|
||||
]
|
||||
)
|
||||
|
||||
for key, val in six.iteritems(local_var_params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise ApiTypeError(
|
||||
"Got an unexpected keyword argument '%s'"
|
||||
" to method fake_http_signature_test" % key
|
||||
)
|
||||
local_var_params[key] = val
|
||||
del local_var_params['kwargs']
|
||||
# verify the required parameter 'pet' is set
|
||||
if self.api_client.client_side_validation and ('pet' not in local_var_params or # noqa: E501
|
||||
local_var_params['pet'] is None): # noqa: E501
|
||||
raise ApiValueError("Missing the required parameter `pet` when calling `fake_http_signature_test`") # noqa: E501
|
||||
|
||||
collection_formats = {}
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = []
|
||||
if 'query_1' in local_var_params and local_var_params['query_1'] is not None: # noqa: E501
|
||||
query_params.append(('query_1', local_var_params['query_1'])) # noqa: E501
|
||||
|
||||
header_params = {}
|
||||
if 'header_1' in local_var_params:
|
||||
header_params['header_1'] = local_var_params['header_1'] # noqa: E501
|
||||
|
||||
form_params = []
|
||||
local_var_files = {}
|
||||
|
||||
body_params = None
|
||||
if 'pet' in local_var_params:
|
||||
body_params = local_var_params['pet']
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
|
||||
['application/json', 'application/xml']) # noqa: E501
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = [] # noqa: E501
|
||||
|
||||
return self.api_client.call_api(
|
||||
'/fake/http-signature-test', 'GET',
|
||||
path_params,
|
||||
query_params,
|
||||
header_params,
|
||||
body=body_params,
|
||||
post_params=form_params,
|
||||
files=local_var_files,
|
||||
response_type=None, # noqa: E501
|
||||
auth_settings=auth_settings,
|
||||
async_req=local_var_params.get('async_req'),
|
||||
_return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501
|
||||
_preload_content=local_var_params.get('_preload_content', True),
|
||||
_request_timeout=local_var_params.get('_request_timeout'),
|
||||
collection_formats=collection_formats)
|
||||
|
||||
def fake_outer_boolean_serialize(self, **kwargs): # noqa: E501
|
||||
"""fake_outer_boolean_serialize # noqa: E501
|
||||
|
||||
|
||||
@@ -49,6 +49,8 @@ class Configuration(object):
|
||||
then all undeclared properties received by the server are injected into the
|
||||
additional properties map. In that case, there are undeclared properties, and
|
||||
nothing to discard.
|
||||
:param signing_info: Configuration parameters for the HTTP signature security scheme.
|
||||
Must be an instance of petstore_api.signing.HttpSigningConfiguration
|
||||
|
||||
:Example:
|
||||
|
||||
@@ -86,6 +88,45 @@ conf = petstore_api.Configuration(
|
||||
password='the-password',
|
||||
)
|
||||
|
||||
|
||||
HTTP Signature Authentication Example.
|
||||
Given the following security scheme in the OpenAPI specification:
|
||||
components:
|
||||
securitySchemes:
|
||||
http_basic_auth:
|
||||
type: http
|
||||
scheme: signature
|
||||
|
||||
Configure API client with HTTP signature authentication. Use the 'hs2019' signature scheme,
|
||||
sign the HTTP requests with the RSA-SSA-PSS signature algorithm, and set the expiration time
|
||||
of the signature to 5 minutes after the signature has been created.
|
||||
Note you can use the constants defined in the petstore_api.signing module, and you can
|
||||
also specify arbitrary HTTP headers to be included in the HTTP signature, except for the
|
||||
'Authorization' header, which is used to carry the signature.
|
||||
|
||||
One may be tempted to sign all headers by default, but in practice it rarely works.
|
||||
This is beccause explicit proxies, transparent proxies, TLS termination endpoints or
|
||||
load balancers may add/modify/remove headers. Include the HTTP headers that you know
|
||||
are not going to be modified in transit.
|
||||
|
||||
conf = petstore_api.Configuration(
|
||||
signing_info = petstore_api.signing.HttpSigningConfiguration(
|
||||
key_id = 'my-key-id',
|
||||
private_key_path = 'rsa.pem',
|
||||
signing_scheme = petstore_api.signing.SCHEME_HS2019,
|
||||
signing_algorithm = petstore_api.signing.ALGORITHM_RSASSA_PSS,
|
||||
signed_headers = [petstore_api.signing.HEADER_REQUEST_TARGET,
|
||||
petstore_api.signing.HEADER_CREATED,
|
||||
petstore_api.signing.HEADER_EXPIRES,
|
||||
petstore_api.signing.HEADER_HOST,
|
||||
petstore_api.signing.HEADER_DATE,
|
||||
petstore_api.signing.HEADER_DIGEST,
|
||||
'Content-Type',
|
||||
'User-Agent'
|
||||
],
|
||||
signature_max_validity = datetime.timedelta(minutes=5)
|
||||
)
|
||||
)
|
||||
"""
|
||||
|
||||
_default = None
|
||||
@@ -94,6 +135,7 @@ conf = petstore_api.Configuration(
|
||||
api_key=None, api_key_prefix=None,
|
||||
username=None, password=None,
|
||||
discard_unknown_keys=False,
|
||||
signing_info=None,
|
||||
):
|
||||
"""Constructor
|
||||
"""
|
||||
@@ -124,6 +166,11 @@ conf = petstore_api.Configuration(
|
||||
"""Password for HTTP basic authentication
|
||||
"""
|
||||
self.discard_unknown_keys = discard_unknown_keys
|
||||
if signing_info is not None:
|
||||
signing_info.host = host
|
||||
self.signing_info = signing_info
|
||||
"""The HTTP signing configuration
|
||||
"""
|
||||
self.access_token = None
|
||||
"""access token for OAuth/Bearer
|
||||
"""
|
||||
@@ -205,6 +252,10 @@ conf = petstore_api.Configuration(
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
object.__setattr__(self, name, value)
|
||||
if name == "signing_info" and value is not None:
|
||||
# Ensure the host paramater from signing info is the same as
|
||||
# Configuration.host.
|
||||
value.host = self.host
|
||||
|
||||
@classmethod
|
||||
def set_default(cls, default):
|
||||
@@ -382,6 +433,13 @@ conf = petstore_api.Configuration(
|
||||
'key': 'Authorization',
|
||||
'value': self.get_basic_auth_token()
|
||||
}
|
||||
if self.signing_info is not None:
|
||||
auth['http_signature_test'] = {
|
||||
'type': 'http-signature',
|
||||
'in': 'header',
|
||||
'key': 'Authorization',
|
||||
'value': None # Signature headers are calculated for every HTTP request
|
||||
}
|
||||
if self.access_token is not None:
|
||||
auth['petstore_auth'] = {
|
||||
'type': 'oauth2',
|
||||
|
||||
Reference in New Issue
Block a user