lenticular_cloud2/libs/ory-hydra-client/ory_hydra_client/api/public/oauth_2_token.py

209 lines
5.3 KiB
Python
Raw Normal View History

2023-01-13 14:52:38 +00:00
from typing import Any, Dict, List, Optional, Union, cast
import httpx
2023-01-13 14:52:38 +00:00
from ...client import AuthenticatedClient, Client
from ...types import Response, UNSET
from typing import Dict
from ...models.oauth_2_token_response import Oauth2TokenResponse
2023-01-13 14:52:38 +00:00
from typing import cast
from ...models.oauth_2_token_data import Oauth2TokenData
from ...models.generic_error import GenericError
def _get_kwargs(
*,
_client: AuthenticatedClient,
2023-01-13 14:52:38 +00:00
) -> Dict[str, Any]:
2023-01-13 14:52:38 +00:00
url = "{}/oauth2/token".format(
_client.base_url)
headers: Dict[str, str] = _client.get_headers()
cookies: Dict[str, Any] = _client.get_cookies()
2023-01-13 14:52:38 +00:00
return {
2023-01-13 14:52:38 +00:00
"method": "post",
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": _client.get_timeout(),
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[GenericError, Oauth2TokenResponse]]:
2023-01-13 14:52:38 +00:00
if response.status_code == HTTPStatus.OK:
response_200 = Oauth2TokenResponse.from_dict(response.json())
2023-01-13 14:52:38 +00:00
return response_200
2023-01-13 14:52:38 +00:00
if response.status_code == HTTPStatus.BAD_REQUEST:
response_400 = GenericError.from_dict(response.json())
2023-01-13 14:52:38 +00:00
return response_400
2023-01-13 14:52:38 +00:00
if response.status_code == HTTPStatus.UNAUTHORIZED:
response_401 = GenericError.from_dict(response.json())
2023-01-13 14:52:38 +00:00
return response_401
2023-01-13 14:52:38 +00:00
if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR:
response_500 = GenericError.from_dict(response.json())
2023-01-13 14:52:38 +00:00
return response_500
return None
def _build_response(*, response: httpx.Response) -> Response[Union[GenericError, Oauth2TokenResponse]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
*,
_client: AuthenticatedClient,
2023-01-13 14:52:38 +00:00
) -> Response[Union[GenericError, Oauth2TokenResponse]]:
"""The OAuth 2.0 Token Endpoint
The client makes a request to the token endpoint by sending the
following parameters using the \"application/x-www-form-urlencoded\" HTTP
request entity-body.
> Do not implement a client for this endpoint yourself. Use a library. There are many libraries
> available for any programming language. You can find a list of libraries here:
https://oauth.net/code/
>
> Do note that Hydra SDK does not implement this endpoint properly. Use one of the libraries listed
above!
Returns:
Response[Union[GenericError, Oauth2TokenResponse]]
"""
2023-01-13 14:52:38 +00:00
kwargs = _get_kwargs(
_client=_client,
2023-01-13 14:52:38 +00:00
)
response = httpx.request(
verify=_client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
*,
_client: AuthenticatedClient,
2023-01-13 14:52:38 +00:00
) -> Optional[Union[GenericError, Oauth2TokenResponse]]:
"""The OAuth 2.0 Token Endpoint
The client makes a request to the token endpoint by sending the
following parameters using the \"application/x-www-form-urlencoded\" HTTP
request entity-body.
> Do not implement a client for this endpoint yourself. Use a library. There are many libraries
> available for any programming language. You can find a list of libraries here:
https://oauth.net/code/
>
> Do note that Hydra SDK does not implement this endpoint properly. Use one of the libraries listed
above!
Returns:
Response[Union[GenericError, Oauth2TokenResponse]]
"""
2023-01-13 14:52:38 +00:00
return sync_detailed(
_client=_client,
2023-01-13 14:52:38 +00:00
).parsed
async def asyncio_detailed(
*,
_client: AuthenticatedClient,
2023-01-13 14:52:38 +00:00
) -> Response[Union[GenericError, Oauth2TokenResponse]]:
"""The OAuth 2.0 Token Endpoint
The client makes a request to the token endpoint by sending the
following parameters using the \"application/x-www-form-urlencoded\" HTTP
request entity-body.
> Do not implement a client for this endpoint yourself. Use a library. There are many libraries
> available for any programming language. You can find a list of libraries here:
https://oauth.net/code/
>
> Do note that Hydra SDK does not implement this endpoint properly. Use one of the libraries listed
above!
Returns:
Response[Union[GenericError, Oauth2TokenResponse]]
"""
2023-01-13 14:52:38 +00:00
kwargs = _get_kwargs(
_client=_client,
2023-01-13 14:52:38 +00:00
)
async with httpx.AsyncClient(verify=_client.verify_ssl) as __client:
2023-01-13 14:52:38 +00:00
response = await __client.request(
**kwargs
)
return _build_response(response=response)
async def asyncio(
*,
_client: AuthenticatedClient,
2023-01-13 14:52:38 +00:00
) -> Optional[Union[GenericError, Oauth2TokenResponse]]:
"""The OAuth 2.0 Token Endpoint
The client makes a request to the token endpoint by sending the
following parameters using the \"application/x-www-form-urlencoded\" HTTP
request entity-body.
> Do not implement a client for this endpoint yourself. Use a library. There are many libraries
> available for any programming language. You can find a list of libraries here:
https://oauth.net/code/
>
> Do note that Hydra SDK does not implement this endpoint properly. Use one of the libraries listed
above!
Returns:
Response[Union[GenericError, Oauth2TokenResponse]]
"""
2023-01-13 14:52:38 +00:00
return (await asyncio_detailed(
_client=_client,
)).parsed