Skip to content

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 Verifies the entered two-factor authentication code for the current user session.
2fa_resend resend 2FA code Sends a new two-factor authentication code to the linked channel (Email or SMS) for the current session.
billing_list get list of available billings Returns a list of available payment systems (billings) linked to the current session or available to the administrator.
email_check check email Validates the email, registers the customer in the system (if not found), and sends a verification code to the email address.
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 linked to a user token.
github_init initialize GitHub SSO Initiates the GitHub authorization process, generates a unique state, and returns the data required to redirect the user to the GitHub OAuth page.
github_signin authorize via GitHub Initiates the GitHub OAuth authorization process. Generates a temporary state and token for subsequent code-to-session exchange.
google_signin authorize via Google SSO Logs in using a Google ID Token. If the token is valid, it links the account to the user or updates the existing session.
info get token information Returns detailed information about the current user session, including role, permissions, customer data, and active servers.
ipalogin login via LDAP (IPA) Authenticates an employee via LDAP (IPA) with the option to link to a server.
login authorize by API key Authenticates a user via the provided API key, checking IP restrictions and linked servers. Returns a session token and a list of available servers.
logout logout from system Clears the current active access token of the user.
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 tags Creates or removes a tag for the customer. Allows setting values for various metadata (e.g., auto_credit).
tg_verify link Telegram username Links the user's Telegram username to their account (removing the old ID) and returns a link to the bot.
vk_init initialize VK OAuth Initiates the VK authorization process, generating parameters for the client side (code_challenge, state, and device_id).
vk_signin authorize via VK Initiates the authorization process through the VK social network, generating temporary data for OAuth2 (state, code_verifier) and saving it in the system.
whmcslogin authorize via WHMCS or SSO Logs into the system. Supports standard authentication (email/password) and SSO methods (Google, GitHub, VK). Upon successful login, returns a session token, user data, and permissions.

auth/2fa_check

Verifies the entered two-factor authentication code for the current user session.

HTTP-method: POST

Parameters:

Parameter Required Type Description
token string Authorization token
code[] string Two-factor authentication code (passed as an array)

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "token=HOSTKEY_TOKEN" \
--data "code[]=123456"
Example of a successful response
{
"result": "2FA OK"
}
Failure response

``` { "code": -1, "message": "Access denied by IP restrictions" }

```

auth/2fa_resend

