From 085762ec174eae1c519ec14db632f5ba197ed3c7 Mon Sep 17 00:00:00 2001 From: winter Date: Tue, 17 Dec 2024 18:39:18 +0000 Subject: hopefully implement push! again i can't really test this yet because i don't have two https instances that can talk to each other. soon i will set that up and test all these recent commits --- routes/auth.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'routes/auth.php') diff --git a/routes/auth.php b/routes/auth.php index 2127a46..d64331e 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -2,7 +2,7 @@ use Digitigrade\GlobalConfig; use Digitigrade\HttpResponseStatus\BadRequest; -use Digitigrade\HttpResponseStatus\Forbidden; +use Digitigrade\HttpResponseStatus\Unauthorized; use Digitigrade\Job\ExpireInboundAuthToken; use Digitigrade\Job\RequestOutboundAuthToken; use Digitigrade\Model\Instance; @@ -19,8 +19,8 @@ Router::getInstance()->mount('/auth/main', function (array $args) { if (!isset($_GET['target'])) { throw new BadRequest('you need to specify the `target` GET parameter'); } - $domain = explode('/', $_GET['target'])[2]; - $instance = Instance::findByDomain($domain); + $domain = hostname_from_uri($_GET['target']); + $instance = Instance::findByHostname($domain); if ($instance == null) { throw new RuntimeException("i can't find your instance information, sorry"); } @@ -51,7 +51,7 @@ Router::getInstance()->mount('/auth/main', function (array $args) { } $instance = Instance::findByDialbackSecret($_GET['secret']); if ($instance == null) { - throw new Forbidden('the provided secret is invalid!'); + throw new Unauthorized('the provided secret is invalid!'); } $instance->auth->secret = null; // it's been used now @@ -79,7 +79,7 @@ Router::getInstance()->mount('/auth/main', function (array $args) { } $instance = Instance::findByInboundAuthToken($_GET['token']); if ($instance == null) { - throw new Forbidden('the provided token is invalid!'); + throw new Unauthorized('the provided token is invalid!'); } $instance->auth->inboundToken = random_printable_bytes(); @@ -109,7 +109,7 @@ Router::getInstance()->mount('/auth/dialback', function (array $args) { if (!isset($_POST['origin'], $_POST['secret'])) { throw new BadRequest('send the `origin` and `secret` parameters as POST data please :3'); } - $instance = Instance::findByDomain($_POST['origin']); + $instance = Instance::findByHostname($_POST['origin']); if ($instance == null) { throw new BadRequest("i can't seem to find your instance information!"); } -- cgit v1.3