aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes
diff options
context:
space:
mode:
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');
}