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