✨ Refactor Trakt configuration to use config file and dependency injection
This commit is contained in:
parent
347c0330b1
commit
caa1f0e442
5 changed files with 32 additions and 19 deletions
|
|
@ -5,16 +5,16 @@ declare(strict_types=1);
|
|||
namespace App\Commands;
|
||||
|
||||
use App\Services\Trakt;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
|
||||
class TraktLogin extends Command
|
||||
{
|
||||
protected $signature = 'trakt:login';
|
||||
protected $description = 'Login and get new token.';
|
||||
|
||||
public function handle(Trakt $trakt): int
|
||||
public function handle(Trakt $trakt, Repository $config): int
|
||||
{
|
||||
$data = [
|
||||
'client_id' => env('TRAKT_APP_ID'),
|
||||
'client_id' => $config->get('trakt.app_id'),
|
||||
];
|
||||
|
||||
$resp = $trakt->requestNoAuth()->post('/oauth/device/code', $data);
|
||||
|
|
@ -33,8 +33,8 @@ class TraktLogin extends Command
|
|||
$this->line("TRAKT_DEVICE_RESP='" . json_encode($body) . "'");
|
||||
|
||||
$data = [
|
||||
'client_id' => env('TRAKT_APP_ID'),
|
||||
'client_secret' => env('TRAKT_APP_SECRET'),
|
||||
'client_id' => $config->get('trakt.app_id'),
|
||||
'client_secret' => $config->get('trakt.app_secret'),
|
||||
'code' => $body['device_code'],
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -5,25 +5,25 @@ declare(strict_types=1);
|
|||
namespace App\Commands;
|
||||
|
||||
use App\Services\Trakt;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
|
||||
class TraktRefreshLogin extends Command
|
||||
{
|
||||
protected $signature = 'trakt:refresh';
|
||||
protected $description = 'Refresh access token.';
|
||||
|
||||
public function handle(Trakt $trakt): int
|
||||
public function handle(Trakt $trakt, Repository $config): int
|
||||
{
|
||||
$oauth_resp = json_decode(env('TRAKT_OAUTH_RESP'), true);
|
||||
if (empty($oauth_resp)) {
|
||||
$this->line("Failed to get OAuth response");
|
||||
$refresh_token = $config->get('trakt.login.oauth.refresh_token');
|
||||
if (empty($refresh_token)) {
|
||||
$this->line("Failed to get refresh token");
|
||||
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'),
|
||||
'refresh_token' => $refresh_token,
|
||||
'client_id' => $config->get('trakt.app_id'),
|
||||
'client_secret' => $config->get('trakt.app_secret'),
|
||||
'redirect_uri' => $config->get('trakt.redirect_uri'),
|
||||
'grant_type' => 'refresh_token',
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue