2017-12-04 14:09:23 -05:00
|
|
|
<?php
|
|
|
|
/**
|
2018-01-30 23:29:05 -05:00
|
|
|
* @file src/Network/FKOAuth1.php
|
2017-12-04 14:09:23 -05:00
|
|
|
*/
|
2017-12-04 15:59:21 -05:00
|
|
|
namespace Friendica\Network;
|
2017-12-04 14:09:23 -05:00
|
|
|
|
2019-10-06 11:17:30 -04:00
|
|
|
use Friendica\BaseObject;
|
2019-12-08 16:45:34 -05:00
|
|
|
use Friendica\App\Authentication;
|
2018-10-29 17:20:46 -04:00
|
|
|
use Friendica\Core\Logger;
|
2019-10-06 11:17:30 -04:00
|
|
|
use Friendica\Core\Session;
|
2018-07-20 08:19:26 -04:00
|
|
|
use Friendica\Database\DBA;
|
2019-12-15 16:34:11 -05:00
|
|
|
use Friendica\DI;
|
2017-12-04 20:30:10 -05:00
|
|
|
use OAuthServer;
|
2017-12-04 21:18:48 -05:00
|
|
|
use OAuthSignatureMethod_HMAC_SHA1;
|
2018-01-30 23:29:05 -05:00
|
|
|
use OAuthSignatureMethod_PLAINTEXT;
|
2017-12-04 14:09:23 -05: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 14:52:04 -05:00
|
|
|
/**
|
|
|
|
* @param string $uid user id
|
|
|
|
* @return void
|
2019-10-06 11:17:30 -04:00
|
|
|
* @throws HTTPException\ForbiddenException
|
2019-01-06 16:06:53 -05:00
|
|
|
* @throws HTTPException\InternalServerErrorException
|
2017-12-04 14:52:04 -05:00
|
|
|
*/
|
2017-12-04 21:03:39 -05:00
|
|
|
public function loginUser($uid)
|
2017-12-04 14:09:23 -05:00
|
|
|
{
|
2018-10-29 17:20:46 -04:00
|
|
|
Logger::log("FKOAuth1::loginUser $uid");
|
2019-12-15 16:34:11 -05:00
|
|
|
$a = DI::app();
|
2018-07-20 08:19:26 -04:00
|
|
|
$record = DBA::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
|
2017-12-04 14:52:04 -05:00
|
|
|
|
2018-07-21 08:46:04 -04:00
|
|
|
if (!DBA::isResult($record)) {
|
2018-10-30 09:58:45 -04:00
|
|
|
Logger::log('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), Logger::DEBUG);
|
2017-12-04 14:52:04 -05:00
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
|
die('This api requires login');
|
2017-12-04 14:09:23 -05:00
|
|
|
}
|
|
|
|
|
2019-12-03 16:29:37 -05:00
|
|
|
/** @var Authentication $authentication */
|
|
|
|
$authentication = BaseObject::getClass(Authentication::class);
|
|
|
|
$authentication->setForUser($a, $record, true);
|
2017-12-04 14:09:23 -05:00
|
|
|
}
|
|
|
|
}
|