# This file was auto-generated by Fern from our API Definition.
import typing
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import encode_path_param
from ..core.pagination import AsyncPager, SyncPager
from ..core.parse_error import ParsingError
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..errors.bad_request_error import BadRequestError
from ..errors.conflict_error import ConflictError
from ..errors.forbidden_error import ForbiddenError
from ..errors.not_found_error import NotFoundError
from ..errors.too_many_requests_error import TooManyRequestsError
from ..errors.unauthorized_error import UnauthorizedError
from ..types.connection_authentication_purpose import ConnectionAuthenticationPurpose
from ..types.connection_connected_accounts_purpose import ConnectionConnectedAccountsPurpose
from ..types.connection_for_list import ConnectionForList
from ..types.connection_identity_provider_enum import ConnectionIdentityProviderEnum
from ..types.connection_properties_options import ConnectionPropertiesOptions
from ..types.connection_strategy_enum import ConnectionStrategyEnum
from ..types.connections_metadata import ConnectionsMetadata
from ..types.create_connection_response_content import CreateConnectionResponseContent
from ..types.create_cross_app_access_resource_app import CreateCrossAppAccessResourceApp
from ..types.cross_app_access_requesting_app import CrossAppAccessRequestingApp
from ..types.get_connection_response_content import GetConnectionResponseContent
from ..types.list_connections_checkpoint_paginated_response_content import (
ListConnectionsCheckpointPaginatedResponseContent,
)
from ..types.update_connection_options import UpdateConnectionOptions
from ..types.update_connection_response_content import UpdateConnectionResponseContent
from ..types.update_cross_app_access_resource_app import UpdateCrossAppAccessResourceApp
from pydantic import ValidationError
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class RawConnectionsClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._client_wrapper = client_wrapper
def list(
self,
*,
from_: typing.Optional[str] = None,
take: typing.Optional[int] = 50,
strategy: typing.Optional[typing.Union[ConnectionStrategyEnum, typing.Sequence[ConnectionStrategyEnum]]] = None,
name: typing.Optional[str] = None,
fields: typing.Optional[str] = None,
include_fields: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> SyncPager[ConnectionForList, ListConnectionsCheckpointPaginatedResponseContent]:
"""
Retrieves detailed list of all [connections](https://auth0.com/docs/authenticate/identity-providers) that match the specified strategy. If no strategy is provided, all connections within your tenant are retrieved. This action can accept a list of fields to include or exclude from the resulting list of connections.
This endpoint supports two types of pagination:
- Offset pagination
- Checkpoint pagination
Checkpoint pagination must be used if you need to retrieve more than 1000 connections.
**Checkpoint Pagination**
To search by checkpoint, use the following parameters:
- `from`: Optional id from which to start selection.
- `take`: The total amount of entries to retrieve when using the from parameter. Defaults to 50.
**Note**: The first time you call this endpoint using checkpoint pagination, omit the `from` parameter. If there are more results, a `next` value is included in the response. You can use this for subsequent API calls. When `next` is no longer included in the response, no pages are remaining.
Parameters
----------
from_ : typing.Optional[str]
Optional Id from which to start selection.
take : typing.Optional[int]
Number of results per page. Defaults to 50.
strategy : typing.Optional[typing.Union[ConnectionStrategyEnum, typing.Sequence[ConnectionStrategyEnum]]]
Provide strategies to only retrieve connections with such strategies
name : typing.Optional[str]
Provide the name of the connection to retrieve
fields : typing.Optional[str]
A comma separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields
include_fields : typing.Optional[bool]
true if the fields specified are to be included in the result, false otherwise (defaults to true)
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SyncPager[ConnectionForList, ListConnectionsCheckpointPaginatedResponseContent]
The connections were retrieved.
"""
_response = self._client_wrapper.httpx_client.request(
"connections",
method="GET",
params={
"from": from_,
"take": take,
"strategy": strategy,
"name": name,
"fields": fields,
"include_fields": include_fields,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_parsed_response = typing.cast(
ListConnectionsCheckpointPaginatedResponseContent,
parse_obj_as(
type_=ListConnectionsCheckpointPaginatedResponseContent, # type: ignore
object_=_response.json(),
),
)
_items = _parsed_response.connections
_parsed_next = _parsed_response.next
_has_next = _parsed_next is not None and _parsed_next != ""
_get_next = lambda: self.list(
from_=_parsed_next,
take=take,
strategy=strategy,
name=name,
fields=fields,
include_fields=include_fields,
request_options=request_options,
)
return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def create(
self,
*,
name: str,
strategy: ConnectionIdentityProviderEnum,
display_name: typing.Optional[str] = OMIT,
options: typing.Optional[ConnectionPropertiesOptions] = OMIT,
enabled_clients: typing.Optional[typing.Sequence[str]] = OMIT,
is_domain_connection: typing.Optional[bool] = OMIT,
show_as_button: typing.Optional[bool] = OMIT,
realms: typing.Optional[typing.Sequence[str]] = OMIT,
metadata: typing.Optional[ConnectionsMetadata] = OMIT,
authentication: typing.Optional[ConnectionAuthenticationPurpose] = OMIT,
connected_accounts: typing.Optional[ConnectionConnectedAccountsPurpose] = OMIT,
cross_app_access_requesting_app: typing.Optional[CrossAppAccessRequestingApp] = OMIT,
cross_app_access_resource_app: typing.Optional[CreateCrossAppAccessResourceApp] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[CreateConnectionResponseContent]:
"""
Creates a new connection according to the JSON object received in `body`.
**Note:** If a connection with the same name was recently deleted and had a large number of associated users, the deletion may still be processing. Creating a new connection with that name before the deletion completes may fail or produce unexpected results.
Parameters
----------
name : str
The name of the connection. Must start and end with an alphanumeric character and can only contain alphanumeric characters and '-'. Max length 128
strategy : ConnectionIdentityProviderEnum
display_name : typing.Optional[str]
Connection name used in the new universal login experience
options : typing.Optional[ConnectionPropertiesOptions]
enabled_clients : typing.Optional[typing.Sequence[str]]
Use of this property is NOT RECOMMENDED. Use the PATCH /v2/connections/{id}/clients endpoint to enable the connection for a set of clients.
is_domain_connection : typing.Optional[bool]
true promotes to a domain-level connection so that third-party applications can use it. false does not promote the connection, so only first-party applications with the connection enabled can use it. (Defaults to false.)
show_as_button : typing.Optional[bool]
Enables showing a button for the connection in the login page (new experience only). If false, it will be usable only by HRD. (Defaults to false.)
realms : typing.Optional[typing.Sequence[str]]
Defines the realms for which the connection will be used (ie: email domains). If the array is empty or the property is not specified, the connection name will be added as realm.
metadata : typing.Optional[ConnectionsMetadata]
authentication : typing.Optional[ConnectionAuthenticationPurpose]
connected_accounts : typing.Optional[ConnectionConnectedAccountsPurpose]
cross_app_access_requesting_app : typing.Optional[CrossAppAccessRequestingApp]
cross_app_access_resource_app : typing.Optional[CreateCrossAppAccessResourceApp]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[CreateConnectionResponseContent]
The connection was created.
"""
_response = self._client_wrapper.httpx_client.request(
"connections",
method="POST",
json={
"name": name,
"display_name": display_name,
"strategy": strategy,
"options": convert_and_respect_annotation_metadata(
object_=options, annotation=ConnectionPropertiesOptions, direction="write"
),
"enabled_clients": enabled_clients,
"is_domain_connection": is_domain_connection,
"show_as_button": show_as_button,
"realms": realms,
"metadata": metadata,
"authentication": convert_and_respect_annotation_metadata(
object_=authentication, annotation=ConnectionAuthenticationPurpose, direction="write"
),
"connected_accounts": convert_and_respect_annotation_metadata(
object_=connected_accounts, annotation=ConnectionConnectedAccountsPurpose, direction="write"
),
"cross_app_access_requesting_app": convert_and_respect_annotation_metadata(
object_=cross_app_access_requesting_app, annotation=CrossAppAccessRequestingApp, direction="write"
),
"cross_app_access_resource_app": convert_and_respect_annotation_metadata(
object_=cross_app_access_resource_app, annotation=CreateCrossAppAccessResourceApp, direction="write"
),
},
headers={
"content-type": "application/json",
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
CreateConnectionResponseContent,
parse_obj_as(
type_=CreateConnectionResponseContent, # type: ignore
object_=_response.json(),
),
)
return HttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 409:
raise ConflictError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def get(
self,
id: str,
*,
fields: typing.Optional[str] = None,
include_fields: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[GetConnectionResponseContent]:
"""
Retrieve details for a specified [connection](https://auth0.com/docs/authenticate/identity-providers) along with options that can be used for identity provider configuration.
Parameters
----------
id : str
The id of the connection to retrieve
fields : typing.Optional[str]
A comma separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields
include_fields : typing.Optional[bool]
true if the fields specified are to be included in the result, false otherwise (defaults to true)
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[GetConnectionResponseContent]
The connection was retrieved.
"""
_response = self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}",
method="GET",
params={
"fields": fields,
"include_fields": include_fields,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
GetConnectionResponseContent,
parse_obj_as(
type_=GetConnectionResponseContent, # type: ignore
object_=_response.json(),
),
)
return HttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
"""
Removes a specific [connection](https://auth0.com/docs/authenticate/identity-providers) from your tenant. This action cannot be undone. Once removed, users can no longer use this connection to authenticate.
**Note:** If your connection has a large amount of users associated with it, please be aware that this operation can be long running after the response is returned and may impact concurrent [create connection](https://auth0.com/docs/api/management/v2/connections/post-connections) requests, if they use an identical connection name.
Parameters
----------
id : str
The id of the connection to delete
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[None]
"""
_response = self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}",
method="DELETE",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return HttpResponse(response=_response, data=None)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def update(
self,
id: str,
*,
display_name: typing.Optional[str] = OMIT,
options: typing.Optional[UpdateConnectionOptions] = OMIT,
enabled_clients: typing.Optional[typing.Sequence[str]] = OMIT,
is_domain_connection: typing.Optional[bool] = OMIT,
show_as_button: typing.Optional[bool] = OMIT,
realms: typing.Optional[typing.Sequence[str]] = OMIT,
metadata: typing.Optional[ConnectionsMetadata] = OMIT,
authentication: typing.Optional[ConnectionAuthenticationPurpose] = OMIT,
connected_accounts: typing.Optional[ConnectionConnectedAccountsPurpose] = OMIT,
cross_app_access_requesting_app: typing.Optional[CrossAppAccessRequestingApp] = OMIT,
cross_app_access_resource_app: typing.Optional[UpdateCrossAppAccessResourceApp] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[UpdateConnectionResponseContent]:
"""
Update details for a specific [connection](https://auth0.com/docs/authenticate/identity-providers), including option properties for identity provider configuration.
**Note**: If you use the `options` parameter, the entire `options` object is overridden. To avoid partial data or other issues, ensure all parameters are present when using this option.
Parameters
----------
id : str
The id of the connection to update
display_name : typing.Optional[str]
The connection name used in the new universal login experience. If display_name is not included in the request, the field will be overwritten with the name value.
options : typing.Optional[UpdateConnectionOptions]
enabled_clients : typing.Optional[typing.Sequence[str]]
DEPRECATED property. Use the PATCH /v2/connections/{id}/clients endpoint to enable or disable the connection for any clients.
is_domain_connection : typing.Optional[bool]
true promotes to a domain-level connection so that third-party applications can use it. false does not promote the connection, so only first-party applications with the connection enabled can use it. (Defaults to false.)
show_as_button : typing.Optional[bool]
Enables showing a button for the connection in the login page (new experience only). If false, it will be usable only by HRD. (Defaults to false.)
realms : typing.Optional[typing.Sequence[str]]
Defines the realms for which the connection will be used (ie: email domains). If the array is empty or the property is not specified, the connection name will be added as realm.
metadata : typing.Optional[ConnectionsMetadata]
authentication : typing.Optional[ConnectionAuthenticationPurpose]
connected_accounts : typing.Optional[ConnectionConnectedAccountsPurpose]
cross_app_access_requesting_app : typing.Optional[CrossAppAccessRequestingApp]
cross_app_access_resource_app : typing.Optional[UpdateCrossAppAccessResourceApp]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[UpdateConnectionResponseContent]
The connection was updated.
"""
_response = self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}",
method="PATCH",
json={
"display_name": display_name,
"options": convert_and_respect_annotation_metadata(
object_=options, annotation=typing.Optional[UpdateConnectionOptions], direction="write"
),
"enabled_clients": enabled_clients,
"is_domain_connection": is_domain_connection,
"show_as_button": show_as_button,
"realms": realms,
"metadata": metadata,
"authentication": convert_and_respect_annotation_metadata(
object_=authentication, annotation=ConnectionAuthenticationPurpose, direction="write"
),
"connected_accounts": convert_and_respect_annotation_metadata(
object_=connected_accounts, annotation=ConnectionConnectedAccountsPurpose, direction="write"
),
"cross_app_access_requesting_app": convert_and_respect_annotation_metadata(
object_=cross_app_access_requesting_app, annotation=CrossAppAccessRequestingApp, direction="write"
),
"cross_app_access_resource_app": convert_and_respect_annotation_metadata(
object_=cross_app_access_resource_app,
annotation=typing.Optional[UpdateCrossAppAccessResourceApp],
direction="write",
),
},
headers={
"content-type": "application/json",
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
UpdateConnectionResponseContent,
parse_obj_as(
type_=UpdateConnectionResponseContent, # type: ignore
object_=_response.json(),
),
)
return HttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 409:
raise ConflictError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def check_status(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
"""
Retrieves the status of an ad/ldap connection referenced by its `ID`. `200 OK` http status code response is returned when the connection is online, otherwise a `404` status code is returned along with an error message
Parameters
----------
id : str
ID of the connection to check
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[None]
"""
_response = self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/status",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return HttpResponse(response=_response, data=None)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
class AsyncRawConnectionsClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._client_wrapper = client_wrapper
async def list(
self,
*,
from_: typing.Optional[str] = None,
take: typing.Optional[int] = 50,
strategy: typing.Optional[typing.Union[ConnectionStrategyEnum, typing.Sequence[ConnectionStrategyEnum]]] = None,
name: typing.Optional[str] = None,
fields: typing.Optional[str] = None,
include_fields: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncPager[ConnectionForList, ListConnectionsCheckpointPaginatedResponseContent]:
"""
Retrieves detailed list of all [connections](https://auth0.com/docs/authenticate/identity-providers) that match the specified strategy. If no strategy is provided, all connections within your tenant are retrieved. This action can accept a list of fields to include or exclude from the resulting list of connections.
This endpoint supports two types of pagination:
- Offset pagination
- Checkpoint pagination
Checkpoint pagination must be used if you need to retrieve more than 1000 connections.
**Checkpoint Pagination**
To search by checkpoint, use the following parameters:
- `from`: Optional id from which to start selection.
- `take`: The total amount of entries to retrieve when using the from parameter. Defaults to 50.
**Note**: The first time you call this endpoint using checkpoint pagination, omit the `from` parameter. If there are more results, a `next` value is included in the response. You can use this for subsequent API calls. When `next` is no longer included in the response, no pages are remaining.
Parameters
----------
from_ : typing.Optional[str]
Optional Id from which to start selection.
take : typing.Optional[int]
Number of results per page. Defaults to 50.
strategy : typing.Optional[typing.Union[ConnectionStrategyEnum, typing.Sequence[ConnectionStrategyEnum]]]
Provide strategies to only retrieve connections with such strategies
name : typing.Optional[str]
Provide the name of the connection to retrieve
fields : typing.Optional[str]
A comma separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields
include_fields : typing.Optional[bool]
true if the fields specified are to be included in the result, false otherwise (defaults to true)
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncPager[ConnectionForList, ListConnectionsCheckpointPaginatedResponseContent]
The connections were retrieved.
"""
_response = await self._client_wrapper.httpx_client.request(
"connections",
method="GET",
params={
"from": from_,
"take": take,
"strategy": strategy,
"name": name,
"fields": fields,
"include_fields": include_fields,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_parsed_response = typing.cast(
ListConnectionsCheckpointPaginatedResponseContent,
parse_obj_as(
type_=ListConnectionsCheckpointPaginatedResponseContent, # type: ignore
object_=_response.json(),
),
)
_items = _parsed_response.connections
_parsed_next = _parsed_response.next
_has_next = _parsed_next is not None and _parsed_next != ""
async def _get_next():
return await self.list(
from_=_parsed_next,
take=take,
strategy=strategy,
name=name,
fields=fields,
include_fields=include_fields,
request_options=request_options,
)
return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def create(
self,
*,
name: str,
strategy: ConnectionIdentityProviderEnum,
display_name: typing.Optional[str] = OMIT,
options: typing.Optional[ConnectionPropertiesOptions] = OMIT,
enabled_clients: typing.Optional[typing.Sequence[str]] = OMIT,
is_domain_connection: typing.Optional[bool] = OMIT,
show_as_button: typing.Optional[bool] = OMIT,
realms: typing.Optional[typing.Sequence[str]] = OMIT,
metadata: typing.Optional[ConnectionsMetadata] = OMIT,
authentication: typing.Optional[ConnectionAuthenticationPurpose] = OMIT,
connected_accounts: typing.Optional[ConnectionConnectedAccountsPurpose] = OMIT,
cross_app_access_requesting_app: typing.Optional[CrossAppAccessRequestingApp] = OMIT,
cross_app_access_resource_app: typing.Optional[CreateCrossAppAccessResourceApp] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncHttpResponse[CreateConnectionResponseContent]:
"""
Creates a new connection according to the JSON object received in `body`.
**Note:** If a connection with the same name was recently deleted and had a large number of associated users, the deletion may still be processing. Creating a new connection with that name before the deletion completes may fail or produce unexpected results.
Parameters
----------
name : str
The name of the connection. Must start and end with an alphanumeric character and can only contain alphanumeric characters and '-'. Max length 128
strategy : ConnectionIdentityProviderEnum
display_name : typing.Optional[str]
Connection name used in the new universal login experience
options : typing.Optional[ConnectionPropertiesOptions]
enabled_clients : typing.Optional[typing.Sequence[str]]
Use of this property is NOT RECOMMENDED. Use the PATCH /v2/connections/{id}/clients endpoint to enable the connection for a set of clients.
is_domain_connection : typing.Optional[bool]
true promotes to a domain-level connection so that third-party applications can use it. false does not promote the connection, so only first-party applications with the connection enabled can use it. (Defaults to false.)
show_as_button : typing.Optional[bool]
Enables showing a button for the connection in the login page (new experience only). If false, it will be usable only by HRD. (Defaults to false.)
realms : typing.Optional[typing.Sequence[str]]
Defines the realms for which the connection will be used (ie: email domains). If the array is empty or the property is not specified, the connection name will be added as realm.
metadata : typing.Optional[ConnectionsMetadata]
authentication : typing.Optional[ConnectionAuthenticationPurpose]
connected_accounts : typing.Optional[ConnectionConnectedAccountsPurpose]
cross_app_access_requesting_app : typing.Optional[CrossAppAccessRequestingApp]
cross_app_access_resource_app : typing.Optional[CreateCrossAppAccessResourceApp]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[CreateConnectionResponseContent]
The connection was created.
"""
_response = await self._client_wrapper.httpx_client.request(
"connections",
method="POST",
json={
"name": name,
"display_name": display_name,
"strategy": strategy,
"options": convert_and_respect_annotation_metadata(
object_=options, annotation=ConnectionPropertiesOptions, direction="write"
),
"enabled_clients": enabled_clients,
"is_domain_connection": is_domain_connection,
"show_as_button": show_as_button,
"realms": realms,
"metadata": metadata,
"authentication": convert_and_respect_annotation_metadata(
object_=authentication, annotation=ConnectionAuthenticationPurpose, direction="write"
),
"connected_accounts": convert_and_respect_annotation_metadata(
object_=connected_accounts, annotation=ConnectionConnectedAccountsPurpose, direction="write"
),
"cross_app_access_requesting_app": convert_and_respect_annotation_metadata(
object_=cross_app_access_requesting_app, annotation=CrossAppAccessRequestingApp, direction="write"
),
"cross_app_access_resource_app": convert_and_respect_annotation_metadata(
object_=cross_app_access_resource_app, annotation=CreateCrossAppAccessResourceApp, direction="write"
),
},
headers={
"content-type": "application/json",
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
CreateConnectionResponseContent,
parse_obj_as(
type_=CreateConnectionResponseContent, # type: ignore
object_=_response.json(),
),
)
return AsyncHttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 409:
raise ConflictError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def get(
self,
id: str,
*,
fields: typing.Optional[str] = None,
include_fields: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncHttpResponse[GetConnectionResponseContent]:
"""
Retrieve details for a specified [connection](https://auth0.com/docs/authenticate/identity-providers) along with options that can be used for identity provider configuration.
Parameters
----------
id : str
The id of the connection to retrieve
fields : typing.Optional[str]
A comma separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields
include_fields : typing.Optional[bool]
true if the fields specified are to be included in the result, false otherwise (defaults to true)
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[GetConnectionResponseContent]
The connection was retrieved.
"""
_response = await self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}",
method="GET",
params={
"fields": fields,
"include_fields": include_fields,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
GetConnectionResponseContent,
parse_obj_as(
type_=GetConnectionResponseContent, # type: ignore
object_=_response.json(),
),
)
return AsyncHttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def delete(
self, id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> AsyncHttpResponse[None]:
"""
Removes a specific [connection](https://auth0.com/docs/authenticate/identity-providers) from your tenant. This action cannot be undone. Once removed, users can no longer use this connection to authenticate.
**Note:** If your connection has a large amount of users associated with it, please be aware that this operation can be long running after the response is returned and may impact concurrent [create connection](https://auth0.com/docs/api/management/v2/connections/post-connections) requests, if they use an identical connection name.
Parameters
----------
id : str
The id of the connection to delete
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[None]
"""
_response = await self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}",
method="DELETE",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return AsyncHttpResponse(response=_response, data=None)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def update(
self,
id: str,
*,
display_name: typing.Optional[str] = OMIT,
options: typing.Optional[UpdateConnectionOptions] = OMIT,
enabled_clients: typing.Optional[typing.Sequence[str]] = OMIT,
is_domain_connection: typing.Optional[bool] = OMIT,
show_as_button: typing.Optional[bool] = OMIT,
realms: typing.Optional[typing.Sequence[str]] = OMIT,
metadata: typing.Optional[ConnectionsMetadata] = OMIT,
authentication: typing.Optional[ConnectionAuthenticationPurpose] = OMIT,
connected_accounts: typing.Optional[ConnectionConnectedAccountsPurpose] = OMIT,
cross_app_access_requesting_app: typing.Optional[CrossAppAccessRequestingApp] = OMIT,
cross_app_access_resource_app: typing.Optional[UpdateCrossAppAccessResourceApp] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncHttpResponse[UpdateConnectionResponseContent]:
"""
Update details for a specific [connection](https://auth0.com/docs/authenticate/identity-providers), including option properties for identity provider configuration.
**Note**: If you use the `options` parameter, the entire `options` object is overridden. To avoid partial data or other issues, ensure all parameters are present when using this option.
Parameters
----------
id : str
The id of the connection to update
display_name : typing.Optional[str]
The connection name used in the new universal login experience. If display_name is not included in the request, the field will be overwritten with the name value.
options : typing.Optional[UpdateConnectionOptions]
enabled_clients : typing.Optional[typing.Sequence[str]]
DEPRECATED property. Use the PATCH /v2/connections/{id}/clients endpoint to enable or disable the connection for any clients.
is_domain_connection : typing.Optional[bool]
true promotes to a domain-level connection so that third-party applications can use it. false does not promote the connection, so only first-party applications with the connection enabled can use it. (Defaults to false.)
show_as_button : typing.Optional[bool]
Enables showing a button for the connection in the login page (new experience only). If false, it will be usable only by HRD. (Defaults to false.)
realms : typing.Optional[typing.Sequence[str]]
Defines the realms for which the connection will be used (ie: email domains). If the array is empty or the property is not specified, the connection name will be added as realm.
metadata : typing.Optional[ConnectionsMetadata]
authentication : typing.Optional[ConnectionAuthenticationPurpose]
connected_accounts : typing.Optional[ConnectionConnectedAccountsPurpose]
cross_app_access_requesting_app : typing.Optional[CrossAppAccessRequestingApp]
cross_app_access_resource_app : typing.Optional[UpdateCrossAppAccessResourceApp]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[UpdateConnectionResponseContent]
The connection was updated.
"""
_response = await self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}",
method="PATCH",
json={
"display_name": display_name,
"options": convert_and_respect_annotation_metadata(
object_=options, annotation=typing.Optional[UpdateConnectionOptions], direction="write"
),
"enabled_clients": enabled_clients,
"is_domain_connection": is_domain_connection,
"show_as_button": show_as_button,
"realms": realms,
"metadata": metadata,
"authentication": convert_and_respect_annotation_metadata(
object_=authentication, annotation=ConnectionAuthenticationPurpose, direction="write"
),
"connected_accounts": convert_and_respect_annotation_metadata(
object_=connected_accounts, annotation=ConnectionConnectedAccountsPurpose, direction="write"
),
"cross_app_access_requesting_app": convert_and_respect_annotation_metadata(
object_=cross_app_access_requesting_app, annotation=CrossAppAccessRequestingApp, direction="write"
),
"cross_app_access_resource_app": convert_and_respect_annotation_metadata(
object_=cross_app_access_resource_app,
annotation=typing.Optional[UpdateCrossAppAccessResourceApp],
direction="write",
),
},
headers={
"content-type": "application/json",
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
UpdateConnectionResponseContent,
parse_obj_as(
type_=UpdateConnectionResponseContent, # type: ignore
object_=_response.json(),
),
)
return AsyncHttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 409:
raise ConflictError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def check_status(
self, id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> AsyncHttpResponse[None]:
"""
Retrieves the status of an ad/ldap connection referenced by its `ID`. `200 OK` http status code response is returned when the connection is online, otherwise a `404` status code is returned along with an error message
Parameters
----------
id : str
ID of the connection to check
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[None]
"""
_response = await self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/status",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return AsyncHttpResponse(response=_response, data=None)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)