Eternaltwin
The main client is the entry point for interacting with the Eternaltwin API. It is used to store authorization information and to make requests to the API.
Currently, two implementations of the main client are available:
eternaltwin.clients.sync.clients.Eternaltwin— synchronous client usingrequeststo communicate with the Eternaltwin API.eternaltwin.clients.asyncio.clients.Eternaltwin— asynchronous client usingaiohttpto communicate with the Eternaltwin API.
Both implementations follow the same interface defined in the section below.
Both main clients use sub-clients to create namespaces for readability and maintainability. The following sub-client is available:
eternaltwin.clients.abc.clients.ClientABC
ClientABC(client_id: str, client_secret: str, redirect_uri: str, state_key: KeyABC, *, url: str = None, scheme: str = 'http', host: str = None, port: str | int = None, prefix: str = '/', timeout: int = 5, verify_ssl: bool = True, allow_redirects: bool = False)
Bases: ABC
Base class for client handling communication with EternalTwin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client_id
|
str
|
The client ID obtained from EternalTwin when registering the app. |
required |
client_secret
|
str
|
The client secret obtained from EternalTwin when registering the app. |
required |
redirect_uri
|
str
|
The redirect URI registered with EternalTwin for the app. |
required |
state_key
|
KeyABC
|
The key used to sign and verify state tokens. |
required |
url
|
str
|
The base URL for the EternalTwin API. If not provided, |
None
|
scheme
|
str
|
The URL scheme to use (e.g., "http" or "https"). Required if |
'http'
|
host
|
str
|
The URL host to use (e.g., "eternaltwin.org"). Required if |
None
|
port
|
str | int
|
The URL port to use. Required if |
None
|
prefix
|
str
|
The URL prefix to use. Default to |
'/'
|
timeout
|
int
|
The timeout for API requests in seconds. Default is 5 seconds. |
5
|
verify_ssl
|
bool
|
Whether to verify SSL certificates for API requests. Default is True. |
True
|
allow_redirects
|
bool
|
Whether to allow redirects for API requests. Default is False. |
False
|
authorization_url
Create an OAuth authorization request URL.
The result URL contains all the information required for the user to grant the requested authorization and then call back the app and resume handling with the provided state.
token
abstractmethod
Retrieve a token using the provided authorization code.
generate_state
Generate a new state using the client's URL and key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expiration
|
int
|
Expiration time in seconds. Default to 600 seconds. |
600
|
nonce
|
str
|
An optional nonce value used to guarantee the state to be unique. If not provided, a random one will be generated. |
None
|
Return
str The generated state encoded as a JWT.
validate_state
Validate the state received from the authorization server.
An expected state can be provided to check if the state received from the authorization server matches the expected one.
Raises:
| Type | Description |
|---|---|
InvalidStateError
|
If action or authorization server does not match, the JWT is expired, or the received state does not match the expected one (if provided). |
eternaltwin.clients.sync.clients.Eternaltwin
Eternaltwin(client_id: str, client_secret: str, redirect_uri: str, state_key: KeyABC, *, url: str = None, scheme: str = 'http', host: str = None, port: str | int = None, prefix: str = '/', timeout: int = 5, verify_ssl: bool = True, allow_redirects: bool = False)
Bases: ClientABC
Synchronous implementation of ClientABC using requests.
eternaltwin.clients.sync.clients.Eternaltwin.get
Helper to make a GET request to EternalTwin.
eternaltwin.clients.sync.clients.Eternaltwin.post
Helper to make a POST request to EternalTwin.
eternaltwin.clients.asyncio.clients.Eternaltwin
Eternaltwin(client_id: str, client_secret: str, redirect_uri: str, state_key: KeyABC, *, url: str = None, scheme: str = 'http', host: str = None, port: str | int = None, prefix: str = '/', timeout: int = 5, verify_ssl: bool = True, allow_redirects: bool = False)
Bases: ClientABC
Asynchronous implementation of ClientABC using aiohttp.
eternaltwin.clients.asyncio.clients.Eternaltwin.get
async
Helper to make a GET request to EternalTwin.
eternaltwin.clients.asyncio.clients.Eternaltwin.post
async
Helper to make a POST request to EternalTwin.