diff --git a/src/OAuth2/OAuth2Routes.php b/src/OAuth2/OAuth2Routes.php index 04f9679..2c94188 100644 --- a/src/OAuth2/OAuth2Routes.php +++ b/src/OAuth2/OAuth2Routes.php @@ -4,6 +4,7 @@ namespace Syokuhou\OAuth2; use RuntimeException; use Syokuhou\SyokuhouContext; use Syokuhou\RpcModels\Hanyuu\{OAuth2AuthInfo,OAuth2RfcModel}; +use Index\Config\Config; use Index\Http\Routing\{HandlerAttribute,HttpGet,HttpOptions,HttpPost,Router,RouteHandler,RouteHandlerTrait}; class OAuth2Routes implements RouteHandler { @@ -15,7 +16,8 @@ class OAuth2Routes implements RouteHandler { ]; public function __construct( - private SyokuhouContext $ctx + private SyokuhouContext $ctx, + private Config $config ) {} public function registerRoutes(Router $router): void { @@ -39,7 +41,24 @@ class OAuth2Routes implements RouteHandler { return $result; } + #[HttpGet('/authorise')] + #[HttpGet('/authorize')] + public function getAuthorise($response, $request) { + $url = trim($this->config->getString('authorise')); + if($url === '') + return 404; + + $params = $request->getParamString(); + if($params !== '') { + $url .= str_contains($url, '?') ? '&' : '?'; + $url .= $params; + } + + $response->redirect($url); + } + #[HttpPost('/request-authorise')] + #[HttpPost('/request-authorize')] public function postRequestAuthorise($response, $request) { $response->setHeader('Cache-Control', 'no-store'); diff --git a/src/SyokuhouContext.php b/src/SyokuhouContext.php index 4aaa042..e911d04 100644 --- a/src/SyokuhouContext.php +++ b/src/SyokuhouContext.php @@ -26,7 +26,7 @@ class SyokuhouContext { $this->router->use('/', $this->handleAcceptHeader(...)); $this->router->get('/', fn() => 'Hello! Someday this page will probably redirect to documentation, but none exists yet.'); - $this->router->scopeTo('/oauth2')->register(new OAuth2\OAuth2Routes($this)); + $this->router->scopeTo('/oauth2')->register(new OAuth2\OAuth2Routes($this, $config->scopeTo('oauth2'))); $this->router->scopeTo('/v1')->register(new V1\V1Routes(new V1\V1Context($this))); }