How to implement the TikTok Login Kit for Web in PHP
With more Gen-Z and Millennials in the platform, allowing the simplified signup and login process via TikTok is the logical step for many Web Apps, including our very own Lnk.Bio.
While the implementation is a very basic oauth2 flow, there were no published class nor guides specific to PHP implementation, so I thought useful to publish an Open-Source class and this quick tutorial based on such class.
Step 1: Register your App
Pay attention to the approved redirect URLs. While the TikTok page calls them “Redirect Domains”, they actually require full URLs, so the full path of the page where you’re redirected after the TikTok login.
After you register your application you will receive, as usual a Client Key and Client Secret.
Step 2: Install helper class
Use Composer to install the PHP helper
composer require gimucco/tiktok-loginkit
If, for any reason, you’re not using Composer, you can download the class from Github. Current stable is v0.1.
Step 3: Full Login Example
The login flow is typical:
- Generate a Redirect Url to send the user to TikTok to authorise your app
- Receive the Authorisation Token
- Exchange the Authorisation Token with an Access Token that you can use for the rest of the calls
- Make a sample call to retrieve the User Information
Here’s a quick code sample