auth.php¶
Authentication and authorization module: session management, login via WHMCS, LDAP, API keys, and SSO (Google, GitHub, VK), 2FA verification, SMS and email, as well as customer tag management.
API Methods¶
| Method | Action | Description |
|---|---|---|
2fa_check | check 2FA | Validates the two-factor authentication code for the current user session. |
2fa_resend | resend 2FA code | Resends the two-factor authentication code to the specified method (Email or SMS) for the current session. |
billing_list | get list of available billings | Returns a list of available payment systems (billings) configured for the current user or administrator. |
email_check | check email | Checks if a customer exists by email in the specified billing location. If the customer is not found, a new profile is created. Sends a verification code to the email. |
flip_tag | toggle tag | Creates or removes the specified tag for the customer. If the tag already exists, it will be removed; if it does not exist, it will be added. |
get_log | get authorization log | Returns the authorization event log for a specified period or by token. |
get_log_details | get authentication log details | Returns detailed information about authentication events for a user via their token. |
github_init | initialize GitHub SSO | Initiates the authorization process via GitHub, generates a unique state, and returns client data to redirect the user to GitHub. |
github_signin | authorize via GitHub | Initiates the OAuth authorization process via GitHub. Generates a temporary state and token for subsequent code-to-session exchange. |
google_signin | authorize via Google SSO | Performs login using a Google ID Token. If the token is valid, it attaches it to the current session or links it to an existing user account. |
info | get token information | Returns detailed information about the current user session, including role, permissions, customer data, and a list of available servers. |
ipalogin | login via LDAP (IPA) | Employee authorization via LDAP (IPA) with the possibility of server binding. |
login | authorize by API key | Authorizes a user via the provided API key, establishes a session, and returns data regarding permissions and available servers. |
logout | logout from system | Deletes the current active access token, terminating the user session. |
session_reset | reset session | Terminates all active user sessions based on their email and reset token. Performs cleanup of tags (sessions) in the database. |
set_tag | manage user tag | Creates or removes a tag for the customer. For regular users, only the 'auto_credit' tag is allowed. |
tg_verify | bind Telegram username | Binds the user's Telegram username to their account and returns a link to the bot for notifications. |
vk_init | initialize VK authorization | Initiates the OAuth authorization process via VK, generating temporary data (state, code_challenge) and saving it in the database for subsequent verification. |
vk_signin | authorize via VK | Initiates the user authorization process through the VKontakte social network. Creates temporary tags to complete the OAuth process and redirects to a confirmation page. |
whmcslogin | authorize via WHMCS or SSO | Performs login. Supports standard email/password authorization, as well as login via third-party services (Google, GitHub, VK) and automatic billing selection. |
auth/2fa_check¶
Validates the two-factor authentication code for the current user session.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | ✅ | string | Session authorization token |
| code | ❌ | string | Two-factor authentication code (passed via $user_token) |
Example Request
Failure response
``` { "code": -1, "message": "Access denied by IP restrictions" }
```
auth/2fa_resend¶
Resends the two-factor authentication code to the specified method (Email or SMS) for the current session.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: 2fa_resend |
| token | ✅ | string | Active user session token |
| from | ❌ | string | Request source: user_profile or resend_dialog |
Example Request
Failure response
``` { "code": -1, "message": "Unable to load authentication data, please try again" }
```
auth/billing_list¶
Returns a list of available payment systems (billings) configured for the current user or administrator.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: billing_list |
| token | ❌ | string | Session token to determine access rights (admin/customer) |
Example Request
Example of a successful response
Failure response
``` { "code": -2, "message": "Malformed request" }
```
auth/email_check¶
Checks if a customer exists by email in the specified billing location. If the customer is not found, a new profile is created. Sends a verification code to the email.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: email_check |
| user_email | ✅ | string | User email (e.g., [email protected]) |
| location | ✅ | string | Billing location (e.g., whmcs) |
| user_token | ❌ | string | Token for verification check |
Example Request
curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=email_check" \
--data "[email protected]" \
--data "location=whmcs"
Example of a successful response
{
"result": "OK",
"state": "verified",
"status": "Email address [email protected] is now verified."
}
Failure response
``` { "code": 0, "message": "Invalid email or billing location error" }
```
auth/flip_tag¶
Creates or removes the specified tag for the customer. If the tag already exists, it will be removed; if it does not exist, it will be added.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: flip_tag |
| token | ✅ | string | Session authorization token |
| tag | ✅ | string | Tag name (maximum 32 characters). For customers, only 'auto_credit' is allowed |
Example Request
Example of a successful response
Failure response
``` { "code": -2, "message": "TAG_MISSING", "details": "\(module/\)action: tag is missing" }
```
auth/get_log¶
Returns the authorization event log for a specified period or by token.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: get_log |
| token | ✅ | string | Session token |
| user_token | ❌ | string | User token for log search |
| period_start | ❌ | string | Start of the period (YYYY-MM-DD) |
| period_stop | ❌ | string | End of the period (YYYY-MM-DD) |
| user_email | ❌ | string | User email for log filtering |
Example Request
Example of a successful response
auth/get_log_details¶
Returns detailed information about authentication events for a user via their token.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | ✅ | string | User session token |
| user_token | ❌ | string | Additional token to retrieve logs for a specific user |
Example Request
Example of a successful response
{
"result": "OK",
"log": [
{
"id": 123,
"event": "login_success",
"timestamp": "2024-05-20T10:30:00Z",
"ip": "192.168.1.1",
"details": {
"user": "[email protected]",
"location": "US"
}
}
]
}
Failure response
``` { "code": 404, "message": "Invalid period or log is empty" }
```
auth/github_init¶
Initiates the authorization process via GitHub, generates a unique state, and returns client data to redirect the user to GitHub.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: github_init |
| token | ❌ | string | Current session token |
Example of a successful response
Failure response
``` { "code": -1, "message": "sso_github_unavailable" }
```
auth/github_signin¶
Initiates the OAuth authorization process via GitHub. Generates a temporary state and token for subsequent code-to-session exchange.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: github_signin |
| state | ✅ | string | OAuth state (contains 6 random characters at the end for verification) |
| token | ❌ | string | Existing session token to link GitHub to the current account |
| code | ✅ | string | code parameter (detected in code) |
Example Request
Example of a successful response
Failure response
``` { "code": -1, "message": "SSO_UNAVAILABLE" }
```
auth/google_signin¶
Performs login using a Google ID Token. If the token is valid, it attaches it to the current session or links it to an existing user account.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: google_signin |
| credential | ✅ | string | Google ID Token (JWT) for user verification |
| token | ❌ | string | Current session token to link Google SSO to an existing account |
Example Request
Example of a successful response
Failure response
``` { "MISSING_CREDENTIAL": { "result": "error", "message": "auth/google_signin: credential is missing", "error_code": "MISSING_CREDENTIAL" }, "INVALID_CREDENTIAL": { "result": "error", "message": "auth/google_signin: invalid credential", "error_code": "INVALID_CREDENTIAL" } }
```
auth/info¶
Returns detailed information about the current user session, including role, permissions, customer data, and a list of available servers.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | ✅ | string | Session authorization token |
Example Request
Example of a successful response
{
"result": "OK",
"role": "Customer",
"role_type": "Customer",
"whmcs_id": 12345,
"whmcs_location": "US",
"servers": [
101,
102
],
"customer_id": 5678,
"permissions": [
"manage_products",
"show_invoices",
"edit_master_profile"
],
"token_expire": 1735689600,
"new": 1,
"prebill": 0,
"email": "[email protected]",
"client_ip": "192.168.1.1",
"timing": {
"auth_validate_token": 5,
"auth_get_role": 2,
"list_permissions": 1
},
"billing_servers": [],
"deploy_keys": {},
"has_product_subscription": false,
"private_ranges": [],
"private_vlans": [],
"verified": null,
"sumsub_id": null,
"sumsub_comment": null,
"corporate": 0,
"tags": [],
"default_lang": "en",
"billing_options": []
}
Failure response
``` { "code": -2, "message": "Invalid token" }
```
auth/login¶
Authorizes a user via the provided API key, establishes a session, and returns data regarding permissions and available servers.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| key | ✅ | string | API key for authorization |
| ttl | ❌ | integer | Token lifetime in seconds (default 3600) |
Example Request
Example of a successful response
{
"token": "7bc29eb23fb1b879b21fce509597f07c",
"role": "Customer",
"role_type": "Customer",
"whmcs_id": 12345,
"whmcs_location": "US",
"servers": [
101,
102
],
"invapi": "https://invapi.hostkey.com",
"customer_id": 5678,
"permissions": [
"manage_products",
"show_invoices"
],
"token_expire": 1715432400,
"new": 1,
"prebill": true,
"prebill_scope": "all"
}
Failure response
``` { "code": -1, "message": "No appropriate servers found" }
```
auth/logout¶
Deletes the current active access token, terminating the user session.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: logout |
| token | ✅ | string | Active authorization token |
Example Request
Failure response
``` { "code": -2, "message": "Token is not specified" }
```
auth/session_reset¶
Terminates all active user sessions based on their email and reset token. Performs cleanup of tags (sessions) in the database.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | ✅ | string | Authorization token to perform the action |
| user_email | ✅ | string | User email for session reset |
| reset_token | ✅ | string | Special reset token (hash of user_email + RESET_TOKEN_SECRET) |
| confirm | ❌ | int | Action confirmation flag (1 to execute) |
Example Request
Failure response
``` { "code": -2, "message": "Malformed request" }
```
auth/set_tag¶
Creates or removes a tag for the customer. For regular users, only the 'auto_credit' tag is allowed.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: set_tag |
| token | ✅ | string | Session token for access rights verification |
| tag | ✅ | string | Tag name (max. 32 characters) |
| set | ✅ | boolean | Flag to create (1) or remove (0/empty) the tag |
Example Request
Example of a successful response
Failure response
`` { "TAG_MISSING": { "code": -2, "message": "$module/$action: tag is missing" }, "VALUE_MISSING": { "code": -2, "message": "$module/$action: set is missing" }, "TAG_TOO_LONG": { "code": -2, "message": "$module/$action: tag too long (32 max)" }, "TAG_INVALID": { "code": -2, "message": "$module/$action: invalid tag (onlyauto_credit` is allowed)" }, "NO_CUSTOMER_ID": { "code": -2, "message": "\(module/\)action: no customer_id tags were found" } }
```
auth/tg_verify¶
Binds the user's Telegram username to their account and returns a link to the bot for notifications.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: tg_verify |
| token | ✅ | string | Session authorization token |
| tg_username | ✅ | string | User's Telegram username (without @ and links) |
Example Request
Failure response
``` { "code": -1, "message": "Illegal TG username" }
```
auth/vk_init¶
Initiates the OAuth authorization process via VK, generating temporary data (state, code_challenge) and saving it in the database for subsequent verification.
HTTP-method: POST|GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: vk_init |
| token | ❌ | string | Existing session token (if any) |
Example of a successful response
Failure response
``` { "result": -1, "error": "SSO_UNAVAILABLE", "message": "sso_github_unavailable" }
```
auth/vk_signin¶
Initiates the user authorization process through the VKontakte social network. Creates temporary tags to complete the OAuth process and redirects to a confirmation page.
HTTP-method: GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| state | ✅ | string | State from the VK OAuth request. Must contain the last 6 characters as the session ID. |
| code | ✅ | string | Authorization code received from VK after user confirmation. |
| device_id | ❌ | string | User's device identifier. |
| token | ✅ | string | Authentication API token |
Example Request
Example of a successful response
Failure response
``` { "code": "OAUTH_STATE_MISSING", "message": "no state" }
```
auth/whmcslogin¶
Performs login. Supports standard email/password authorization, as well as login via third-party services (Google, GitHub, VK) and automatic billing selection.
HTTP-method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: whmcslogin |
| token | ✅ | string | Authorization token |
| sso | ❌ | string | SSO method (google, github, vk) |
| sso_hash | ❌ | string | Hash/token for SSO authorization |
| user | ✅ | string | User email (for standard authorization) |
| password | ✅ | string | User password |
| location | ❌ | string | Specific billing (WHMCS location) |
Example Request
Example of a successful response
{
"result": "OK",
"module": "auth",
"action": "whmcslogin",
"token": "7bc29eb23fb1b879b21fce509597f07c",
"role": "Customer",
"role_type": "Customer",
"whmcs_id": 12345,
"whmcs_location": "US",
"permissions": [
"manage_products",
"show_invoices"
],
"token_expire": 1715865600,
"new": 1,
"country": "United States",
"country_code": "US",
"currency_code": "USD",
"vat": "",
"prebill": true,
"prebill_scope": "all",
"client_details": {
"account_id": 12345,
"email": "[email protected]",
"userid": 12345,
"billing": "US",
"currency_code": "USD",
"countrycode": "US",
"countryname": "United States"
},
"contact_id": 0,
"corporate": 0,
"verified": null,
"client_ip": "127.0.0.1",
"timing": []
}
Failure response
``` { "code": -2, "message": "Invalid credential" }