From c97ea9850420bca5c4c8c21f9b74627f69f49a0b Mon Sep 17 00:00:00 2001 From: fokosun Date: Sat, 7 Oct 2023 16:40:51 -0400 Subject: [PATCH 1/2] bugfix --- app/Http/Clients/TikTokHttpClient.php | 10 +++++++--- app/Http/Controllers/AuthController.php | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Http/Clients/TikTokHttpClient.php b/app/Http/Clients/TikTokHttpClient.php index 3f928b3..2903bed 100644 --- a/app/Http/Clients/TikTokHttpClient.php +++ b/app/Http/Clients/TikTokHttpClient.php @@ -9,7 +9,6 @@ class TikTokHttpClient { protected array $config; - protected Client $client; public function __construct() { @@ -18,7 +17,7 @@ public function __construct() public function getAccessToken(string $code) { - $response = $this->client->request( + $response = $this->getClient()->request( 'POST', $this->getUri() . '/oauth/access_token/', [ @@ -42,7 +41,7 @@ public function getAccessToken(string $code) public function getUserInfo(string $open_id, string $access_token) { - $userInfoResponse = $this->client->request('POST', + $userInfoResponse = $this->getClient()->request('POST', $this->getUri() . '/user/info/', [ 'json' => [ @@ -83,4 +82,9 @@ private function getClientSecret(): string { return $this->config['client_secret'] ?? ''; } + + private function getClient() + { + return new Client(); + } } diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 940269c..5cf5c73 100755 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -144,7 +144,7 @@ public function loginViaMagicLink(Request $request, LocationService $locationSer * * @throws GuzzleException */ - public function tikTokHandleCallback(Request $request, TikTokHttpClient $client, UserService $service) + public function tikTokHandleCallback(Request $request, TikTokHttpClient $httpClient, UserService $service) { $code = $request->get('code'); $errCode = $request->get('errCode'); @@ -154,7 +154,7 @@ public function tikTokHandleCallback(Request $request, TikTokHttpClient $client, } try { - $decoded = $client->getAccessToken($code); + $decoded = $httpClient->getAccessToken($code); $message = Arr::get($decoded, 'message'); $open_id = Arr::get($decoded, 'data.open_id'); $access_token = Arr::get($decoded, 'data.access_token'); @@ -163,7 +163,7 @@ public function tikTokHandleCallback(Request $request, TikTokHttpClient $client, throw new \Exception(json_encode($decoded)); } - $userInfo = $client->getUserInfo($open_id, $access_token); + $userInfo = $httpClient->getUserInfo($open_id, $access_token); if (!empty($userInfo['data']['user'])) { $open_id = Arr::get($userInfo, 'data.user.open_id'); From e5c6956a74f664e81cf1b38c56c93e48daabfd00 Mon Sep 17 00:00:00 2001 From: fokosun Date: Sat, 7 Oct 2023 16:43:49 -0400 Subject: [PATCH 2/2] bugfix --- app/Http/Clients/TikTokHttpClient.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/Http/Clients/TikTokHttpClient.php b/app/Http/Clients/TikTokHttpClient.php index 2903bed..60a3a00 100644 --- a/app/Http/Clients/TikTokHttpClient.php +++ b/app/Http/Clients/TikTokHttpClient.php @@ -9,15 +9,17 @@ class TikTokHttpClient { protected array $config; + protected Client $client; - public function __construct() + public function __construct(Client $client) { $this->config = config('services.tiktok'); + $this->client = $client; } public function getAccessToken(string $code) { - $response = $this->getClient()->request( + $response = $this->client->request( 'POST', $this->getUri() . '/oauth/access_token/', [ @@ -41,7 +43,7 @@ public function getAccessToken(string $code) public function getUserInfo(string $open_id, string $access_token) { - $userInfoResponse = $this->getClient()->request('POST', + $userInfoResponse = $this->client->request('POST', $this->getUri() . '/user/info/', [ 'json' => [ @@ -82,9 +84,4 @@ private function getClientSecret(): string { return $this->config['client_secret'] ?? ''; } - - private function getClient() - { - return new Client(); - } }