2017-12-04 19:09:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2018-01-31 04:29:05 +00:00
|
|
|
* @file src/Network/FKOAuth1.php
|
2017-12-04 19:09:23 +00:00
|
|
|
*/
|
2017-12-04 20:59:21 +00:00
|
|
|
namespace Friendica\Network;
|
2017-12-04 19:09:23 +00:00
|
|
|
|
2019-10-06 15:17:30 +00:00
|
|
|
use Friendica\BaseObject;
|
2018-10-29 21:20:46 +00:00
|
|
|
use Friendica\Core\Logger;
|
2019-10-06 15:17:30 +00:00
|
|
|
use Friendica\Core\Session;
|
2018-07-20 12:19:26 +00:00
|
|
|
use Friendica\Database\DBA;
|
2017-12-05 01:30:10 +00:00
|
|
|
use OAuthServer;
|
2017-12-05 02:18:48 +00:00
|
|
|
use OAuthSignatureMethod_HMAC_SHA1;
|
2018-01-31 04:29:05 +00:00
|
|
|
use OAuthSignatureMethod_PLAINTEXT;
|
2017-12-04 19:09:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief OAuth protocol
|
|
|
|
*/
|
|
|
|
class FKOAuth1 extends OAuthServer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @brief Constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct(new FKOAuthDataStore());
|
|
|
|
$this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
|
|
|
|
$this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
|
|
|
|
}
|
|
|
|
|
2017-12-04 19:52:04 +00:00
|
|
|
/**
|
|
|
|
* @param string $uid user id
|
|
|
|
* @return void
|
2019-10-06 15:17:30 +00:00
|
|
|
* @throws HTTPException\ForbiddenException
|
2019-01-06 21:06:53 +00:00
|
|
|
* @throws HTTPException\InternalServerErrorException
|
2017-12-04 19:52:04 +00:00
|
|
|
*/
|
2017-12-05 02:03:39 +00:00
|
|
|
public function loginUser($uid)
|
2017-12-04 19:09:23 +00:00
|
|
|
{
|
2018-10-29 21:20:46 +00:00
|
|
|
Logger::log("FKOAuth1::loginUser $uid");
|
2019-10-06 15:17:30 +00:00
|
|
|
$a = BaseObject::getApp();
|
2018-07-20 12:19:26 +00:00
|
|
|
$record = DBA::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
|
2017-12-04 19:52:04 +00:00
|
|
|
|
2018-07-21 12:46:04 +00:00
|
|
|
if (!DBA::isResult($record)) {
|
2018-10-30 13:58:45 +00:00
|
|
|
Logger::log('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), Logger::DEBUG);
|
2017-12-04 19:52:04 +00:00
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
|
die('This api requires login');
|
2017-12-04 19:09:23 +00:00
|
|
|
}
|
|
|
|
|
2019-10-06 15:17:30 +00:00
|
|
|
Session::setAuthenticatedForUser($a, $record, true);
|
2017-12-04 19:09:23 +00:00
|
|
|
}
|
|
|
|
}
|