Allow API key to be used instead of password for API
This commit is contained in:
parent
a41eea4cff
commit
432cf39b8c
2
api.php
2
api.php
@ -19,7 +19,7 @@ header("Content-Type: application/json");
|
|||||||
|
|
||||||
$username = $VARS['username'];
|
$username = $VARS['username'];
|
||||||
$password = $VARS['password'];
|
$password = $VARS['password'];
|
||||||
if (user_exists($username) !== true || authenticate_user($username, $password, $errmsg) !== true) {
|
if (user_exists($username) !== true || (authenticate_user($username, $password, $errmsg) !== true && checkAPIKey($password) !== true)) {
|
||||||
header("HTTP/1.1 403 Unauthorized");
|
header("HTTP/1.1 403 Unauthorized");
|
||||||
die("\"403 Unauthorized\"");
|
die("\"403 Unauthorized\"");
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,34 @@ function checkLoginServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given AccountHub API key is valid by attempting to
|
||||||
|
* access the API with it.
|
||||||
|
* @param String $key The API key to check
|
||||||
|
* @return boolean TRUE if the key is valid, FALSE if invalid or something went wrong
|
||||||
|
*/
|
||||||
|
function checkAPIKey($key) {
|
||||||
|
try {
|
||||||
|
$client = new GuzzleHttp\Client();
|
||||||
|
|
||||||
|
$response = $client
|
||||||
|
->request('POST', PORTAL_API, [
|
||||||
|
'form_params' => [
|
||||||
|
'key' => $key,
|
||||||
|
'action' => "ping"
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($response->getStatusCode() === 200) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Account handling //
|
// Account handling //
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user