Անցնել պարունակությանը

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 client 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 linked channel (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 client exists by email in the specified billing location. If the client is not found, a new one is created. Also sends a verification code to the email.
flip_tag toggle tag Allows toggling the state (create or delete) of a specified tag for the client. If the tag already exists, it will be deleted; if it does not exist, it will be created.
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 by user token
github_init initialize GitHub SSO Initiates the authorization process via GitHub, generates a unique state, and returns the necessary data to redirect the user to the GitHub OAuth page.
github_signin initialize GitHub login Initiates the OAuth authorization process via GitHub. Generates a temporary state and returns client data for user redirection.
google_signin Google SSO login Performs user authentication using a Google ID Token. If the token is valid, it links the Google account to the current session or connects it to an existing client.
info get token information Returns detailed information about the current user session, including role, permissions, client data, and active servers.
ipalogin LDAP (IPA) login Employee authorization via LDAP (IPA) with the possibility of server binding.
login API key login User authorization using an API key. Returns an access token, role information, and a list of available servers.
logout logout from system Clears the current user access token, ending the session.
session_reset reset session Terminates all active user sessions based on their email and reset token. Performs tag purging for all found hashes.
set_tag manage user tag Creates or deletes a tag for the client. If the set parameter is 1, the tag is created; if 0, it is deleted.
tg_verify bind Telegram username Binds the specified Telegram username to the user account and returns a link to the bot. Deletes the old tg_user_id tag.
vk_init initialize VK authorization Initiates the OAuth authorization process via VK, generates a code_challenge, and returns the necessary data for user redirect.
vk_signin VK authorization Initiates the authorization process through the VKontakte social network. Generates temporary data (state, code_verifier) and saves it in temporary storage for subsequent verification when the user returns.
whmcslogin WHMCS or SSO authorization Performs system 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 Active session token
code string Two-factor authentication code (passed via user_token in the verification logic)

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=2fa_check" \
--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

Resends the two-factor authentication code to the linked channel (email or SMS) for the current session.

HTTP-method: POST

Parameters:

Parameter Required Type Description
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 "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) configured for the current user or administrator.

HTTP-method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: billing_list
token string Session 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": [
{
"location": "EU-Central",
"company": "Hostkey Global",
"active": 1,
"url": "https://hostkey.com",
"admin_url": "https://hostkey.com/admin",
"allowed_endpoints": [
"login",
"register"
],
"PAYPAL_ID": "PAY-123456789"
},
{
"location": "EU-Central",
"company": "Hostkey Global",
"active": 1,
"url": "https://hostkey.com",
"admin_url": "https://hostkey.com/admin",
"allowed_endpoints": [
"login"
],
"PAYPAL_ID": null
}
]
}
Failure response

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

```

auth/email_check

Checks if a client exists by email in the specified billing location. If the client is not found, a new one is created. Also 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 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": 0, "message": "Invalid email or billing location error" }

```

auth/flip_tag

Allows toggling the state (create or delete) of a specified tag for the client. If the tag already exists, it will be deleted; if it does not exist, it will be created.

HTTP-method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: flip_tag
token string Session authorization token
tag string Tag name to toggle (e.g., 'auto_credit')

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": "$module/$action: tag $tag created",
"action": "created"
}
Failure response

``` { "code": "TAG_MISSING", "message": "\(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 Period start (YYYY-MM-DD)
period_stop string Period end (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 by user token.

HTTP-method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: get_log_details
token string Session token to get log details

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",
"action": "get_log_details",
"log": [
{
"event": "login_attempt",
"timestamp": "2024-05-20T10:30:00Z",
"ip": "192.168.1.1",
"status": "success"
}
]
}
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 the necessary data to redirect the user to the GitHub OAuth page.

HTTP-method: POST

Parameters:

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

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 OAuth authorization process via GitHub. Generates a temporary state and returns client data for user redirection.

HTTP-method: POST|GET

Parameters:

Parameter Required Type Description
action string Method identifier: github_signin
state string OAuth state to verify request validity
token string Session token to bind GitHub account to the current user
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",
"data": {
"client_id": "string",
"redirect_uri": "string",
"state": "string"
},
"error_code": null,
"sso": "github"
}
Failure response

``` { "result": "error", "message": "no state", "error_code": "OAUTH_STATE_MISSING" }

