Requirements
- Go 1.21 or later
- No external dependencies (standard library only)
Installation
The module path isgithub.com/AuthForgeCC/authforge-go. Install the latest release:
@latest with a v1.x.y tag.
Imports always use github.com/AuthForgeCC/authforge-go. Run go mod tidy after editing go.mod.
- Local replace (forks / air-gap)
replace at a directory that contains the SDK’s go.mod, then run go mod tidy.Quick start
Config reference
SessionTTL (grace period)
Requested lifetime of the session token returned by /auth/validate. This is the grace period: how long the app keeps running on the signed session without contacting AuthForge. Leave at 0 to accept the server default (24 hours). The server clamps the final value to [1h, 7d]. 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()orValidateLicense()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.
Validate license (no session)
ValidateLicense performs the same /auth/validate request and signature verification as Login, but does not persist session fields on the client, start the background goroutine, or invoke OnFailure for validate failures (network errors still return an error; repeated network failure does not call OnFailure when using ValidateLicense).
The SDK recognizes AUTHFORGE_SDK_TEST_NONCE for integration tests only; never set it in production (it pins the validate nonce).
Methods reference
Login and ValidateLicense return a LoginResult with:
SessionTokenExpiresInAppVariablesLicenseVariablesRequestID
Error handling
The Go SDK exposes sentinel errors so you can branch witherrors.Is:
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. Leave AppSecret empty so the air-gapped binary does not contain the App Secret.
errors.Is, in check order: ErrOfflineBadArmor, ErrOfflineBadSignature, ErrOfflineUnsupportedVersion, ErrOfflineMalformedPayload, ErrOfflineWrongApp, ErrOfflineExpired, ErrOfflineHwidMismatch; authforge.OfflineErrorCode(err) returns the cross-SDK string and OnFailure receives offline_login_failed: <code>. client.VerifyLicenseFile(pathOrText) and the package function authforge.VerifyLicenseFile(text, opts) run the same checks without touching state. Issued files cannot be revoked remotely; they stay valid until their own expiry. CreateActivationRequest(opts) produces the .authforge-request the operator uploads; hostname is omitted unless IncludeMachineName is set. See Activation requests.
Migrating from HeartbeatMode
HeartbeatMode ("server" / "local") is deprecated and may now be left empty:
HeartbeatMode: "local": remove the field; the grace period is now the default.HeartbeatMode: "server": useOnlineHeartbeat: trueinstead.