2017-12-04 20:09:23 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-02-09 16:18:46 +01:00
|
|
|
* @copyright Copyright (C) 2020, Friendica
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
2017-12-04 20:09:23 +01:00
|
|
|
*/
|
2020-02-09 16:18:46 +01:00
|
|
|
|
2017-12-04 21:59:21 +01:00
|
|
|
namespace Friendica\Network;
|
2017-12-04 20:09:23 +01:00
|
|
|
|
2018-10-29 22:20:46 +01:00
|
|
|
use Friendica\Core\Logger;
|
2018-07-20 14:19:26 +02:00
|
|
|
use Friendica\Database\DBA;
|
2019-12-15 22:34:11 +01:00
|
|
|
use Friendica\DI;
|
2017-12-05 02:30:10 +01:00
|
|
|
use OAuthServer;
|
2017-12-05 03:18:48 +01:00
|
|
|
use OAuthSignatureMethod_HMAC_SHA1;
|
2018-01-31 05:29:05 +01:00
|
|
|
use OAuthSignatureMethod_PLAINTEXT;
|
2017-12-04 20:09:23 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-19 07:05:23 +01:00
|
|
|
* OAuth protocol
|
2017-12-04 20:09:23 +01:00
|
|
|
*/
|
|
|
|
class FKOAuth1 extends OAuthServer
|
|
|
|
{
|
|
|
|
/**
|
2020-01-19 07:05:23 +01:00
|
|
|
* Constructor
|
2017-12-04 20:09:23 +01:00
|
|
|
*/
|
|
|
|
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 20:52:04 +01:00
|
|
|
/**
|
|
|
|
* @param string $uid user id
|
|
|
|
* @return void
|
2019-10-06 17:17:30 +02:00
|
|
|
* @throws HTTPException\ForbiddenException
|
2019-01-06 22:06:53 +01:00
|
|
|
* @throws HTTPException\InternalServerErrorException
|
2017-12-04 20:52:04 +01:00
|
|
|
*/
|
2017-12-05 03:03:39 +01:00
|
|
|
public function loginUser($uid)
|
2017-12-04 20:09:23 +01:00
|
|
|
{
|
2020-06-29 22:22:00 +02:00
|
|
|
Logger::notice("FKOAuth1::loginUser $uid");
|
2019-12-15 22:34:11 +01:00
|
|
|
$a = DI::app();
|
2018-07-20 14:19:26 +02:00
|
|
|
$record = DBA::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
|
2017-12-04 20:52:04 +01:00
|
|
|
|
2018-07-21 14:46:04 +02:00
|
|
|
if (!DBA::isResult($record)) {
|
2020-06-29 22:22:00 +02:00
|
|
|
Logger::info('FKOAuth1::loginUser failure', ['server' => $_SERVER]);
|
2017-12-04 20:52:04 +01:00
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
|
die('This api requires login');
|
2017-12-04 20:09:23 +01:00
|
|
|
}
|
|
|
|
|
2019-12-15 23:28:01 +01:00
|
|
|
DI::auth()->setForUser($a, $record, true);
|
2017-12-04 20:09:23 +01:00
|
|
|
}
|
|
|
|
}
|