"""
Cardinity Authentication
This module handles OAuth 1.0 authentication for the Cardinity API.
"""
from typing import Dict
from requests_oauthlib import OAuth1
[docs]
class CardinityAuth:
"""OAuth 1.0 authentication handler for Cardinity API.
This class manages OAuth 1.0 authentication using HMAC-SHA1 signature method
as required by the Cardinity API. It provides authentication headers for
HTTP requests.
"""
[docs]
def __init__(self, consumer_key: str, consumer_secret: str) -> None:
"""Initialize the Cardinity authentication handler.
Args:
consumer_key: The OAuth consumer key provided by Cardinity
consumer_secret: The OAuth consumer secret provided by Cardinity
Raises:
ValueError: If consumer_key or consumer_secret is empty
"""
if not consumer_key:
raise ValueError("Consumer key cannot be empty")
if not consumer_secret:
raise ValueError("Consumer secret cannot be empty")
self.consumer_key = consumer_key
self.consumer_secret = consumer_secret
[docs]
def get_auth(self) -> OAuth1:
"""Get the OAuth1 authentication object for requests.
Returns:
OAuth1: Configured OAuth1 authentication object that can be used
with the requests library
"""
return OAuth1(
client_key=self.consumer_key,
client_secret=self.consumer_secret,
signature_method="HMAC-SHA1",
signature_type="AUTH_HEADER",
)
[docs]
def __repr__(self) -> str:
"""Return a string representation of the auth object."""
return f"CardinityAuth(consumer_key='{self.consumer_key[:8]}...')"