Search code examples
node.jshttp-redirectoauth-2.0tiktok

TIKTOK LoginKit, redirect_uri bad


  • I just followed the documentation for use auth2 with tiktok.

  • My URL Redirect is setting enter image description here

  • And my code follow that


     @Get('/tiktok/redirect')
        loginTicTok(
            @Res() res,
        ) {
            const csrfState = Math.random().toString(36).substring(2);
            res.cookie('csrfState', csrfState, { maxAge: 60000 });
            let url =`${this.config.get('tictokURL')}`;
            url +=`?client_key=${this.config.get('tictokClientKey')}`;
            url +=`&scope=video.upload`;
            url += '&response_type=code';
            url += '&redirect_uri=https://reelcrm-backend.herokuapp.com/social-network/tiktok/';
            res.redirect(url);
        }
  • My link generate is:
  • But the problems is tiktok is getting show me bad request from URL:

https://www.tiktok.com/v2/auth/authorize/?client_key=myclientcode&scope=video.upload&response_type=code&redirect_uri=https://reelcrm-backend.herokuapp.com/social-network/tiktok/

enter image description here


Solution

  • I think your TikTok request URL is right https://www.tiktok.com/v2/auth/authorize/?client_key=myclientcode&scope=video.upload&response_type=code&redirect_uri=https://reelcrm-backend.herokuapp.com/social-network/tiktok/.

    And I also your redirect uri is same but you need to encode your URL parameters tiktok guideline for URL encode parameters.

    so try using encoded URL query params this is reference https://developers.tiktok.com/doc/login-kit-web