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
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.
- send_batch_robot_result(batch_robot_result: BatchRobotResult) BatchEnhancementRequestRead [source]#
Send a BatchRobotResult to destiny repository.
Signs the request with the client’s secret key.
- Parameters:
batch_robot_result (BatchRobotResult) – The Batch Robot Result to send
- Returns:
The BatchEnhancementRequestRead 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 Robot Result 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.