mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 16:32:47 +00:00
Add Bearer authentication support to Python client (#1999)
* add bearer auth support to python * add bearer auth support to python * update python oas2 petstore samples * update samples * add bearer format * update php symfony samle
This commit is contained in:
@@ -51,6 +51,7 @@ import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
|
||||
# create an instance of the API class
|
||||
api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration))
|
||||
client = petstore_api.Client() # Client | client model
|
||||
@@ -163,16 +164,24 @@ Class | Method | HTTP request | Description
|
||||
- **API key parameter name**: api_key
|
||||
- **Location**: HTTP header
|
||||
|
||||
|
||||
## api_key_query
|
||||
|
||||
- **Type**: API key
|
||||
- **API key parameter name**: api_key_query
|
||||
- **Location**: URL query string
|
||||
|
||||
|
||||
## bearer_test
|
||||
|
||||
- **Type**: Bearer authentication (JWT)
|
||||
|
||||
|
||||
## http_basic_test
|
||||
|
||||
- **Type**: HTTP basic authentication
|
||||
|
||||
|
||||
## petstore_auth
|
||||
|
||||
- **Type**: OAuth
|
||||
|
||||
@@ -15,6 +15,7 @@ To test special tags
|
||||
To test special tags and operation ID starting with number
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
|
||||
@@ -13,6 +13,7 @@ Method | HTTP request | Description
|
||||
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
|
||||
@@ -26,6 +26,7 @@ Method | HTTP request | Description
|
||||
Test serialization of outer boolean types
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -73,6 +74,7 @@ No authorization required
|
||||
Test serialization of object with outer number type
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -120,6 +122,7 @@ No authorization required
|
||||
Test serialization of outer number types
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -167,6 +170,7 @@ No authorization required
|
||||
Test serialization of outer string types
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -214,6 +218,7 @@ No authorization required
|
||||
For this test, the body for this request much reference a schema named `File`.
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -258,6 +263,7 @@ No authorization required
|
||||
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -306,6 +312,7 @@ To test \"client\" model
|
||||
To test \"client\" model
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -355,7 +362,7 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン
|
||||
|
||||
### Example
|
||||
|
||||
* Basic Authentication (http_basic_test):
|
||||
* Basic Authentication (http_basic_test):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -433,6 +440,7 @@ To test enum parameters
|
||||
To test enum parameters
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -494,15 +502,20 @@ Fake endpoint to test group parameters (optional)
|
||||
Fake endpoint to test group parameters (optional)
|
||||
|
||||
### Example
|
||||
|
||||
* Bearer (JWT) Authentication (bearer_test):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
configuration = petstore_api.Configuration()
|
||||
# Configure Bearer authorization (JWT): bearer_test
|
||||
configuration.access_token = 'YOUR_BEARER_TOKEN'
|
||||
|
||||
# create an instance of the API class
|
||||
api_instance = petstore_api.FakeApi()
|
||||
api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration))
|
||||
required_string_group = 56 # int | Required String in group parameters
|
||||
required_boolean_group = True # bool | Required Boolean in group parameters
|
||||
required_int64_group = 56 # int | Required Integer in group parameters
|
||||
@@ -534,7 +547,7 @@ void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
[bearer_test](../README.md#bearer_test)
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
@@ -549,6 +562,7 @@ No authorization required
|
||||
test inline additionalProperties
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -594,6 +608,7 @@ No authorization required
|
||||
test json serialization of form data
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
|
||||
@@ -16,7 +16,7 @@ To test class name in snake case
|
||||
|
||||
### Example
|
||||
|
||||
* Api Key Authentication (api_key_query):
|
||||
* Api Key Authentication (api_key_query):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
|
||||
@@ -22,7 +22,7 @@ Add a new pet to the store
|
||||
|
||||
### Example
|
||||
|
||||
* OAuth Authentication (petstore_auth):
|
||||
* OAuth Authentication (petstore_auth):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -72,7 +72,7 @@ Deletes a pet
|
||||
|
||||
### Example
|
||||
|
||||
* OAuth Authentication (petstore_auth):
|
||||
* OAuth Authentication (petstore_auth):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -126,7 +126,7 @@ Multiple status values can be provided with comma separated strings
|
||||
|
||||
### Example
|
||||
|
||||
* OAuth Authentication (petstore_auth):
|
||||
* OAuth Authentication (petstore_auth):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -179,7 +179,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
|
||||
|
||||
### Example
|
||||
|
||||
* OAuth Authentication (petstore_auth):
|
||||
* OAuth Authentication (petstore_auth):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -232,7 +232,7 @@ Returns a single pet
|
||||
|
||||
### Example
|
||||
|
||||
* Api Key Authentication (api_key):
|
||||
* Api Key Authentication (api_key):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -285,7 +285,7 @@ Update an existing pet
|
||||
|
||||
### Example
|
||||
|
||||
* OAuth Authentication (petstore_auth):
|
||||
* OAuth Authentication (petstore_auth):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -335,7 +335,7 @@ Updates a pet in the store with form data
|
||||
|
||||
### Example
|
||||
|
||||
* OAuth Authentication (petstore_auth):
|
||||
* OAuth Authentication (petstore_auth):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -389,7 +389,7 @@ uploads an image
|
||||
|
||||
### Example
|
||||
|
||||
* OAuth Authentication (petstore_auth):
|
||||
* OAuth Authentication (petstore_auth):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -444,7 +444,7 @@ uploads an image (required)
|
||||
|
||||
### Example
|
||||
|
||||
* OAuth Authentication (petstore_auth):
|
||||
* OAuth Authentication (petstore_auth):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
|
||||
@@ -18,6 +18,7 @@ Delete purchase order by ID
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -66,7 +67,7 @@ Returns a map of status codes to quantities
|
||||
|
||||
### Example
|
||||
|
||||
* Api Key Authentication (api_key):
|
||||
* Api Key Authentication (api_key):
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -116,6 +117,7 @@ Find purchase order by ID
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -162,6 +164,7 @@ No authorization required
|
||||
Place an order for a pet
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
|
||||
@@ -22,6 +22,7 @@ Create user
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -67,6 +68,7 @@ No authorization required
|
||||
Creates list of users with given input array
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -112,6 +114,7 @@ No authorization required
|
||||
Creates list of users with given input array
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -159,6 +162,7 @@ Delete user
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -204,6 +208,7 @@ No authorization required
|
||||
Get user by user name
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -250,6 +255,7 @@ No authorization required
|
||||
Logs user into the system
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -298,6 +304,7 @@ No authorization required
|
||||
Logs out current logged in user session
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
@@ -341,6 +348,7 @@ Updated user
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
import time
|
||||
|
||||
@@ -1127,7 +1127,7 @@ class FakeApi(object):
|
||||
|
||||
body_params = None
|
||||
# Authentication setting
|
||||
auth_settings = [] # noqa: E501
|
||||
auth_settings = ['bearer_test'] # noqa: E501
|
||||
|
||||
return self.api_client.call_api(
|
||||
'/fake', 'DELETE',
|
||||
|
||||
@@ -59,10 +59,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
|
||||
self.username = ""
|
||||
# Password for HTTP basic authentication
|
||||
self.password = ""
|
||||
|
||||
# access token for OAuth
|
||||
# access token for OAuth/Bearer
|
||||
self.access_token = ""
|
||||
|
||||
# Logging Settings
|
||||
self.logger = {}
|
||||
self.logger["package_logger"] = logging.getLogger("petstore_api")
|
||||
@@ -229,6 +227,14 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
|
||||
'key': 'api_key_query',
|
||||
'value': self.get_api_key_with_prefix('api_key_query')
|
||||
},
|
||||
'bearer_test':
|
||||
{
|
||||
'type': 'bearer',
|
||||
'in': 'header',
|
||||
'format': 'JWT',
|
||||
'key': 'Authorization',
|
||||
'value': 'Bearer ' + self.access_token
|
||||
},
|
||||
'http_basic_test':
|
||||
{
|
||||
'type': 'basic',
|
||||
@@ -236,7 +242,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
|
||||
'key': 'Authorization',
|
||||
'value': self.get_basic_auth_token()
|
||||
},
|
||||
|
||||
'petstore_auth':
|
||||
{
|
||||
'type': 'oauth2',
|
||||
@@ -244,7 +249,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
|
||||
'key': 'Authorization',
|
||||
'value': 'Bearer ' + self.access_token
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
def to_debug_report(self):
|
||||
|
||||
Reference in New Issue
Block a user