Checking whether an User can log into the WebTV
support, ws.webtv, api, users, log_in_check
GET vars specific to this request:
Var | Value | Description |
go | users | The API section |
do | log_in_check | The API action |
Resulting Request URL:
The resulting request URL would be similar to this (don't forget to append the required info: key, timestamp, salt and signature):
https://....../api.php?go=users&do=log_in_check&{required information}
The following POST vars are required.
Case 1 - Standard login:
Var | Value | Description |
login | (string) Username | [Up to 40 characters] Username (Login)... |
password | (string) Password | Password... |
ignore_concurrency | (int) 0|1 | Whether the system will perform the verification regarless of the User being already logged in. NOTE: This variable is available since WS.WebTV 2.3. |
Case 2 - External auth provider login (WS.WebTV 1.8.5+):
Var | Value | Description |
login | (string) "" | Empty string... |
password | (string) "" | Empty string... |
ext_auth | (int) 1 | Indicate that this is a login using an external auth provider. |
ext_provider | (string) auth_provider | Name of the auth provider. Available options: "twitter", "facebook", "oauth", "google", "openid" |
ext_user_id | (string) external_user_id | ID of the user, from the external auth provider. |
ext_token | (string) external_token | [Optional] If you have a token (for the user) from the external auth provider, provide it here. |
ext_secret | (string) external_sectret | [Optional] If you have a secret (for the user) from the external auth provider, provide it here. |
ip | (string) IP Address | When not provided, the WebTV will use the detected IP (the IP of the application) to log in the User. |
ignore_concurrency | (int) 0|1 | Whether the system will perform the verification regarless of the User being already logged in. NOTE: This variable is available since WS.WebTV 2.3. |
If the request was successful, you'll receive a response containing:
• ok: If the User can log in with the supplied Username and Password.
• id: The ID of the User.
Example:
{ "ok": "User can log in", "id": "2" }
If the request failed (for example, if the Username and/or Password are wrong or if the User already has an active session), you'll receive a response like the following:
{ "error": "LOG_IN_ERROR", "error_long": "Wrong login or password" }
Possible Error Messages
Besides the general errors, this request can return the following errors:
• REQUEST_ERROR | Login/Username cannot be blank
• REQUEST_ERROR | Password cannot be blank
• LOG_IN_ERROR | {Message}
User cannot log in because of the specified reason.
Preparing GET and POST data.
// The GET vars $GET_VARS = array( "go" => "users", "do" => "log_in_check" ); // The POST vars $POST_VARS = array( "login" => "john", "password" => "xyz123" );
Generating the salt, timestamp, signature and sending the request
*** The following code block is common to all signed requests ***
// Collect the API Base URL and Credential info $API_URL = "https://www.mywebtvdomain.tv/api.php"; $API_KEY_ID = "1b323a1cb879fd4e66530fbad07a32ee"; $API_SHARED_SECRET = "MWIzMjNhMWNiODc5ZmQ0ZTY2NTMwZmJhZDA3YTMyZWViOTQ3MDJiOGM2ZTU2NjE3"; // keep this safe!!! // Generating salt and timestamp $salt = md5(mt_rand()); $timestamp = time(); $signature = base64_encode(hash_hmac('sha256', $salt.$timestamp, $API_SHARED_SECRET, true)); // Generating the validation signature // - Default method: using base64_encode(hash_hmac(...)) $signature = base64_encode(hash_hmac('sha256', $salt.$timestamp, $API_SHARED_SECRET, true)); // comment this line if using the next method // - Simplified method - available since v60: using md5(). // This method requires the variable $API_SIGNATURE_GENERATION_MODE = 1; in the config/Config.inc.php file. // $signature = md5($salt."-".$timestamp."-".$API_SHARED_SECRET); // you must "uncomment" this line when using the simplified method // Append the timestamp, salt, key and signature to the GET vars $GET_VARS["timestamp"] = $timestamp; // UTC timestamp $GET_VARS["salt"] = $salt; $GET_VARS["key"] = $API_KEY_ID ; // The API Key ID: This is public and is used by the API to identify the application; $GET_VARS["signature"] = $signature; // Create the request URL. Please note that if you do not use PHP buit in function // to create the HTTP query then don't forget to URL encode the values $REQUEST_URL = $API_URL."?".http_build_query($GET_VARS); // The previous will build an URL like .../api.php?go=api_subject&do=api_action&etc... // Create a new cURL resource and set the appropriate options $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $REQUEST_URL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $POST_VARS); // If your PHP host does not have a valid SSL certificate, you will need to turn off SSL // Certificate Verification. This is dangerous (!), and should only be done temporarily // until a valid certificate has been installed curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Turns off verification of the SSL certificate. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Turns off verification of the SSL certificate. // Sending the request to the API $response = curl_exec($ch); // Processing the response if (!$response) { echo 'API call failed'; } else { print_r(json_decode($response,true)); }