Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions app/Http/Controllers/Auth/TikTokController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ class TikTokController extends SocialController

protected SocialPlatform $platform = SocialPlatform::TikTok;

protected array $scopes = [
'user.info.basic',
'user.info.profile',
'user.info.stats',
'video.publish',
'video.upload',
'video.list',
];
/**
* Requested scopes come from config so self-hosters whose TikTok app lacks
* a product (Display API is no longer offered to new apps, taking
* user.info.profile/stats and video.list with it) can trim the list via
* TIKTOK_SCOPES instead of hitting a "scope" error on the consent screen.
*/
private function scopes(): array
{
return (array) config('trypost.platforms.tiktok.scopes');
}

public function connect(Request $request): Response
{
Expand All @@ -37,7 +39,7 @@ public function connect(Request $request): Response

$this->authorize('manageAccounts', $workspace);

return $this->redirectToProvider($request, $this->driver, $this->scopes);
return $this->redirectToProvider($request, $this->driver, $this->scopes());
}

public function callback(Request $request): InertiaResponse
Expand All @@ -46,7 +48,7 @@ public function callback(Request $request): InertiaResponse

try {
$socialUser = Socialite::driver($this->driver)
->scopes($this->scopes)
->scopes($this->scopes())
->user();

// TikTok returns username via getNickname() when user.info.profile scope is included
Expand Down
4 changes: 4 additions & 0 deletions config/trypost.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
'tiktok' => [
'enabled' => env('TIKTOK_ENABLED', true),
'api' => env('TIKTOK_API', 'https://open.tiktokapis.com/v2'),
// OAuth scopes to request. Trim when the TikTok app lacks a product
// (e.g. no Display API => drop user.info.profile, user.info.stats,
// video.list; analytics degrade gracefully, username stays empty).
'scopes' => array_values(array_filter(array_map('trim', explode(',', (string) env('TIKTOK_SCOPES', 'user.info.basic,user.info.profile,user.info.stats,video.publish,video.upload,video.list'))))),
],
'youtube' => [
'enabled' => env('YOUTUBE_ENABLED', true),
Expand Down