Requirements
- Python 3.9 or later
- Dependencies:
cryptographyandtyping_extensions(installed automatically with the PyPI package).
Installation
Install from PyPI asauthforge-sdk. In code, import the authforge module:
Need a vendored single file? Copy
authforge.py from the GitHub repository and ensure cryptography is declared in your environment. The published wheel is recommended for most projects.Quick start
Constructor parameters
ttl_seconds (grace period)
Requested session token lifetime in seconds for /auth/validate. This is the grace period: how long the app keeps running on the signed session without contacting AuthForge. Pass None (or omit) to accept the server default of 24 hours. The server clamps to [3600, 604800] (1 hour to 7 days). The requested TTL is preserved across heartbeat refreshes, and apps relying on the grace period alone can extend their window up to 7 days.
Billing
- Each successful
login()orvalidate_license()costs 1 credit (one/auth/validatedebit). - The grace period is free: local session re-verification makes no network calls and consumes no credits.
- Online check-ins (if enabled) cost 1 credit per 10 successful heartbeats (billed on every 10th call).
- With online check-ins, revocations take effect on the next check-in regardless of interval; without them, at session expiry.
Login
True if authentication succeeded, False otherwise. On success, the SDK starts a background thread that re-verifies the signed session locally during the grace period (and sends online check-ins if online_heartbeat=True).
Validate license (no session)
/auth/validate flow and signatures as login, without storing session state on the client or starting the background thread. On success, the result includes optional entitlement convenience fields when the server sends them: session_expires_at, license_expires_at (None for lifetime keys after a JSON null), max_hwid_slots, hwid_count, and license_label. The full signed payload remains in session_data.
Failure callback
If authentication fails, an online check-in fails, or the session expires, the SDK calls youron_failure callback. If no callback is set (or the callback raises an exception), the SDK calls os._exit(1).
Reading variables
After a successful login, app variables and license variables are available on the client:Grace period and online check-ins
By default, the app runs through the grace period after activation: the SDK re-verifies the signed session locally, makes no network calls, and stops when the session expires. Opt in to online check-ins for fast revocation and concurrent-use detection:Offline license files (.authforge)
For machines that never connect to the internet, the operator mints a signed offline license file in the dashboard or Developer API (1 credit). The SDK verifies it locally with your public key and the machine HWID; no network, no check-ins, and online login() is untouched. Construct the client with app_secret=None (or "") so the air-gapped binary does not contain the App Secret.
on_failure("offline_login_failed", ValueError(code)) and return False (never os._exit). Codes, in check order: bad_armor, bad_signature, unsupported_version, malformed_payload, wrong_app, expired, hwid_mismatch. client.verify_license_file(path_or_text) and the module-level authforge.verify_license_file(text, app_id, public_key, hwid) run the same checks without touching state. Issued files cannot be revoked remotely; they stay valid until their own expiry. create_activation_request() / write_activation_request(path) produce the .authforge-request the operator uploads; hostname is omitted unless include_machine_name=True. See Activation requests.
Migrating from heartbeat_mode
heartbeat_mode="LOCAL" / "SERVER" is deprecated (it emits a DeprecationWarning) but still accepted:
heartbeat_mode="LOCAL": remove the option; the grace period is now the default.heartbeat_mode="SERVER": useonline_heartbeat=Trueinstead.