]> git.mxchange.org Git - friendica.git/blob - src/Network/FKOAuth1.php
Merge remote-tracking branch 'upstream/develop' into aria
[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\Core\Logger;
9 use Friendica\Core\Session;
10 use Friendica\Database\DBA;
11 use OAuthServer;
12 use OAuthSignatureMethod_HMAC_SHA1;
13 use OAuthSignatureMethod_PLAINTEXT;
14
15 /**
16  * @brief OAuth protocol
17  */
18 class FKOAuth1 extends OAuthServer
19 {
20         /**
21          * @brief Constructor
22          */
23         public function __construct()
24         {
25                 parent::__construct(new FKOAuthDataStore());
26                 $this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
27                 $this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
28         }
29
30         /**
31          * @param string $uid user id
32          * @return void
33          * @throws HTTPException\ForbiddenException
34          * @throws HTTPException\InternalServerErrorException
35          */
36         public function loginUser($uid)
37         {
38                 Logger::log("FKOAuth1::loginUser $uid");
39                 $a = BaseObject::getApp();
40                 $record = DBA::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]);
41
42                 if (!DBA::isResult($record)) {
43                         Logger::log('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), Logger::DEBUG);
44                         header('HTTP/1.0 401 Unauthorized');
45                         die('This api requires login');
46                 }
47
48                 Session::setAuthenticatedForUser($a, $record, true);
49         }
50 }