Sends a new two-factor authentication code to the linked channel (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

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=2fa_resend" \
--data "token=HOSTKEY_TOKEN"
Example of a successful response
{
"result": "OK",
"message": "2FA token sent"
}
Failure response

``` { "code": -1, "message": "Unable to load authentication data, please try again" }

```

auth/billing_list

Returns a list of available payment systems (billings) linked to the current session or available to the administrator.

HTTP-method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: billing_list
token string User authorization token

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=billing_list"
Example of a successful response
{
"result": "OK",
"billings": [
{
"billing": "whmcs",
"company": "HostKey Global",
"active": 1,
"native_endpoint": "https://invapi.hostkey.com/auth.php"
}
]
}
Failure response

``` { "code": -2, "message": "Malformed request" }

```

auth/email_check

Validates the email, registers the customer in the system (if not found), and sends a verification code to the email address.

HTTP-method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: email_check
user_email string User email for verification and registration
location string Request source (e.g., whmcs)
user_token string User token (if required)

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": 400, "message": "Invalid email" }

```

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

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=flip_tag" \
--data "token=HOSTKEY_TOKEN" \
--data "tag=auto_credit"
Example of a successful response
{
"result": "OK",
"message": "auth/flip_tag: tag auto_credit created",
"action": "created"
}
Failure response

``` { "code": 0, "message": "TAG_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

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=get_log" \
--data "token=HOSTKEY_TOKEN"
Example of a successful response
{
"result": "OK",
"data": [
{
"id": 123,
"action": "login",
"ip": "1.2.3.4",
"time": "2024-01-15 10:00:00"
}
]
}
Failure response
{
"code": 404,
"message": "Log is empty"
}

auth/get_log_details

Returns detailed information about authentication events linked to a user token.

HTTP-method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: get_log_details
token string User session token
user_token string Additional token to retrieve logs for a specific user

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=get_log_details" \
--data "token=HOSTKEY_TOKEN"
Example of a successful response
{
"result": "OK",
"log": [
{
"event": "example_event",
"timestamp": "2024-05-20T10:30:00Z"
}
]
}
Failure response

``` { "code": 404, "message": "Invalid period or log is empty" }

```

auth/github_init

Initiates the GitHub authorization process, generates a unique state, and returns the data required to redirect the user to the GitHub OAuth page.

HTTP-method: POST|GET

Parameters:

Parameter Required Type Description
action string Method identifier: github_init
token string Session token (optional)

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=github_init"
Example of a successful response
{
"result": "OK",
"data": {
"client_id": "GITHUB_CLIENT_ID",
"redirect_uri": "GITHUB_REDIRECT_URI",
"state": "string (random state + 6 digits)"
},
"error_code": null
}
Failure response

``` { "code": -1, "message": "sso_github_unavailable" }

```

auth/github_signin

Initiates the GitHub OAuth authorization process. 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 for request authenticity verification.
token string Session token to link GitHub to an existing account.
code string Authorization code from GitHub.

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=github_signin" \
--data "state=VALUE" \
--data "code=VALUE"
Example of a successful response
{
"result": "OK",
"sso": "github",
"sso_hash": "string",
"error_code": null
}
Failure response

``` { "code": -1, "message": "sso_github_unavailable" }

```

auth/google_signin

Logs in using a Google ID Token. If the token is valid, it links the account to the user or updates the existing session.

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 Existing session token to link Google SSO to the current account

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=google_signin" \
--data "credential=VALUE"
Example of a successful response
{
"result": "OK",
"sso": "google",
"sso_hash": "eyJhbGciOiJSUzI1NiIs...",
"error_code": null,
"sso_set": 0
}
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 active servers.

HTTP-method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: info
token string Authorization token

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=info" \
--data "token=HOSTKEY_TOKEN"
Example of a successful response
{
"result": "OK",
"role": "Customer",
"role_name": "Customer",
"role_type": "Customer",
"whmcs_id": 12345,
"whmcs_location": "US",
"servers": [
101,
102
],
"customer_id": 5678,
"permissions": [
"manage_products",
"show_invoices"
],
"token_expire": 1735689600,
"new": 1,
"prebill": true,
"prebill_scope": "all",
"email": "[email protected]",
"client_ip": "192.168.1.1",
"corporate": 0,
"verified": null,
"sumsub_id": null,
"sumsub_comment": null,
"default_lang": "en",
"private_ranges": [],
"private_vlans": [],
"billing_options": {},
"has_product_subscription": false,
"deploy_keys": [],
"prebill_pending": []
}
Failure response

``` { "code": -2, "message": "Invalid token" }

```

auth/login

Authenticates a user via the provided API key, checking IP restrictions and linked servers. Returns a session token and a list of available servers.

HTTP-method: POST

Parameters:

Parameter Required Type Description
key string User API key
ttl integer Token lifetime in seconds (default 3600)
base string Base URL for invapi

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=login" \
--data "key=VALUE"
Example of a successful response
{
"token": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
"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": 1715856000,
"new": 1,
"prebill": true,
"prebill_scope": "all",
"prebill_global": true,
"billing_options": {
"location": "US",
"company": "Hostkey"
}
}
Failure response

``` { "code": -1, "message": "API key is empty" }

```

auth/logout

Clears the current active access token of the user.

HTTP-method: POST

Parameters:

Parameter Required Type Description
token string Active session token

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "token=HOSTKEY_TOKEN"
Example of a successful response
{
"result": "OK",
"message": "access token cleared"
}
Failure response

``` { "-2": { "code": "TOKEN_REQUIRED", "message": "Token is not specified" }, "-1": { "code": "INVALID_TOKEN", "message": "Invalid token" } }

```

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
action string Method identifier: session_reset
token string Authorization token to perform the action
user_email string User email for session reset
reset_token string Special reset token (hash of token + RESET_TOKEN_SECRET)
confirm int Action confirmation flag (1 to execute)

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=session_reset" \
--data "token=HOSTKEY_TOKEN" \
--data "user_email=VALUE" \
--data "reset_token=VALUE"
Example of a successful response
{
"result": "OK"
}
Failure response

``` { "code": -2, "message": "Malformed request" }

```

auth/set_tag

Creates or removes a tag for the customer. Allows setting values for various metadata (e.g., auto_credit).

HTTP-method: POST

Parameters:

Parameter Required Type Description
tag string Tag name. For customers, only 'auto_credit' is allowed
set boolean Set value (1) or remove tag (0)
token string Authentication API token

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=set_tag" \
--data "tag=auto_credit" \
--data "set=1" \
--data "token=HOSTKEY_TOKEN"
Example of a successful response
{
"result": "OK",
"message": "tag [name] created/removed",
"action": "set|unset",
"error_code": null
}
Failure response

`` { "TAG_MISSING": { "code": -2, "message": "tag is missing" }, "VALUE_MISSING": { "code": -2, "message": "set is missing" }, "TAG_TOO_LONG": { "code": -2, "message": "tag too long (32 max)" }, "TAG_INVALID": { "code": -2, "message": "invalid tag (onlyauto_credit` is allowed)" }, "NO_CUSTOMER_ID": { "code": -2, "message": "no customer_id tags were found" } }

```

auth/tg_verify

Links the user's Telegram username to their account (removing the old ID) and returns a link to the bot.

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

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=tg_verify" \
--data "token=HOSTKEY_TOKEN" \
--data "tg_username=VALUE"
Example of a successful response
{
"result": "OK",
"bot_url": "https://t.me/example_bot"
}
Failure response

``` { "code": -1, "message": "Illegal TG username" }

```

auth/vk_init

Initiates the VK authorization process, generating parameters for the client side (code_challenge, state, and device_id).

HTTP-method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: vk_init
token string Existing session token (if any)

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=vk_init"
Example of a successful response
{
"result": "OK",
"data": {
"client_id": "1234567890",
"redirect_uri": "https://hostkey.com/callback",
"code_challenge": "E_XampleChallengeString",
"device_id": "aBcdEfGhIjKlMnOpQrStUvWxYz123456",
"state": "random_state_string_abcde"
}
}
Failure response

``` { "code": -2, "message": "Malformed request" }

```

auth/vk_signin

Initiates the authorization process through the VK social network, generating temporary data for OAuth2 (state, code_verifier) and saving it in the system.

HTTP-method: GET

Parameters:

Parameter Required Type Description
action string Method identifier: vk_signin
state string OAuth request state (contains last 6 characters of ID)
code string Authorization code from VK
device_id string Device identifier
token string Authentication API token

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X GET \
--data "action=vk_signin" \
--data "state=VALUE" \
--data "code=VALUE" \
--data "token=HOSTKEY_TOKEN"
Example of a successful response
{
"result": "OK",
"data": {
"client_id": "VK_CLIENT_ID_VALUE",
"redirect_uri": "https://vk.com/oauth2/auth",
"code_challenge": "E9f8a7b6c5d4e3f2g1h0",
"device_id": "random_device_string",
"state": "random_state_string"
}
}
Failure response

``` { "code": -1, "message": "Invalid host header" }

```

auth/whmcslogin

Logs into the system. Supports standard authentication (email/password) and SSO methods (Google, GitHub, VK). Upon successful login, returns a session token, user data, and permissions.

HTTP-method: POST

Parameters:

Parameter Required Type Description
user string User email (for standard login)
password string User password
token string Authorization token for session verification
sso string SSO method (google, github, vk)
sso_hash string Hash or token for SSO authorization

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "user=VALUE" \
--data "password=VALUE"
Example of a successful response
{
"token": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a7b8c9d0",
"role": "Customer",
"role_type": "Customer",
"whmcs_id": 12345,
"whmcs_location": "US",
"permissions": [
"manage_products",
"show_invoices"
],
"token_expire": 1715865600,
"new": 1,
"country": "USA",
"country_code": "US",
"currency_code": "USD",
"vat": "",
"prebill": true,
"prebill_scope": "all",
"prebill_global": true,
"client_data": {
"account_id": 12345,
"email": "[email protected]",
"countrycode": "US",
"currency_code": "USD"
}
}
Failure response

``` { "code": -2, "message": "Invalid service" }

question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×