Added /oauth2/authori[sz]e redirect to api.flashii.net.
This commit is contained in:
parent
ff5d8f8bdb
commit
2829419111
2 changed files with 21 additions and 2 deletions
|
@ -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');
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class SyokuhouContext {
|
|||
$this->router->use('/', $this->handleAcceptHeader(...));
|
||||
$this->router->get('/', fn() => '<!doctype html>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)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue