OAuth2.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. declare(strict_types = 1);
  3. // {{{ License
  4. // This file is part of GNU social - https://www.gnu.org/software/social
  5. //
  6. // GNU social is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // GNU social is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  18. // }}}
  19. /**
  20. * ActivityPub implementation for GNU social
  21. *
  22. * @package OAuth2
  23. * @category API
  24. *
  25. * @author Diogo Peralta Cordeiro <@diogo.site>
  26. * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
  27. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  28. */
  29. namespace Plugin\IndieAuth\Controller;
  30. use App\Core\Controller;
  31. use Nyholm\Psr7\Factory\Psr17Factory;
  32. use Plugin\IndieAuth\IndieAuth;
  33. use Psr\Http\Message\ResponseInterface;
  34. use Psr\Http\Message\ServerRequestInterface;
  35. use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
  36. use Symfony\Component\HttpFoundation\RequestStack;
  37. /**
  38. * App Management Endpoint
  39. *
  40. * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
  41. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  42. */
  43. class OAuth2 extends Controller
  44. {
  45. private ServerRequestInterface $psrRequest;
  46. public function __construct(RequestStack $requestStack)
  47. {
  48. parent::__construct($requestStack);
  49. $psr17Factory = new Psr17Factory();
  50. $psrHttpFactory = new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);
  51. $this->psrRequest = $psrHttpFactory->createRequest($this->request);
  52. }
  53. public function handleAuthorizationEndpointRequest(): ResponseInterface
  54. {
  55. return IndieAuth::$server->handleAuthorizationEndpointRequest($this->psrRequest);
  56. }
  57. public function handleTokenEndpointRequest(): ResponseInterface
  58. {
  59. return IndieAuth::$server->handleTokenEndpointRequest($this->psrRequest);
  60. }
  61. }