Switch to format json

This commit is contained in:
Artem Vasilev 2024-03-12 11:57:28 +03:00
parent f01b5f8fd7
commit 34289ae0e2

View File

@ -22,57 +22,61 @@ use Joomla\Event\SubscriberInterface;
class Plugin extends CMSPlugin implements SubscriberInterface class Plugin extends CMSPlugin implements SubscriberInterface
{ {
public static function getSubscribedEvents(): array public static function getSubscribedEvents(): array
{ {
return ['onAfterInitialise' => 'attachOauthRouter']; return ['onAfterInitialise' => 'attachOauthRouter'];
} }
/** /**
* @return void * @return void
* @since version * @since version
*/ */
public function attachOauthRouter(): void public function attachOauthRouter(): void
{ {
/** @var \Joomla\CMS\Application\SiteApplication $app */ /** @var \Joomla\CMS\Application\SiteApplication $app */
$app = $this->getApplication(); $app = $this->getApplication();
if (!$app->isClient('site')) if (!$app->isClient('site'))
{ {
return; return;
} }
/** @var \Joomla\CMS\Router\SiteRouter $siteRouter */ /** @var \Joomla\CMS\Router\SiteRouter $siteRouter */
$siteRouter = Factory::getContainer()->get(SiteRouter::class); $siteRouter = Factory::getContainer()->get(SiteRouter::class);
$siteRouter->attachParseRule([$this, 'parseOauthRoute'], $siteRouter::PROCESS_BEFORE); $siteRouter->attachParseRule([$this, 'parseOauthRoute'], $siteRouter::PROCESS_BEFORE);
} }
/** /**
* @param \Joomla\CMS\Router\SiteRouter $router * @param \Joomla\CMS\Router\SiteRouter $router
* @param \Joomla\CMS\Uri\Uri $uri * @param \Joomla\CMS\Uri\Uri $uri
* *
* @return void * @return void
* @since version * @since version
*/ */
public function parseOauthRoute(SiteRouter &$router, Uri &$uri): void public function parseOauthRoute(SiteRouter &$router, Uri &$uri): void
{ {
$route = trim($uri->getPath(), '/'); $route = trim($uri->getPath(), '/');
if (empty($route)) if (empty($route))
{ {
return; return;
} }
if (!str_starts_with($route, 'login/oauth')) if (!str_starts_with($route, 'login/oauth'))
{ {
return; return;
} }
$segments = explode('/', $route); $segments = explode('/', $route);
$uri->setVar('option', 'com_oauthserver'); $uri->setVar('option', 'com_oauthserver');
$uri->setVar('task', 'login.' . $segments[2]); $uri->setVar('task', 'login.' . $segments[2]);
$uri->setVar('view', 'default'); if ($segments[2] !== 'authorize')
{
$uri->setVar('format', 'json');
}
$uri->setVar('view', 'default');
$uri->setPath(''); $uri->setPath('');
} }
} }