-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdateRefreshTokenService.php
More file actions
54 lines (43 loc) · 1.71 KB
/
UpdateRefreshTokenService.php
File metadata and controls
54 lines (43 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Seatplus\Eveapi\Services\Esi;
use Seatplus\EsiClient\DataTransferObjects\EsiAuthentication;
use Seatplus\EsiClient\Services\UpdateRefreshTokenService as EsiClientUpdateToken;
use Seatplus\Eveapi\Models\RefreshToken;
class UpdateRefreshTokenService
{
private EsiClientUpdateToken $refreshTokenService;
public static function make(): self
{
return new self;
}
public function update(RefreshToken $refreshToken): RefreshToken
{
$authentication = new EsiAuthentication(
client_id: config('eveapi.config.esi.eve_client_id'),
secret: config('eveapi.config.esi.eve_client_secret'),
access_token: $refreshToken->getRawOriginal('token'),
refresh_token: $refreshToken->refresh_token,
);
// Values are access_token // expires_in // token_type // refresh_token
$token = $this->getRefreshTokenService()->getRefreshTokenResponse($authentication);
return RefreshToken::updateOrCreate([
'character_id' => $refreshToken->character_id,
], [
'refresh_token' => data_get($token, 'refresh_token'),
'token' => data_get($token, 'access_token'),
'expires_on' => carbon()->addSeconds(data_get($token, 'expires_in')),
]);
}
public function getRefreshTokenService(): EsiClientUpdateToken
{
if (! isset($this->refreshTokenService)) {
$this->setRefreshTokenService(new EsiClientUpdateToken);
}
return $this->refreshTokenService;
}
public function setRefreshTokenService(EsiClientUpdateToken $refreshTokenService): self
{
$this->refreshTokenService = $refreshTokenService;
return $this;
}
}