Complete guide to integrating Lockence authentication into your applications. Works with Python, C++, C#, and any language that supports HTTP requests.
https://your-domain.com/api/v1
Include your API key in the request body for all endpoints. You can find your API key in the dashboard after creating an application.
{
"api_key": "your_api_key_here",
...
}
Validates a license key and creates an authenticated session. This is the first endpoint you call when a user starts your application.
{
"api_key": "string", // Your application API key
"license_key": "string", // User's license key
"hwid": "string" // Hardware ID (unique device identifier)
}
{
"success": true,
"message": "Authentication successful",
"session_token": "uuid",
"expires_at": "2025-01-18T12:00:00Z",
"username": "john_doe",
"metadata": {}
}
{
"success": false,
"message": "Invalid license key" | "License expired" | "HWID mismatch"
}
import requests
import hashlib
import platform
def get_hwid():
"""Generate hardware ID from machine info"""
return hashlib.sha256(
platform.node().encode()
).hexdigest()
def initialize_license(api_key, license_key):
"""Initialize and validate license"""
response = requests.post(
"https://your-domain.com/api/v1/init",
json={
"api_key": api_key,
"license_key": license_key,
"hwid": get_hwid()
}
)
data = response.json()
if data["success"]:
return data["session_token"]
else:
raise Exception(data["message"])
# Usage
try:
session = initialize_license(
"your_api_key",
"XXXXX-XXXXX-XXXXX-XXXXX"
)
print(f"Authenticated! Session: {session}")
except Exception as e:
print(f"Authentication failed: {e}")
Checks if a session is still valid. Call this periodically to ensure the user is still authenticated.
{
"api_key": "string",
"session_token": "string"
}
{
"success": true,
"message": "Session is valid",
"username": "john_doe",
"metadata": {}
}
def validate_session(api_key, session_token):
"""Validate an active session"""
response = requests.post(
"https://your-domain.com/api/v1/validate",
json={
"api_key": api_key,
"session_token": session_token
}
)
data = response.json()
return data["success"]
# Usage
if validate_session("your_api_key", session_token):
print("Session is valid")
else:
print("Session expired or invalid")
Updates the last activity timestamp for a session. Call this every few minutes to keep the session alive and track user activity.
{
"api_key": "string",
"session_token": "string"
}
import time
import threading
def heartbeat_loop(api_key, session_token):
"""Send heartbeat every 5 minutes"""
while True:
try:
requests.post(
"https://your-domain.com/api/v1/heartbeat",
json={
"api_key": api_key,
"session_token": session_token
}
)
except:
pass
time.sleep(300) # 5 minutes
# Start heartbeat in background thread
thread = threading.Thread(
target=heartbeat_loop,
args=(api_key, session_token),
daemon=True
)
thread.start()
Terminates an active session. Call this when the user closes your application or logs out.
{
"api_key": "string",
"session_token": "string"
}
def logout(api_key, session_token):
"""Terminate session"""
response = requests.post(
"https://your-domain.com/api/v1/logout",
json={
"api_key": api_key,
"session_token": session_token
}
)
return response.json()["success"]
401 Unauthorized
Invalid API key
403 Forbidden
License expired, disabled, or HWID mismatch
404 Not Found
License key or session not found
500 Internal Server Error
Server error - contact support