Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2KB

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