Module keycloak_oidc_api_client
A client library for accessing Keycloak OIDC API
Sub-modules
- keycloak_oidc_api_client.api
- keycloak_oidc_api_client.client
- keycloak_oidc_api_client.errors
- keycloak_oidc_api_client.models
- keycloak_oidc_api_client.types
Classes
AuthenticatedClient
class AuthenticatedClient(
base_url: str,
token: str,
prefix: str = 'Bearer',
auth_header_name: str = 'Authorization',
*,
raise_on_unexpected_status: bool = False,
cookies: dict[str, str] = NOTHING,
headers: dict[str, str] = NOTHING,
timeout: httpx.Timeout | None = None,
verify_ssl: str | bool | ssl.SSLContext = True,
follow_redirects: bool = False,
httpx_args: dict[str, typing.Any] = NOTHING
)
A Client which has been authenticated for use on secured endpoints
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
``cookies``: A dictionary of cookies to be sent with every request
``headers``: A dictionary of headers to be sent with every request
``timeout``: The maximum amount of a time a request can take. API functions will raise
httpx.TimeoutException if this is exceeded.
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
but can be set to False for testing purposes.
``follow_redirects``: Whether or not to follow redirects. Default value is False.
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
Attributes
| Name | Type | Description | Default |
|---|---|---|---|
| raise_on_unexpected_status | None | Whether or not to raise an errors.UnexpectedStatus if the API returns a status code that was not documented in the source OpenAPI document. Can also be provided as a keyword argument to the constructor. |
None |
| token | None | The token to use for authentication | None |
| prefix | None | The prefix to use for the Authorization header | None |
| auth_header_name | None | The name of the Authorization header | None |
Instance variables
auth_header_name
prefix
raise_on_unexpected_status
token
Methods
get_async_httpx_client
def get_async_httpx_client(
self
) -> httpx.AsyncClient
Get the underlying httpx.AsyncClient, constructing a new one if not previously set
get_httpx_client
def get_httpx_client(
self
) -> httpx.Client
Get the underlying httpx.Client, constructing a new one if not previously set
set_async_httpx_client
def set_async_httpx_client(
self,
async_client: httpx.AsyncClient
) -> 'AuthenticatedClient'
Manually the underlying httpx.AsyncClient
NOTE: This will override any other settings on the client, including cookies, headers, and timeout.
set_httpx_client
def set_httpx_client(
self,
client: httpx.Client
) -> 'AuthenticatedClient'
Manually set the underlying httpx.Client
NOTE: This will override any other settings on the client, including cookies, headers, and timeout.
with_cookies
def with_cookies(
self,
cookies: dict[str, str]
) -> 'AuthenticatedClient'
Get a new client matching this one with additional cookies
with_headers
def with_headers(
self,
headers: dict[str, str]
) -> 'AuthenticatedClient'
Get a new client matching this one with additional headers
with_timeout
def with_timeout(
self,
timeout: httpx.Timeout
) -> 'AuthenticatedClient'
Get a new client matching this one with a new timeout (in seconds)
Client
class Client(
base_url: str,
*,
raise_on_unexpected_status: bool = False,
cookies: dict[str, str] = NOTHING,
headers: dict[str, str] = NOTHING,
timeout: httpx.Timeout | None = None,
verify_ssl: str | bool | ssl.SSLContext = True,
follow_redirects: bool = False,
httpx_args: dict[str, typing.Any] = NOTHING
)
A class for keeping track of data related to the API
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
``cookies``: A dictionary of cookies to be sent with every request
``headers``: A dictionary of headers to be sent with every request
``timeout``: The maximum amount of a time a request can take. API functions will raise
httpx.TimeoutException if this is exceeded.
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
but can be set to False for testing purposes.
``follow_redirects``: Whether or not to follow redirects. Default value is False.
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
Attributes
| Name | Type | Description | Default |
|---|---|---|---|
| raise_on_unexpected_status | None | Whether or not to raise an errors.UnexpectedStatus if the API returns a status code that was not documented in the source OpenAPI document. Can also be provided as a keyword argument to the constructor. |
None |
Instance variables
raise_on_unexpected_status
Methods
get_async_httpx_client
def get_async_httpx_client(
self
) -> httpx.AsyncClient
Get the underlying httpx.AsyncClient, constructing a new one if not previously set
get_httpx_client
def get_httpx_client(
self
) -> httpx.Client
Get the underlying httpx.Client, constructing a new one if not previously set
set_async_httpx_client
def set_async_httpx_client(
self,
async_client: httpx.AsyncClient
) -> 'Client'
Manually the underlying httpx.AsyncClient
NOTE: This will override any other settings on the client, including cookies, headers, and timeout.
set_httpx_client
def set_httpx_client(
self,
client: httpx.Client
) -> 'Client'
Manually set the underlying httpx.Client
NOTE: This will override any other settings on the client, including cookies, headers, and timeout.
with_cookies
def with_cookies(
self,
cookies: dict[str, str]
) -> 'Client'
Get a new client matching this one with additional cookies
with_headers
def with_headers(
self,
headers: dict[str, str]
) -> 'Client'
Get a new client matching this one with additional headers
with_timeout
def with_timeout(
self,
timeout: httpx.Timeout
) -> 'Client'
Get a new client matching this one with a new timeout (in seconds)