|
| 1 | +Metadata-Version: 2.4 |
| 2 | +Name: authforge |
| 3 | +Version: 1.0.0 |
| 4 | +Summary: Official Python SDK for AuthForge — credit-based license key authentication with Ed25519-verified responses. |
| 5 | +Author: AuthForge |
| 6 | +License: MIT |
| 7 | +Project-URL: Homepage, https://authforge.cc |
| 8 | +Project-URL: Documentation, https://docs.authforge.cc |
| 9 | +Project-URL: Source, https://github.com/AuthForgeCC/authforge-python |
| 10 | +Project-URL: Issues, https://github.com/AuthForgeCC/authforge-python/issues |
| 11 | +Keywords: authforge,license,licensing,hwid,authentication |
| 12 | +Classifier: Development Status :: 5 - Production/Stable |
| 13 | +Classifier: Intended Audience :: Developers |
| 14 | +Classifier: License :: OSI Approved :: MIT License |
| 15 | +Classifier: Operating System :: OS Independent |
| 16 | +Classifier: Programming Language :: Python :: 3 |
| 17 | +Classifier: Programming Language :: Python :: 3.9 |
| 18 | +Classifier: Programming Language :: Python :: 3.10 |
| 19 | +Classifier: Programming Language :: Python :: 3.11 |
| 20 | +Classifier: Programming Language :: Python :: 3.12 |
| 21 | +Classifier: Programming Language :: Python :: 3.13 |
| 22 | +Requires-Python: >=3.9 |
| 23 | +Description-Content-Type: text/markdown |
| 24 | +License-File: LICENSE |
| 25 | +Requires-Dist: cryptography>=41.0.0 |
| 26 | +Dynamic: license-file |
| 27 | + |
| 28 | +# AuthForge Python SDK |
| 29 | + |
| 30 | +Official Python SDK for [AuthForge](https://authforge.cc) — credit-based license key authentication with Ed25519-verified responses. |
| 31 | + |
| 32 | +Uses `cryptography` for Ed25519 verification. Works on Python 3.9+. |
| 33 | + |
| 34 | +## Quick Start |
| 35 | + |
| 36 | +Install from PyPI: |
| 37 | + |
| 38 | +```bash |
| 39 | +pip install authforge |
| 40 | +``` |
| 41 | + |
| 42 | +Or copy `authforge.py` into your project directly, then: |
| 43 | + |
| 44 | +```python |
| 45 | +from authforge import AuthForgeClient |
| 46 | + |
| 47 | +client = AuthForgeClient( |
| 48 | + app_id="YOUR_APP_ID", # from your AuthForge dashboard |
| 49 | + app_secret="YOUR_APP_SECRET", # from your AuthForge dashboard |
| 50 | + public_key="YOUR_PUBLIC_KEY", # from your AuthForge dashboard |
| 51 | + heartbeat_mode="SERVER", # "SERVER" or "LOCAL" |
| 52 | +) |
| 53 | + |
| 54 | +license_key = input("Enter license key: ") |
| 55 | + |
| 56 | +if client.login(license_key): |
| 57 | + print("Authenticated!") |
| 58 | + # Your app logic here — heartbeats run automatically in the background |
| 59 | +else: |
| 60 | + print("Invalid license key.") |
| 61 | + exit(1) |
| 62 | +``` |
| 63 | + |
| 64 | +## Configuration |
| 65 | + |
| 66 | +| Parameter | Type | Default | Description | |
| 67 | +|---|---|---|---| |
| 68 | +| `app_id` | str | required | Your application ID from the AuthForge dashboard | |
| 69 | +| `app_secret` | str | required | Your application secret from the AuthForge dashboard | |
| 70 | +| `public_key` | str | required | App Ed25519 public key (base64) from dashboard | |
| 71 | +| `heartbeat_mode` | str | required | `"SERVER"` or `"LOCAL"` (see below) | |
| 72 | +| `heartbeat_interval` | int | `900` | Seconds between heartbeat checks (default 15 min) | |
| 73 | +| `api_base_url` | str | `https://auth.authforge.cc` | API endpoint | |
| 74 | +| `on_failure` | callable | `None` | Callback `(reason: str, exc: Exception | None)` on auth failure | |
| 75 | +| `request_timeout` | int | `15` | HTTP request timeout in seconds | |
| 76 | + |
| 77 | +## Methods |
| 78 | + |
| 79 | +| Method | Returns | Description | |
| 80 | +|---|---|---| |
| 81 | +| `login(license_key)` | `bool` | Validates key and stores signed session (`sessionToken`, `expiresIn`, `appVariables`, `licenseVariables`) | |
| 82 | +| `logout()` | `None` | Stops heartbeat and clears all session/auth state | |
| 83 | +| `is_authenticated()` | `bool` | True when an active authenticated session exists | |
| 84 | +| `get_session_data()` | `dict \| None` | Full decoded payload map | |
| 85 | +| `get_app_variables()` | `dict \| None` | App-scoped variables map | |
| 86 | +| `get_license_variables()` | `dict \| None` | License-scoped variables map | |
| 87 | + |
| 88 | +## Heartbeat Modes |
| 89 | + |
| 90 | +**SERVER** — The SDK calls `/auth/heartbeat` every `heartbeat_interval` seconds with a fresh nonce, verifies signature + nonce, and triggers failure on invalid session state. |
| 91 | + |
| 92 | +**LOCAL** — No network calls. The SDK re-verifies stored signature state and checks expiry timestamp locally. If expired, it triggers failure with `session_expired`. |
| 93 | + |
| 94 | +## Failure Handling |
| 95 | + |
| 96 | +If authentication fails (login rejected, heartbeat fails, signature mismatch, etc.), the SDK calls your `on_failure` callback if one is provided. If no callback is set, **the SDK calls `os._exit(1)` to terminate the process.** This is intentional — it prevents your app from running without a valid license. |
| 97 | + |
| 98 | +Recognized server errors: |
| 99 | +`invalid_app`, `invalid_key`, `expired`, `revoked`, `hwid_mismatch`, `no_credits`, `blocked`, `rate_limited`, `replay_detected`, `app_disabled`, `session_expired`, `bad_request` |
| 100 | + |
| 101 | +Request retries are automatic inside the internal HTTP layer: |
| 102 | +- `rate_limited`: retry after 2s, then 5s (max 3 attempts total) |
| 103 | +- network failure: retry once after 2s |
| 104 | +- every retry regenerates a fresh nonce |
| 105 | + |
| 106 | +```python |
| 107 | +def handle_auth_failure(reason, exception): |
| 108 | + print(f"Auth failed: {reason}") |
| 109 | + if exception: |
| 110 | + print(f"Details: {exception}") |
| 111 | + # Clean up and exit gracefully |
| 112 | + sys.exit(1) |
| 113 | + |
| 114 | +client = AuthForgeClient( |
| 115 | + app_id="YOUR_APP_ID", |
| 116 | + app_secret="YOUR_APP_SECRET", |
| 117 | + public_key="YOUR_PUBLIC_KEY", |
| 118 | + heartbeat_mode="SERVER", |
| 119 | + on_failure=handle_auth_failure, |
| 120 | +) |
| 121 | +``` |
| 122 | + |
| 123 | +## How It Works |
| 124 | + |
| 125 | +1. **Login** — Collects a hardware fingerprint (MAC, CPU, disk serial), generates a random nonce, and sends everything to the AuthForge API. The server validates the license key, binds the HWID, deducts a credit, and returns a signed payload. The SDK verifies the Ed25519 signature and nonce to prevent replay attacks. |
| 126 | + |
| 127 | +2. **Heartbeat** — A background daemon thread checks in at the configured interval. In SERVER mode, it sends a fresh nonce and verifies the response. In LOCAL mode, it re-verifies the stored signature and checks expiry without network calls. |
| 128 | + |
| 129 | +3. **Crypto** — Both `/validate` and `/heartbeat` responses are signed by AuthForge with your app's Ed25519 private key. The SDK verifies every signed `payload` using your configured `public_key` and rejects tampered responses. |
| 130 | + |
| 131 | +## Hardware ID |
| 132 | + |
| 133 | +The SDK generates a deterministic hardware fingerprint by hashing: |
| 134 | +- MAC address |
| 135 | +- CPU identifier |
| 136 | +- Disk serial number |
| 137 | + |
| 138 | +Each component falls back gracefully if it can't be read (e.g. permissions issues). The HWID is sent with every auth request so the server can enforce per-device license limits. |
| 139 | + |
| 140 | +## Test Vectors |
| 141 | + |
| 142 | +The shared `test_vectors.json` file validates cross-language Ed25519 verification behavior. |
| 143 | + |
| 144 | +## Requirements |
| 145 | + |
| 146 | +- Python 3.9+ |
| 147 | +- Dependency: `cryptography` |
| 148 | + |
| 149 | +## License |
| 150 | + |
| 151 | +MIT |
0 commit comments