From 2a8fbb3f6e741cfc9fa087a0da062c03d332c6d7 Mon Sep 17 00:00:00 2001
From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com>
Date: Wed, 29 Oct 2025 23:21:38 +0100
Subject: [PATCH] feat: add token validation functionality for Hetzner and
DigitalOcean providers
---
app/Livewire/Security/CloudProviderTokens.php | 54 +++++++++++++++++++
.../cloud-provider-token-form.blade.php | 18 ++++---
.../security/cloud-provider-tokens.blade.php | 28 ++++++----
3 files changed, 82 insertions(+), 18 deletions(-)
diff --git a/app/Livewire/Security/CloudProviderTokens.php b/app/Livewire/Security/CloudProviderTokens.php
index f05b3c0ca..cfef30772 100644
--- a/app/Livewire/Security/CloudProviderTokens.php
+++ b/app/Livewire/Security/CloudProviderTokens.php
@@ -30,6 +30,60 @@ public function loadTokens()
$this->tokens = CloudProviderToken::ownedByCurrentTeam()->get();
}
+ public function validateToken(int $tokenId)
+ {
+ try {
+ $token = CloudProviderToken::ownedByCurrentTeam()->findOrFail($tokenId);
+ $this->authorize('view', $token);
+
+ if ($token->provider === 'hetzner') {
+ $isValid = $this->validateHetznerToken($token->token);
+ if ($isValid) {
+ $this->dispatch('success', 'Hetzner token is valid.');
+ } else {
+ $this->dispatch('error', 'Hetzner token validation failed. Please check the token.');
+ }
+ } elseif ($token->provider === 'digitalocean') {
+ $isValid = $this->validateDigitalOceanToken($token->token);
+ if ($isValid) {
+ $this->dispatch('success', 'DigitalOcean token is valid.');
+ } else {
+ $this->dispatch('error', 'DigitalOcean token validation failed. Please check the token.');
+ }
+ } else {
+ $this->dispatch('error', 'Unknown provider.');
+ }
+ } catch (\Throwable $e) {
+ return handleError($e, $this);
+ }
+ }
+
+ private function validateHetznerToken(string $token): bool
+ {
+ try {
+ $response = \Illuminate\Support\Facades\Http::withToken($token)
+ ->timeout(10)
+ ->get('https://api.hetzner.cloud/v1/servers?per_page=1');
+
+ return $response->successful();
+ } catch (\Throwable $e) {
+ return false;
+ }
+ }
+
+ private function validateDigitalOceanToken(string $token): bool
+ {
+ try {
+ $response = \Illuminate\Support\Facades\Http::withToken($token)
+ ->timeout(10)
+ ->get('https://api.digitalocean.com/v2/account');
+
+ return $response->successful();
+ } catch (\Throwable $e) {
+ return false;
+ }
+ }
+
public function deleteToken(int $tokenId)
{
try {
diff --git a/resources/views/livewire/security/cloud-provider-token-form.blade.php b/resources/views/livewire/security/cloud-provider-token-form.blade.php
index 9ed7a5ca2..e803aa00c 100644
--- a/resources/views/livewire/security/cloud-provider-token-form.blade.php
+++ b/resources/views/livewire/security/cloud-provider-token-form.blade.php
@@ -14,13 +14,14 @@