friendica/src/Network/FKOAuth1.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2017-12-04 20:09:23 +01:00
<?php
/**
2018-01-31 05:29:05 +01:00
* @file src/Network/FKOAuth1.php
2017-12-04 20:09:23 +01:00
*/
namespace Friendica\Network;
2017-12-04 20:09:23 +01:00
use Friendica\BaseObject;
2018-10-29 22:20:46 +01:00
use Friendica\Core\Logger;
use Friendica\Core\Session;
use Friendica\Database\DBA;
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
/**
* @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());
}
/**
* @param string $uid user id
* @return void
* @throws HTTPException\ForbiddenException
2019-01-06 22:06:53 +01:00
* @throws HTTPException\InternalServerErrorException
*/
2017-12-05 03:03:39 +01:00
public function loginUser($uid)
2017-12-04 20:09:23 +01:00
{
2018-10-29 22:20:46 +01:00
Logger::log("FKOAuth1::loginUser $uid");
$a = BaseObject::getApp();
$record = DBA::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
2018-07-21 14:46:04 +02:00
if (!DBA::isResult($record)) {
Logger::log('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), Logger::DEBUG);
header('HTTP/1.0 401 Unauthorized');
die('This api requires login');
2017-12-04 20:09:23 +01:00
}
Session::setAuthenticatedForUser($a, $record, true);
2017-12-04 20:09:23 +01:00
}
}