I have followed TikTok's docs here and here, step by step to setup user login through TikTok, but it sounds the docs are not clear enough, AppDelegate and Info.plist are correctly setup and there is no SceneDelegate in my test project, I'm using the following function to kick-off the login:
func startTikTokLogin() {
/* STEP 1 */
let scopes = ["user.info.basic"] // list your scopes
let scopesSet = NSOrderedSet(array: scopes)
let request = TikTokOpenSDKAuthRequest()
request.permissions = scopesSet
/* STEP 2 */
request.send(self, completion: { resp -> Void in
/* STEP 3 */
if resp.isSucceed {
print("TikTok success case")
/* STEP 3.a */
let clientKey = "my_client_key"
let responseCode = resp.code!
let baseURlString = "https://open-api.tiktok.com/demoapp/callback/?code=\(responseCode)&client_key=\(clientKey)"
let url = NSURL(string: baseURlString)
/* STEP 3.b */
let session = URLSession(configuration: .default)
let urlRequest = NSMutableURLRequest(url: url! as URL)
let task = session.dataTask(with: urlRequest as URLRequest) { (data, response, error) -> Void in
/* STEP 3.c */
let str = try! JSONSerialization.jsonObject(with: data!)
print("returned access token")
print(str)
}
task.resume()
} else {
// handle error
print("TikTok error case \(resp.errString!) - \(resp.errCode.rawValue)")
}
})
}
However, if the app is installed on device it opens displaying the following error message: Illegal authorization scope.
If the app is not installed an auth view controller (SafariViewController) opens and when I finish entering user credentials the SafariViewController dismisses and the else case above is executed printing the following error string and code in the console:
param_error - 10006.
I searched on TikTok's developer website for that error, it says:
10006 : Illegal redirection URI needs to be consistent with the "authorized callback domain" in the app configuration.
The error is misleading because there is nothing called callback domain in the app configuration section as the only enabled platform is iOS (no Web and no Android).
in Info.plist I've set the client key in the TikTokAppID and CFBundleURLSchemes keys as stated in the docs and I even tried to set the app ID in those two keys but to no avail.
I tried to follow the answer here but that didn't solve my problem.
Here's a small demo if what's going on (right: iPhone 12 Pro device with TikTok app installed, left: iPhone SE 3rd generation simulator):
P.S. the app is currently under review but I got a client id and secret once I first created the app (no review is required to get these two values).
