A Node.js implementation for Autholas authentication service with hardware ID verification.
- User authentication via Autholas API
- Hardware ID generation using system information
- Cross-platform support (Windows/Linux/macOS)
- Built-in crypto module for SHA-256 hashing
- Comprehensive error handling
- Promise-based async/await support
- Node.js 12.0 or higher
- npm (Node Package Manager)
Download and install Node.js from nodejs.org
# Initialize a new Node.js project
npm init -y
# Install required dependencies
npm install axios
# Alternative: Install specific version
npm install axios@^1.0.0Create or update your package.json:
{
"name": "autholas-auth",
"version": "1.0.0",
"description": "Autholas Authentication System",
"main": "main.js",
"scripts": {
"start": "node main.js",
"dev": "nodemon main.js"
},
"dependencies": {
"axios": "^1.0.0"
},
"devDependencies": {
"nodemon": "^2.0.0"
},
"keywords": ["autholas", "authentication", "api"],
"author": "Your Name",
"license": "MIT"
}├── autholas.js # Authentication functions and utilities
├── main.js # Main program entry point
├── package.json # Node.js project configuration
├── package-lock.json # Dependency lock file
└── README.md # This file
- Open
autholas.js - Replace
YOUR_API_KEY_HEREwith your actual Autholas API key:const API_KEY = 'your_actual_api_key_here';
# Run the application
node main.js
# Or using npm script
npm start
# For development with auto-restart
npm install -g nodemon
nodemon main.jsconst { authenticateUser, getHardwareID } = require('./autholas');
async function login() {
const hwid = getHardwareID();
console.log(`Hardware ID: ${hwid}`);
const result = await authenticateUser('username', 'password', hwid);
if (result.success) {
console.log('Authentication successful!');
console.log(`Session token: ${result.sessionToken}`);
return result.sessionToken;
} else {
console.log(`Authentication failed: ${result.error}`);
return null;
}
}
login().then(token => {
if (token) {
// Start your application
console.log('Welcome to the application!');
}
}).catch(console.error);Generates a unique hardware ID based on:
- System hostname
- Username
- System architecture
Returns: string - SHA-256 hash of combined system info
Authenticates user with Autholas API.
Parameters:
username(string) - User's usernamepassword(string) - User's passwordhwid(string) - Hardware ID fromgetHardwareID()
Returns: Promise<Object>
{
success: true/false,
sessionToken: 'token_string', // Only if success
error: 'error_message', // Only if failed
errorCode: 'ERROR_CODE' // Only if failed
}Displays user-friendly error messages for different error codes.
Helper function for command-line input.
Parameters:
query(string) - Question to display
Returns: Promise<string> - User input
The system handles various authentication errors:
INVALID_CREDENTIALS- Wrong username/passwordUSER_BANNED- Account suspendedSUBSCRIPTION_EXPIRED- Subscription endedMAX_DEVICES_REACHED- Device limit exceededHWID_BANNED- Device bannedRATE_LIMIT_EXCEEDED- Too many attemptsMISSING_PARAMETERS- Invalid request- Network errors (ECONNREFUSED, ENOTFOUND, ECONNABORTED)
const { authenticateUser, getHardwareID, question } = require('./autholas');
class AuthManager {
constructor() {
this.sessionToken = null;
this.hwid = getHardwareID();
}
async login() {
const username = await question('Username: ');
const password = await question('Password: ');
const result = await authenticateUser(username, password, this.hwid);
if (result.success) {
this.sessionToken = result.sessionToken;
return true;
}
return false;
}
isAuthenticated() {
return this.sessionToken !== null;
}
getToken() {
return this.sessionToken;
}
}
// Usage
async function main() {
const auth = new AuthManager();
if (await auth.login()) {
console.log('Access granted!');
// Start your application
startApp(auth.getToken());
} else {
console.log('Access denied!');
process.exit(1);
}
}
function startApp(token) {
console.log(`Application started with token: ${token}`);
// Your application logic here
}
main().catch(console.error);For production, use environment variables:
// In autholas.js
const API_KEY = process.env.AUTHOLAS_API_KEY || 'YOUR_API_KEY_HERE';
const API_URL = process.env.AUTHOLAS_API_URL || 'https://autholas.web.id/api/auth';Create a .env file:
AUTHOLAS_API_KEY=your_actual_api_key_here
AUTHOLAS_API_URL=https://autholas.web.id/api/authInstall and use dotenv:
npm install dotenv// At the top of your main.js
require('dotenv').config();-
Error: Cannot find module 'axios'
npm install axios
-
ECONNREFUSED errors
- Check internet connection
- Verify API URL is correct
- Check if firewall is blocking the connection
-
Request timeout
- Increase timeout in axios config
- Check network stability
-
SSL/TLS errors
npm update # Or disable SSL verification (not recommended) process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
const axios = require('axios');
async function testConnection() {
try {
const response = await axios.get('https://httpbin.org/status/200', { timeout: 5000 });