Python SDK API Reference
Complete API reference for the Hawcx Python SDK
Python SDK API Reference
HawcxOAuth
Initialize the OAuth client and exchange codes for verified claims.
from hawcx_oauth_client import HawcxOAuth
import os
oauth = HawcxOAuth(
config_id=os.getenv('HAWCX_API_KEY'),
base_url=os.getenv('HAWCX_BASE_URL') # optional
)exchange_code(auth_code, code_verifier)
Exchange an authorization code for verified claims.
result = oauth.exchange_code(auth_code, code_verifier)
claims = result.claims
# claims['sub'] = user ID
# claims.get('email') = verified email (if present)Returns:
result.id_token— raw JWT (do not use as access token)result.claims— verified claims
verify_token(token)
Verify a JWT and return its claims.
claims = oauth.verify_token(id_token)Delegation Client
Use the delegation client for backend-driven MFA setup and user/device management.
HawcxDelegationClient.from_keys()
from hawcx_oauth_client.delegation import HawcxDelegationClient
import os
client = HawcxDelegationClient.from_keys(
sp_signing_key=os.getenv('SP_ED25519_PRIVATE_KEY_PEM'),
sp_encryption_key=os.getenv('SP_X25519_PRIVATE_KEY_PEM'),
idp_verify_key=os.getenv('IDP_ED25519_PUBLIC_KEY_PEM'),
idp_encryption_key=os.getenv('IDP_X25519_PUBLIC_KEY_PEM'),
base_url=os.getenv('HAWCX_BASE_URL') or 'https://api.hawcx.com',
sp_id=os.getenv('OAUTH_CLIENT_ID')
)MFA
from hawcx_oauth_client.delegation import MfaMethod
result = client.initiate_mfa_change(
userid='[email protected]',
mfa_method=MfaMethod.SMS,
phone_number='+15551234567'
)
client.verify_mfa_change(
userid='[email protected]',
session_id=result['session_id'],
otp='123456'
)Users
creds = client.get_user_credentials('[email protected]')