38 lines
982 B
PHP
38 lines
982 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Settings;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class SynapseService
|
|
{
|
|
public function createRegistrationToken(): ?string
|
|
{
|
|
$token = Settings::get('synapse_access_token', '');
|
|
$endpoint = Settings::get('synapse_endpoint', '');
|
|
|
|
$response = Http::withHeaders([
|
|
'Authorization' => "Bearer $token",
|
|
'Content-Type' => 'application/json'
|
|
])->post($endpoint . '/_synapse/admin/v1/registration_tokens/new', [
|
|
'uses_allowed' => 1,
|
|
'length' => 12,
|
|
'expiry_time' => now()->addWeek()->valueOf(),
|
|
]);
|
|
|
|
if ($response->successful()) {
|
|
return $response->json()['token'] ?? null;
|
|
}
|
|
|
|
Log::error('Failed to create Synapse registration token', [
|
|
'status' => $response->status(),
|
|
'body' => $response->body()
|
|
]);
|
|
|
|
return null;
|
|
}
|
|
}
|