Skip to content

Commit

Permalink
Merge pull request #295 from mycookbook/quick-fix-tiktok-login
Browse files Browse the repository at this point in the history
bugfix
  • Loading branch information
fokosun authored Oct 7, 2023
2 parents 3203e7a + e5c6956 commit a5f0d1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/Http/Clients/TikTokHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ 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)
Expand Down
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 a5f0d1c

Please sign in to comment.