FlutterWebAuth2 browser not closing on TikTok login

20 views Asked by At

I've been trying to figure out the problem in my TikTok login flow. I tried integrating native SDK of TikTok Login Kit but it doesn't seem to work very well as my app is already managing a lot of URL schemes. The problem with the native SDK was the deeplink interception so I chose to log the user in using FlutterWebAuth2.

This is how my code looks like for the login flow:

static Future<void> getCode() async {
    final generatedPkcePair = PkcePair.generate();

    final codeVerifier = generatedPkcePair.codeVerifier;
    final codeChallenge = generatedPkcePair.codeChallenge;

    final result = await FlutterWebAuth2.authenticate(
      url:
          'https://www.tiktok.com/v2/auth/authorize/?response_type=code&scope=user.info.basic&client_key=XXXXXXXXXXXXXX0p&state&redirect_uri=https://app.xxxxxxxx.com/login/tiktok&code_challenge=$codeChallenge',
      callbackUrlScheme: 'https',
    );

    print(result);
}

I've also added the https as my url scheme and app.xxxxxxxx.com as my applink. TikTok doesn't allow schemes other than https for Web and iOS.

Result: When the I tap on continue, the button keeps loading and nothing happens. I have to tap on cancel which throws an exception of user_cancelled.

This runs for infinite

Expected Result: The in app browser should close and return the code along with code_verifier and other necessary data.

Versions: Flutter SDK: 3.16.9 flutter_web_auth_2: ^3.1.1

If you need any further details, just add a comment and I will edit the question

0

There are 0 answers