friendica/src/Security/FKOAuth1.php

67 lines
2.0 KiB
PHP
Raw Normal View History

2017-12-04 14:09:23 -05:00
<?php
/**
2021-03-29 02:40:20 -04:00
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @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 14:09:23 -05:00
*/
namespace Friendica\Security;
2017-12-04 14:09:23 -05:00
2018-10-29 17:20:46 -04:00
use Friendica\Core\Logger;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Security\OAuth1\OAuthServer;
2020-09-30 05:26:52 -04:00
use Friendica\Security\OAuth1\Signature\OAuthSignatureMethod_HMAC_SHA1;
use Friendica\Security\OAuth1\Signature\OAuthSignatureMethod_PLAINTEXT;
2017-12-04 14:09:23 -05:00
/**
2020-01-19 01:05:23 -05:00
* OAuth protocol
2017-12-04 14:09:23 -05:00
*/
class FKOAuth1 extends OAuthServer
{
/**
2020-01-19 01:05:23 -05:00
* Constructor
2017-12-04 14:09:23 -05:00
*/
public function __construct()
{
parent::__construct(new FKOAuthDataStore());
$this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
$this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
}
/**
* @param string $uid user id
* @return void
* @throws HTTPException\ForbiddenException
2019-01-06 16:06:53 -05:00
* @throws HTTPException\InternalServerErrorException
*/
2017-12-04 21:03:39 -05:00
public function loginUser($uid)
2017-12-04 14:09:23 -05:00
{
Logger::notice("FKOAuth1::loginUser $uid");
$a = DI::app();
$record = DBA::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
2020-11-19 12:19:14 -05:00
if (!DBA::isResult($record) || empty($uid)) {
Logger::info('FKOAuth1::loginUser failure', ['server' => $_SERVER]);
header('HTTP/1.0 401 Unauthorized');
die('This api requires login');
2017-12-04 14:09:23 -05:00
}
DI::auth()->setForUser($a, $record, true);
2017-12-04 14:09:23 -05:00
}
}