ThexXTURBOXx / flutter_web_auth_2

Flutter plugin for authenticating a user with a web service
https://pub.dev/packages/flutter_web_auth_2
MIT License
51 stars 50 forks source link

Need help for login with tiktok #64

Closed alfaruqrizqi18 closed 1 year ago

alfaruqrizqi18 commented 1 year ago

Description

Hi, after redirected to tiktok authorize and redirect uri, still not getting the result

To Reproduce

Future<String?> connect() async {
    // Construct the url
    const String callbackUrlScheme = 'https://example.com/oauth2redirect?social=Tiktok';
    final url = Uri.https('www.tiktok.com', '/auth/authorize/', {
      'client_key': '***********',
      'response_type': 'code',
      'scope': 'user.info.basic,video.list',
      'redirect_uri': callbackUrlScheme,
      'state': 'Tiktok',
    });

    try {
      final result = await FlutterWebAuth2.authenticate(
        url: url.toString(),
        callbackUrlScheme: 'https',
      );
      // String accessToken = Uri.parse(result).queryParameters['code'] ?? "";
      return Uri.parse(result).toString();
    } catch (e) {
      print("Error -> ${e.toString()}");
    }
  }

Expected behavior

Need to get the result after authorized from tiktok and redirect_uri

Screenshots

If applicable, add screenshots to help explain your problem.

Device (please complete the following information!)

Additional context

Add any other context about the problem here.

Checklist

alfaruqrizqi18 commented 1 year ago

Is something missing with my code? @ThexXTURBOXx

ThexXTURBOXx commented 1 year ago

First read through the troubleshooting guide please as indicated by the issue template. Also, I need further information: Are you compiling your application for Windows or Web or something different?

alfaruqrizqi18 commented 1 year ago

Still confusing about callbackUrlScheme, because from tiktok redirect_uri is to my webpage Ex : my redirect_uri in tiktok -> https://example.com/oauth2redirect?social=Tiktok, so what is the callbackUrlScheme?

I'm using this for web

alfaruqrizqi18 commented 1 year ago

Still confusing about callbackUrlScheme, because from tiktok redirect_uri is to my webpage Ex : my redirect_uri in tiktok -> https://example.com/oauth2redirect?social=Tiktok, so what is the callbackUrlScheme?

I'm using this for web

Can help this? @ThexXTURBOXx I don't know what is callbackUrlScheme for web

ThexXTURBOXx commented 1 year ago

You need to read through the readme for the setup instructions and the troubleshooting guide for further help.

alfaruqrizqi18 commented 1 year ago

You need to read through the readme for the setup instructions and the troubleshooting guide for further help.

I have read readme for the setup instructions and the troubleshooting guide. But still can't get the result @ThexXTURBOXx

alfaruqrizqi18 commented 1 year ago

also have created auth.html

ThexXTURBOXx commented 1 year ago

Then, why are you still not redirecting to the auth.html page as described in the Readme?

alfaruqrizqi18 commented 1 year ago

When this code called

final result = await FlutterWebAuth2.authenticate(
  url: url.toString(),
  callbackUrlScheme: 'https',
);

It will open new tab with this url and parameter

Uri.https('www.tiktok.com', '/auth/authorize/', {
      'client_key': '***********',
      'response_type': 'code',
      'scope': 'user.info.basic,video.list',
      'redirect_uri': 'https://example.com/oauth2redirect?social=Tiktok',
      'state': 'Tiktok',
    })

After tiktok page is open, I just need to click Authorize Button and then if authorize is successfull, from tiktok will redirect automatically to this 'https://example.com/oauth2redirect?social=Tiktok'

After redirected to that page, the tab isn't closed. That's why I ask you to help. Is this code still wrong or something? because I don't know the callbackUrlScheme, so I added the https

final result = await FlutterWebAuth2.authenticate(
  url: url.toString(),
  callbackUrlScheme: 'https',
);

@ThexXTURBOXx

ThexXTURBOXx commented 1 year ago

The callbackUrlScheme is ignored on the Web version. You need tiktok to redirect to the auth.html page as described in the Readme.