- Introduced `KekaAccessGuard`, `KekaConfigResolver`, `KekaIntegrationService`, `KekaTokenService`, and `KekaUrlBuilder` to streamline Keka HR functionality. - Refactored `KekaController` to delegate key operations to modular services, improving maintainability. - Updated dashboard UI to ensure alignment with the new service-based architecture. - Enhanced error handling, logging, and code reusability for Keka integration workflows.
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Keka;
|
|
|
|
use App\Models\{OauthToken, User};
|
|
|
|
class KekaTokenService
|
|
{
|
|
public function store(User $user, string $code): void
|
|
{
|
|
$microsoftToken = $user->oauthToken('microsoft');
|
|
|
|
if ($microsoftToken) {
|
|
$accessToken = $microsoftToken->access_token;
|
|
$refreshToken = $microsoftToken->refresh_token;
|
|
$tokenType = $microsoftToken->token_type;
|
|
$scopes = $microsoftToken->scopes;
|
|
$expiresAt = $microsoftToken->expires_at;
|
|
} else {
|
|
$accessToken = $code;
|
|
$refreshToken = 'keka-placeholder-refresh';
|
|
$tokenType = 'Bearer';
|
|
$scopes = 'openid profile email';
|
|
$expiresAt = now()->addHour();
|
|
}
|
|
|
|
OauthToken::updateOrCreate(
|
|
[
|
|
'user_id' => $user->id,
|
|
'provider' => 'keka',
|
|
],
|
|
[
|
|
'access_token' => $accessToken,
|
|
'refresh_token' => $refreshToken,
|
|
'token_type' => $tokenType,
|
|
'scopes' => $scopes,
|
|
'expires_at' => $expiresAt,
|
|
]
|
|
);
|
|
}
|
|
|
|
public function revoke(User $user): void
|
|
{
|
|
$user->oauthToken('keka')?->delete();
|
|
}
|
|
}
|