diff --git a/app/Livewire/RegistrationToken.php b/app/Livewire/RegistrationToken.php
new file mode 100644
index 0000000..05bc145
--- /dev/null
+++ b/app/Livewire/RegistrationToken.php
@@ -0,0 +1,58 @@
+synapseService = $synapseService;
+ }
+
+ public function mount()
+ {
+ $this->fetchTokens();
+ }
+
+ public function fetchTokens()
+ {
+ $this->tokens = $this->synapseService->fetchTokens();
+ }
+
+ public function revokeToken(string $token)
+ {
+ if ($this->synapseService->revokeToken($token)) {
+ $this->fetchTokens();
+ }
+ }
+
+ public function createToken()
+ {
+ $this->registrationToken = $this->synapseService->createRegistrationToken();
+
+ // Open modal
+ $this->modal('registration-token')->show();
+ }
+
+ public function resetToken()
+ {
+ $this->registrationToken = null;
+ $this->fetchTokens();
+ }
+
+ public function render()
+ {
+ return view('livewire.registration-token');
+ }
+}
diff --git a/app/Services/SynapseService.php b/app/Services/SynapseService.php
index c15bdf7..a1c042d 100644
--- a/app/Services/SynapseService.php
+++ b/app/Services/SynapseService.php
@@ -9,15 +9,24 @@ use Illuminate\Support\Facades\Log;
class SynapseService
{
+ protected string $AUTH_TOKEN;
+ protected string $SYNAPSE_ENDPOINT;
+
+ public function __construct()
+ {
+ $this->AUTH_TOKEN = Settings::get('synapse_access_token', '');
+ $this->SYNAPSE_ENDPOINT = Settings::get('synapse_endpoint', '');
+ }
+
+ /**
+ * Create registration token
+ */
public function createRegistrationToken(): ?string
{
- $token = Settings::get('synapse_access_token', '');
- $endpoint = Settings::get('synapse_endpoint', '');
-
$response = Http::withHeaders([
- 'Authorization' => "Bearer $token",
+ 'Authorization' => "Bearer $this->AUTH_TOKEN",
'Content-Type' => 'application/json'
- ])->post($endpoint . '/_synapse/admin/v1/registration_tokens/new', [
+ ])->post("$this->SYNAPSE_ENDPOINT/_synapse/admin/v1/registration_tokens/new", [
'uses_allowed' => 1,
'length' => 12,
'expiry_time' => now()->addWeek()->valueOf(),
@@ -34,4 +43,34 @@ class SynapseService
return null;
}
+
+ /**
+ * Fetch all active registration tokens from Synapse
+ */
+ public function fetchTokens(): ?array
+ {
+ $response = Http::withHeaders([
+ 'Authorization' => "Bearer $this->AUTH_TOKEN",
+ 'Content-Type' => 'application/json'
+ ])->get("$this->SYNAPSE_ENDPOINT/_synapse/admin/v1/registration_tokens?valid=true");
+
+ if ($response->successful()) {
+ return $response->json()['registration_tokens'] ?? [];
+ }
+
+ return null;
+ }
+
+ /**
+ * Revoke registration token
+ */
+ public function revokeToken(string $token): ?bool
+ {
+ $response = Http::withHeaders([
+ 'Authorization' => "Bearer $this->AUTH_TOKEN",
+ 'Content-Type' => 'application/json'
+ ])->delete("$this->SYNAPSE_ENDPOINT/_synapse/admin/v1/registration_tokens/$token");
+
+ return $response->successful();
+ }
}
diff --git a/resources/views/components/layouts/app/sidebar.blade.php b/resources/views/components/layouts/app/sidebar.blade.php
index 4583fb8..79f4ef6 100644
--- a/resources/views/components/layouts/app/sidebar.blade.php
+++ b/resources/views/components/layouts/app/sidebar.blade.php
@@ -10,6 +10,7 @@
Uses allowed | +Pending | +Completed | +Expiry time | +Actions | +|
---|---|---|---|---|---|
+ {{ $token['uses_allowed'] }} + | +{{ $token['pending'] }} | +{{ $token['completed'] }} | ++ {{ $token['expiry_time'] ? Carbon\Carbon::createFromTimestampMs($token['expiry_time'])->toDateTimeString() : 'Never' }} + | +
+ |
+ |
No tokens found. | +