]> git.mxchange.org Git - friendica.git/blob - src/Network/FKOAuth1.php
Move Cookie to own class (with tests)
[friendica.git] / src / Network / FKOAuth1.php
1 <?php
2 /**
3  * @file src/Network/FKOAuth1.php
4  */
5 namespace Friendica\Network;
6
7 use Friendica\BaseObject;
8 use Friendica\App\Authentication;
9 use Friendica\Core\Logger;
10 use Friendica\Core\Session;
11 use Friendica\Database\DBA;
12 use OAuthServer;
13 use OAuthSignatureMethod_HMAC_SHA1;
14 use OAuthSignatureMethod_PLAINTEXT;
15
16 /**
17  * @brief OAuth protocol
18  */
19 class FKOAuth1 extends OAuthServer
20 {
21         /**
22          * @brief Constructor
23          */
24         public function __construct()
25         {
26                 parent::__construct(new FKOAuthDataStore());
27                 $this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
28                 $this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
29         }
30
31         /**
32          * @param string $uid user id
33          * @return void
34          * @throws HTTPException\ForbiddenException
35          * @throws HTTPException\InternalServerErrorException
36          */
37         public function loginUser($uid)
38         {
39                 Logger::log("FKOAuth1::loginUser $uid");
40                 $a = BaseObject::getApp();
41                 $record = DBA::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
42
43                 if (!DBA::isResult($record)) {
44                         Logger::log('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), Logger::DEBUG);
45                         header('HTTP/1.0 401 Unauthorized');
46                         die('This api requires login');
47                 }
48
49                 /** @var Authentication $authentication */
50                 $authentication = BaseObject::getClass(Authentication::class);
51                 $authentication->setForUser($a, $record, true);
52         }
53 }