LeetAuth API
Code examples
Stuck at implementing our authentication system? Look here to find some code snippets explaining how to do so in 3 different languages. Check this page regularly as we may add your language here too.
All examples are raw implementations of our API. For the time being LeetAuth does not provide any official packages/modules for any languages. This is a simple guide that can be edited, distributed and shared by and to anyone using LeetAuth
The LeetAuth API supports every programming language that has any type of HTTP client and can parse JSON data. Here we only have snippets for most commonly cases of usage. Soon we will add more languages like: Golang, PHP, C++, Rust and Javascript

Python 3

This example can also be found at: https://github.com/LeetAuth/PythonExample

# Importing requests module for talking to the API
import requests
# Importing JSON for reading the response body
import json
# Importing simplejson for error handling when downloading a file
import simplejson
from urllib.parse import urlencode
class LeetAuth:
def __init__(self, identifier: str):
self.base_url = "https://api.leet-auth.dev/public"
self.app_id = identifier
self.auth_token = ""
def url(self, path: str) -> str:
return self.base_url + path
def format_json(json_body: dict) -> str:
return json.dumps(json_body, indent=4, ensure_ascii=True)
def headers(self) -> dict:
return {
"Authorization": self.auth_token,
"User-Agent": "LeetAuth"
# Pre-Auth Functions
def login(self, username: str, password: str, **kwargs) -> str:
response = requests.post(self.url("/authenticate"), params={
"app": self.app_id,
"username": username,
"password": password,
"hwid": kwargs.get("hwid", ""),
"checksum": kwargs.get("checksum", "")
}, headers=self.headers)
# Getting the JSON response from our API
json_body = response.json()
# Assigning the JWT to our session
if json_body["status"]:
self.auth_token = json_body["token"]
return self.format_json(json_body)
def register(self, username: str, password: str, license_key: str, **kwargs) -> str:
response = requests.post(self.url("/register"), params={
"app": self.app_id,
"username": username,
"password": password,
"license": license_key,
"hwid": kwargs.get("hwid", ""),
"checksum": kwargs.get("checksum", "")
}, headers=self.headers)
return self.format_json(response.json())
def renew_plan(self, username: str, license: str) -> str;
response = requests.post(self.url("/renew"), params={
"app": self.app_id,
"username": username,
"license": license_key,
}, headers=self.headers)
return self.format_json(response.json())
# Post-Auth functions
def get_properties(self) -> str:
response = requests.get(self.url("/properties"), params={
"app": self.app_id,
}, headers=self.headers)
return self.format_json(response.json())
def change_password(self, new_password: str, confirm_new_password: str) -> str:
response = requests.post(self.url("/change_password"), params={
"app": self.app_id,
"new_password": new_password,
"cnf_password": confirm_new_password
}, headers=self.headers)
return self.format_json(response.json())
def get_login_logs(self) -> str:
response = requests.get(self.url("/logins"), params={
"app": self.app_id,
}, headers=self.headers)
return self.format_json(response.json())
def download_file(self, file_name: str, path_to_save: str) -> str:
response = requests.get(self.url("/files/") + file_name, params={
"app": self.app_id,
}, headers=self.headers)
json_body = response.json()
except simplejson.errors.JSONDecodeError:
# Writing the file in chunks, its a better way of writing if the file is big
with open(path_to_save, 'wb') as downloaded_file:
for chunk in response.iter_content(chunk_size=128):
# Returning a hardocded sucess response
return self.format_json({
"status": True,
"note": "Successfully downloaded the file"
return self.format_json(json_body)
def get_variable(self, variable_name: str) -> str:
response = requests.get(self.url("/variables/") + variable_name, params={
"app": self.app_id,
}, headers=self.headers)
return self.format_json(response.json())

Usage example

# All methods besides the LeetAuth() return a string which can be printed out
# the string is just a nicely formatted JSON response, it can be loaded using
# json.loads(function_return) to have a dictionary object of it
# Creating a class instance using the class above
auth = LeetAuth("app_id")
# the hwid & checksum are optional arguments, if not provided they will be sent as empty strings
auth.register("username", "password", "license", hwid="hardware identifier", checksum="app checksum")
auth.login("username", "password", hwid="hardware identifier", checksum="app checksum")
if auth.auth_token == "":
print("Something went wrong during the authentication")
# Exitting the app and returning a non 0 response
auth.change_password("newPassword123!", "newPassword123!")
auth.download_file("hey.txt", "./myfile.txt")
print(auth.renew_plan("username", "license-key"))


We have created 2 examples for you guys to look at in order to integrate LeetAuth into your own service.

Copy link