forked from loafle/openapi-generator-original
Python apikey cookie (#2367)
* The `ApiClient` will now have support to store and use HTTP Cookies (as APIKey auth). * Use Cookie authentication for user management. * - Updated Python related samples.
This commit is contained in:
committed by
William Cheng
parent
33786e11f3
commit
83bc863b2b
@@ -17,6 +17,22 @@ def info_from_api_key(api_key, required_scopes):
|
||||
return {'uid': 'user_id'}
|
||||
|
||||
|
||||
def info_from_auth_cookie(api_key, required_scopes):
|
||||
"""
|
||||
Check and retrieve authentication information from api_key.
|
||||
Returned value will be passed in 'token_info' parameter of your operation function, if there is one.
|
||||
'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one.
|
||||
|
||||
:param api_key API key provided by Authorization header
|
||||
:type api_key: str
|
||||
:param required_scopes Always None. Used for other authentication method
|
||||
:type required_scopes: None
|
||||
:return: Information attached to provided api_key or None if api_key is invalid or does not allow access to called API
|
||||
:rtype: dict | None
|
||||
"""
|
||||
return {'uid': 'user_id'}
|
||||
|
||||
|
||||
def info_from_petstore_auth(token):
|
||||
"""
|
||||
Validate and decode token.
|
||||
|
||||
@@ -395,6 +395,8 @@ paths:
|
||||
responses:
|
||||
default:
|
||||
description: successful operation
|
||||
security:
|
||||
- auth_cookie: []
|
||||
summary: Create user
|
||||
tags:
|
||||
- user
|
||||
@@ -407,6 +409,8 @@ paths:
|
||||
responses:
|
||||
default:
|
||||
description: successful operation
|
||||
security:
|
||||
- auth_cookie: []
|
||||
summary: Creates list of users with given input array
|
||||
tags:
|
||||
- user
|
||||
@@ -419,6 +423,8 @@ paths:
|
||||
responses:
|
||||
default:
|
||||
description: successful operation
|
||||
security:
|
||||
- auth_cookie: []
|
||||
summary: Creates list of users with given input array
|
||||
tags:
|
||||
- user
|
||||
@@ -455,6 +461,13 @@ paths:
|
||||
type: string
|
||||
description: successful operation
|
||||
headers:
|
||||
Set-Cookie:
|
||||
description: Cookie authentication key for use with the `auth_cookie` apiKey authentication.
|
||||
explode: false
|
||||
schema:
|
||||
example: AUTH_KEY=abcde12345; Path=/; HttpOnly
|
||||
type: string
|
||||
style: simple
|
||||
X-Rate-Limit:
|
||||
description: calls per hour allowed by the user
|
||||
explode: false
|
||||
@@ -481,6 +494,8 @@ paths:
|
||||
responses:
|
||||
default:
|
||||
description: successful operation
|
||||
security:
|
||||
- auth_cookie: []
|
||||
summary: Logs out current logged in user session
|
||||
tags:
|
||||
- user
|
||||
@@ -503,6 +518,8 @@ paths:
|
||||
description: Invalid username supplied
|
||||
404:
|
||||
description: User not found
|
||||
security:
|
||||
- auth_cookie: []
|
||||
summary: Delete user
|
||||
tags:
|
||||
- user
|
||||
@@ -560,6 +577,8 @@ paths:
|
||||
description: Invalid user supplied
|
||||
404:
|
||||
description: User not found
|
||||
security:
|
||||
- auth_cookie: []
|
||||
summary: Updated user
|
||||
tags:
|
||||
- user
|
||||
@@ -803,3 +822,8 @@ components:
|
||||
name: api_key
|
||||
type: apiKey
|
||||
x-apikeyInfoFunc: openapi_server.controllers.security_controller_.info_from_api_key
|
||||
auth_cookie:
|
||||
in: cookie
|
||||
name: AUTH_KEY
|
||||
type: apiKey
|
||||
x-apikeyInfoFunc: openapi_server.controllers.security_controller_.info_from_auth_cookie
|
||||
|
||||
@@ -30,6 +30,7 @@ class TestUserController(BaseTestCase):
|
||||
}
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'auth_cookie': 'special-key',
|
||||
}
|
||||
response = self.client.open(
|
||||
'/v2/user',
|
||||
@@ -48,6 +49,7 @@ class TestUserController(BaseTestCase):
|
||||
user = []
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'auth_cookie': 'special-key',
|
||||
}
|
||||
response = self.client.open(
|
||||
'/v2/user/createWithArray',
|
||||
@@ -66,6 +68,7 @@ class TestUserController(BaseTestCase):
|
||||
user = []
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'auth_cookie': 'special-key',
|
||||
}
|
||||
response = self.client.open(
|
||||
'/v2/user/createWithList',
|
||||
@@ -82,6 +85,7 @@ class TestUserController(BaseTestCase):
|
||||
Delete user
|
||||
"""
|
||||
headers = {
|
||||
'auth_cookie': 'special-key',
|
||||
}
|
||||
response = self.client.open(
|
||||
'/v2/user/{username}'.format(username='username_example'),
|
||||
@@ -129,6 +133,7 @@ class TestUserController(BaseTestCase):
|
||||
Logs out current logged in user session
|
||||
"""
|
||||
headers = {
|
||||
'auth_cookie': 'special-key',
|
||||
}
|
||||
response = self.client.open(
|
||||
'/v2/user/logout',
|
||||
@@ -154,6 +159,7 @@ class TestUserController(BaseTestCase):
|
||||
}
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'auth_cookie': 'special-key',
|
||||
}
|
||||
response = self.client.open(
|
||||
'/v2/user/{username}'.format(username='username_example'),
|
||||
|
||||
Reference in New Issue
Block a user