Files
nihonbuzz-academy/app/Services/SocialAuthService.php
2026-01-23 17:28:21 +07:00

46 lines
1.3 KiB
PHP

<?php
namespace App\Services;
use App\Models\SocialAccount;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class SocialAuthService
{
/**
* Revoke the OAuth token for a given social account.
* Mandatory for security compliance.
*/
public function revokeToken(SocialAccount $account): bool
{
if (!$account->token) {
return false;
}
try {
if ($account->provider === 'google') {
$response = Http::asForm()->post('https://oauth2.googleapis.com/revoke', [
'token' => $account->token,
]);
if ($response->successful()) {
Log::info("Successfully revoked Google token for User ID: {$account->user_id}");
$account->update([
'token' => null,
'refresh_token' => null,
'expires_at' => null,
]);
return true;
}
Log::error("Failed to revoke Google token for User ID: {$account->user_id}. Status: " . $response->status());
}
} catch (\Exception $e) {
Log::error("Error during token revocation: " . $e->getMessage());
}
return false;
}
}