```

auth/google_signin

Performs user authentication using a Google ID Token. If the token is valid, it links the Google account to the current session or connects it to an existing client.

HTTP-method: POST

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 bind the Google account to the current user

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": "\(module/google_signin: credential is missing", "error_code": "MISSING_CREDENTIAL" }, "INVALID_CREDENTIAL": { "result": "error", "message": "\)module/google_signin: invalid credential", "error_code": "INVALID_CREDENTIAL" } }

```

auth/info

Returns detailed information about the current user session, including role, permissions, client 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

User authorization using an API key. Returns an access token, role information, and a list of available servers.

HTTP-method: POST

Parameters:

Parameter Required Type Description
key string API key for authorization
ttl int Token lifetime in seconds (default 3600)

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=login" \
--data "key=VALUE"
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

Clears the current user access token, ending the session.

HTTP-method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: logout
token string Access token to end the session

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=logout" \
--data "token=HOSTKEY_TOKEN"
Example of a successful response
{
"result": "OK",
"message": "access token cleared"
}
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 tag purging for all found hashes.

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 reset_token)
confirm integer Action confirmation flag (1 to execute)

Example Request

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--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 deletes a tag for the client. If the set parameter is 1, the tag is created; if 0, it is deleted.

HTTP-method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: set_tag
tag string Tag name (maximum 32 characters). For clients, only 'auto_credit' is allowed
set integer Action: 1 to create the tag, 0 to delete
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 auto_credit created",
"action": "set"
}
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 specified Telegram username to the user account and returns a link to the bot. Deletes the old tg_user_id tag.

HTTP-method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: tg_verify
token string Session authorization token
tg_username string Telegram username to bind

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/your_bot_link"
}
Failure response

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

```

auth/vk_init

Initiates the OAuth authorization process via VK, generates a code_challenge, and returns the necessary data for user redirect.

HTTP-method: POST|GET

Parameters:

Parameter Required Type Description
action string Method identifier: vk_init
token string Session token (from \(_POST/\)_GET)
state string OAuth authorization state

Example Request

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

``` { "result": -1, "error": "SSO_UNAVAILABLE", "message": "sso_github_unavailable" }

```

auth/vk_signin

Initiates the authorization process through the VKontakte social network. Generates temporary data (state, code_verifier) and saves it in temporary storage for subsequent verification when the user returns.

HTTP-method: GET

Parameters:

Parameter Required Type Description
action string Action (automatically determined as vk_signin if device parameters are present)
state string OAuth request state for CSRF protection. Accepts value in format state[]=val1&state[]=val2
code string Authorization code received from VK after user confirmation
device_id string User 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[]=val1" \
--data "code=AUTH_CODE" \
--data "token=YOUR_TOKEN"
Example of a successful response
{
"result": "OK",
"data": {
"client_id": "VK_CLIENT_ID_VALUE",
"redirect_uri": "https://vk.com/oauth2/auto_auth",
"code_challenge": "E9xy...base64url",
"device_id": "random_string_24",
"state": "random_string_30"
}
}
Failure response

``` { "INVALID_HOST_HEADER": { "result": "error", "message": "Invalid host header", "code": "INVALID_HOST_HEADER" }, "ERROR_VK_REQUEST": { "result": "error", "message": "Error occurs when querying VK", "code": "ERROR_VK_REQUEST" }, "ERROR_FETCH_VK_USER": { "result": "error", "message": "Authorized, but unable to get VK user", "code": "ERROR_FETCH_VK_USER" }, "OAUTH_STATE_MISMATCH": { "result": "error", "message": "Incorrect state", "code": "OAUTH_STATE_MISMATCH" }, "OAUTH_STATE_MISSING": { "result": "error", "message": "No state", "code": "OAUTH_STATE_MISSING" }, "OAUTH_CODE_VERIFIER_MISSING": { "result": "error", "message": "No code_verifier", "code": "OAUTH_CODE_VERIFIER_MISSING" } }

```

auth/whmcslogin

Performs system 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

curl -s "https://invapi.hostkey.com/auth.php" -X POST \
--data "action=whmcslogin" \
--data "token=HOSTKEY_TOKEN" \
--data "user=VALUE" \
--data "password=VALUE"
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" }

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