✨ Add login/refresh token commands
This commit is contained in:
parent
bc3a42b501
commit
d0c3002bf1
3 changed files with 105 additions and 0 deletions
45
app/Commands/TraktRefreshLogin.php
Normal file
45
app/Commands/TraktRefreshLogin.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Services\Trakt;
|
||||
|
||||
class TraktRefreshLogin extends Command
|
||||
{
|
||||
protected $signature = 'trakt:refresh';
|
||||
protected $description = 'Refresh access token.';
|
||||
|
||||
public function handle(Trakt $trakt): int
|
||||
{
|
||||
$oauth_resp = json_decode(env('TRAKT_OAUTH_RESP'), true);
|
||||
if (empty($oauth_resp)) {
|
||||
$this->line("Failed to get OAuth response");
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'refresh_token' => $oauth_resp['refresh_token'],
|
||||
'client_id' => env('TRAKT_APP_ID'),
|
||||
'client_secret' => env('TRAKT_APP_SECRET'),
|
||||
'redirect_uri' => env('TRAKT_REDIRECT_URI'),
|
||||
'grant_type' => 'refresh_token',
|
||||
];
|
||||
|
||||
$resp = $trakt->request()->post('/oauth/token', $data);
|
||||
|
||||
if (!$resp->ok()) {
|
||||
$this->line('Failed to get new token');
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
// $this->line(json_encode($resp->body()));
|
||||
// $body = $json->body();
|
||||
$body = $resp->json();
|
||||
$this->line("TRAKT_OAUTH_RESP='" . json_encode($body) . "'");
|
||||
$this->line('TRAKT_OAUTH_TOKEN=' . $body['access_token']);
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue