Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
fokosun committed Oct 7, 2023
1 parent 12af28e commit 322ddc7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions app/Http/Clients/TikTokHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
class TikTokHttpClient
{
protected array $config;
protected Client $client;

public function __construct()
{
Expand All @@ -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/',
[
Expand All @@ -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' => [
Expand Down Expand Up @@ -83,4 +82,9 @@ private function getClientSecret(): string
{
return $this->config['client_secret'] ?? '';
}

private function getClient()
{
return new Client();
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit 322ddc7

Please sign in to comment.