mirror of
https://github.com/nihonbuzz/nihonbuzz-academy.git
synced 2026-01-27 02:41:58 +07:00
46 lines
1.3 KiB
PHP
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;
|
|
}
|
|
}
|