SDK Auth#
This documentation auto-generates details about the Authentication and Authorization functionality provided by the SDK.
Service Auth#
HMAC authentication assistance methods.
- exception libs.sdk.src.destiny_sdk.auth.AuthException(status_code: Annotated[int, Doc('\n HTTP status code to send to the client.\n ')], detail: Annotated[Any, Doc('\n Any data to be sent to the client in the `detail` key of the JSON\n response.\n ')] = None, headers: Annotated[Dict[str, str] | None, Doc('\n Any headers to send to the client in the response.\n ')] = None)[source]#
An exception related to HTTP authentication.
Raised by implementations of the AuthMethod protocol.
raise AuthException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Unable to parse authentication token.", )
- class libs.sdk.src.destiny_sdk.auth.BypassHMACAuth(*args, **kwargs)[source]#
A fake auth class that will always respond successfully.
Intended for use in local environments and for testing.
Not for production use!
- class libs.sdk.src.destiny_sdk.auth.HMACAuth(secret_key: str)[source]#
Adds HMAC auth when used as a router or endpoint dependency.
- class libs.sdk.src.destiny_sdk.auth.HMACAuthMethod(*args, **kwargs)[source]#
Protocol for HMAC auth methods, enforcing the implmentation of __call__().
This allows FastAPI to call class instances as depenedencies in FastAPI routes, see https://fastapi.tiangolo.com/advanced/advanced-dependencies
auth = HMACAuthMethod() router = APIRouter( prefix="/robots", tags=["robot"], dependencies=[Depends(auth)] )
- pydantic model libs.sdk.src.destiny_sdk.auth.HMACAuthorizationHeaders[source]#
The HTTP authorization headers required for HMAC authentication.
Expects the following headers to be present in the request
Authorization: Signature [request signature]
X-Client-Id: [UUID]
X-Request-Timestamp: [float]
Show Entity Relationship Diagram
![digraph "Entity Relationship Diagram created by erdantic" {
graph [fontcolor=gray66,
fontname="Times New Roman,Times,Liberation Serif,serif",
fontsize=9,
nodesep=0.5,
rankdir=LR,
ranksep=1.5
];
node [fontname="Times New Roman,Times,Liberation Serif,serif",
fontsize=14,
label="\N",
shape=plain
];
edge [dir=both];
"libs.sdk.src.destiny_sdk.auth.HMACAuthorizationHeaders" [label=<<table border="0" cellborder="1" cellspacing="0"><tr><td port="_root" colspan="2"><b>HMACAuthorizationHeaders</b></td></tr><tr><td>signature</td><td port="signature">str</td></tr><tr><td>client_id</td><td port="client_id">UUID</td></tr><tr><td>timestamp</td><td port="timestamp">float</td></tr></table>>,
tooltip="libs.sdk.src.destiny_sdk.auth.HMACAuthorizationHeaders

The HTTP authorization headers required for HMAC authentication.&#\
xA;
Expects the following headers to be present in the request

- Authorization: Signature [request signature]
- \
X-Client-Id: [UUID]
- X-Request-Timestamp: [float]
"];
}](../_images/graphviz-58ea380b47f9e7092bd3ffd309e3cc0e0769da0a.png)
Show JSON schema
{ "title": "HMACAuthorizationHeaders", "description": "The HTTP authorization headers required for HMAC authentication.\n\nExpects the following headers to be present in the request\n\n- Authorization: Signature [request signature]\n- X-Client-Id: [UUID]\n- X-Request-Timestamp: [float]", "type": "object", "properties": { "signature": { "title": "Signature", "type": "string" }, "client_id": { "format": "uuid4", "title": "Client Id", "type": "string" }, "timestamp": { "title": "Timestamp", "type": "number" } }, "required": [ "signature", "client_id", "timestamp" ] }
- field client_id: Annotated[UUID, UuidVersion(uuid_version=4)] [Required][source]#
- Constraints:
uuid_version = 4
- classmethod from_request(request: Request) Self[source]#
Get the required headers for HMAC authentication.
- Parameters:
request (Request) – The incoming request
- Raises:
AuthException – Authorization header is missing
AuthException – Authorization type not supported
AuthException – X-Client-Id header is missing
AuthException – Client id format is invalid
AuthException – X-Request-Timestamp header is missing
AuthException – Request timestamp has expired
- Returns:
Header values necessary for authenticating the request
- Return type:
- libs.sdk.src.destiny_sdk.auth.create_signature(secret_key: str, request_body: bytes, client_id: Annotated[UUID, UuidVersion(uuid_version=4)], timestamp: float) str[source]#
Create an HMAC signature using SHA256.
- Parameters:
secret_key (bytes) – secret key with which to encrypt message
request_body (bytes) – request body to be encrypted
client_id – client id to include in hmac
timestamp – timestamp for when the request is sent
- Type:
UUID4
- Type:
float
- Returns:
encrypted hexdigest of the request body with the secret key
- Return type:
str
Client Auth#
Send authenticated requests to Destiny Repository.
- class libs.sdk.src.destiny_sdk.client.Client(base_url: HttpUrl, secret_key: str, client_id: Annotated[UUID, UuidVersion(uuid_version=4)])[source]#
Client for interaction with the Destiny API.
Current implementation only supports robot results.
- poll_robot_enhancement_batch(robot_id: Annotated[UUID, UuidVersion(uuid_version=4)], limit: int = 10, timeout: int = 60) RobotEnhancementBatch | None[source]#
Poll for a robot enhancement batch.
Signs the request with the client’s secret key.
- Parameters:
robot_id (UUID4) – The ID of the robot to poll for
limit (int) – The maximum number of pending enhancements to return
- Returns:
The RobotEnhancementBatch object from the response, or None if no batches available
- Return type:
- send_robot_enhancement_batch_result(robot_enhancement_batch_result: RobotEnhancementBatchResult) RobotEnhancementBatchRead[source]#
Send a RobotEnhancementBatchResult to destiny repository.
Signs the request with the client’s secret key.
- Parameters:
robot_enhancement_batch_result (RobotEnhancementBatchResult) – The RobotEnhancementBatchResult to send
- Returns:
The RobotEnhancementBatchRead object from the response.
- Return type:
- send_robot_result(robot_result: RobotResult) EnhancementRequestRead[source]#
Send a RobotResult to destiny repository.
Signs the request with the client’s secret key.
- Parameters:
robot_result (RobotResult) – The RobotResult to send
- Returns:
The EnhancementRequestRead object from the response.
- Return type:
- class libs.sdk.src.destiny_sdk.client.HMACSigningAuth(secret_key: str, client_id: Annotated[UUID, UuidVersion(uuid_version=4)])[source]#
Client that adds an HMAC signature to a request.
- async async_auth_flow(request: Request) AsyncGenerator[Request, Response][source]#
Execute the authentication flow asynchronously.
By default, this defers to .auth_flow(). You should override this method when the authentication scheme does I/O and/or uses concurrency primitives.