|
| 1 | +# TikTok Shop |
| 2 | + |
| 3 | +```bash |
| 4 | +composer require socialiteproviders/manager |
| 5 | +``` |
| 6 | + |
| 7 | +## Installation & Basic Usage |
| 8 | + |
| 9 | +Please see the [Base Installation Guide](https://socialiteproviders.com/usage/), then follow the provider specific |
| 10 | +instructions below. |
| 11 | + |
| 12 | +## Configuration |
| 13 | + |
| 14 | +First, add your TikTok Shop app credentials to `config/services.php`: |
| 15 | + |
| 16 | +```php |
| 17 | +'tiktokshop' => [ |
| 18 | + 'client_id' => env('TIKTOKSHOP_APP_KEY'), // Your Partner Center App Key |
| 19 | + 'client_secret' => env('TIKTOKSHOP_APP_SECRET'), // Your Partner Center App Secret |
| 20 | + 'redirect' => env('TIKTOKSHOP_REDIRECT_URI'), // Your callback URI |
| 21 | +], |
| 22 | +``` |
| 23 | + |
| 24 | +Make sure you have these in your `.env`: |
| 25 | + |
| 26 | +```bash |
| 27 | +TIKTOKSHOP_APP_KEY=your_partner_center_app_key |
| 28 | +TIKTOKSHOP_APP_SECRET=your_partner_center_app_secret |
| 29 | +TIKTOKSHOP_REDIRECT_URI=https://yourapp.com/auth/tiktokshop/callback |
| 30 | +``` |
| 31 | + |
| 32 | +### Add provider event listener |
| 33 | + |
| 34 | +#### Laravel 11+ |
| 35 | + |
| 36 | +In Laravel 11, register the listener directly in your `AppServiceProvider@boot`: |
| 37 | + |
| 38 | +```php |
| 39 | +use SocialiteProviders\Manager\SocialiteWasCalled; |
| 40 | +use App\Providers\Socialite\TikTokShop\TikTokShopExtendSocialite; |
| 41 | +use Illuminate\Support\Facades\Event; |
| 42 | + |
| 43 | +public function boot() |
| 44 | +{ |
| 45 | + Event::listen(function (SocialiteProviders\Manager\SocialiteWasCalled $event) { |
| 46 | + $event->extendSocialite('tiktokshop', \App\Providers\Socialite\TikTokShop\Provider::class); |
| 47 | + }); |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +<details> |
| 52 | +<summary>Laravel 10 or below</summary> |
| 53 | + |
| 54 | +Configure the package’s listener in `app/Providers/EventServiceProvider.php`: |
| 55 | + |
| 56 | +```php |
| 57 | +protected $listen = [ |
| 58 | + \SocialiteProviders\Manager\SocialiteWasCalled::class => [ |
| 59 | + \App\Providers\Socialite\TikTokShop\TikTokShopExtendSocialite::class.'@handle', |
| 60 | + ], |
| 61 | +]; |
| 62 | +``` |
| 63 | + |
| 64 | +</details> |
| 65 | + |
| 66 | +## Usage |
| 67 | + |
| 68 | +You can now redirect to TikTok Shop for authorization: |
| 69 | + |
| 70 | +```php |
| 71 | +use Laravel\Socialite\Facades\Socialite; |
| 72 | + |
| 73 | +return Socialite::driver('tiktokshop')->redirect(); |
| 74 | +``` |
| 75 | + |
| 76 | +And handle the callback: |
| 77 | + |
| 78 | +```php |
| 79 | +$shopUser = Socialite::driver('tiktokshop')->user(); |
| 80 | + |
| 81 | +// Access mapped fields: |
| 82 | +$shopUser->getId(); |
| 83 | +$shopUser->getName(); |
| 84 | +$shopUser->token; |
| 85 | +$shopUser->refreshToken; |
| 86 | +$shopUser->expiresIn; |
| 87 | +``` |
| 88 | + |
| 89 | +### Returned User fields |
| 90 | + |
| 91 | +* `id` – the TikTok Shop `open_id` |
| 92 | +* `nickname` / `name` – the `seller_name` |
| 93 | +* `token` – the `access_token` |
| 94 | +* `refreshToken` – the `refresh_token` |
| 95 | +* `expiresIn` – seconds until token expiry |
| 96 | + |
| 97 | +## References |
| 98 | + |
| 99 | +* [TikTok Shop Partner Center Authorization Overview (202407)](https://partner.tiktokshop.com/docv2/page/678e3a3292b0f40314a92d75) |
0 commit comments