aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes
diff options
context:
space:
mode:
authorwinter2024-12-17 14:07:52 +0000
committerwinter2024-12-17 14:07:52 +0000
commit8cbb7f7c632961f615f9b5f9bd51984b9a929340 (patch)
tree7dd41ffaa09a0409761aabb37ac6442595cc3303 /routes
parenta33cc49a45053025e1977c3a1f6e4e7b5f8a264d (diff)
hopefully implement refreshing inbound tokens
Diffstat (limited to 'routes')
-rw-r--r--routes/auth.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/routes/auth.php b/routes/auth.php
index 2dbe6f1..2127a46 100644
--- a/routes/auth.php
+++ b/routes/auth.php
@@ -72,6 +72,33 @@ Router::getInstance()->mount('/auth/main', function (array $args) {
break;
+ case 'refresh':
+ // verify the token, if it's good, replace it with a new one
+ if (!isset($_GET['token'])) {
+ throw new BadRequest('you need to specify the `token` GET parameter');
+ }
+ $instance = Instance::findByInboundAuthToken($_GET['token']);
+ if ($instance == null) {
+ throw new Forbidden('the provided token is invalid!');
+ }
+
+ $instance->auth->inboundToken = random_printable_bytes();
+ $instance->auth->save();
+
+ $expiry = new \DateTimeImmutable('1 day');
+ (new ExpireInboundAuthToken(
+ $instance->domain,
+ $instance->auth->inboundToken,
+ $expiry
+ ))->submit();
+
+ json_response([
+ 'token' => $instance->auth->inboundToken,
+ 'expires' => $expiry->format('c')
+ ]);
+
+ break;
+
default:
throw new BadRequest('invalid phase');
}