flutter_web_auth icon indicating copy to clipboard operation
flutter_web_auth copied to clipboard

Flutter web authenticate method loop forever

Open emporioreale opened this issue 1 year ago • 2 comments

After calling the FlutterWebAuth.authenticate method and the page auth.html is shown, the method never returns, it loops forever. I am using flutter web. I am trying to get the ebay user authorization code. This is the code: ```

   Map<String, dynamic> queryParams = {
      "client_id": ebayAuthSnapshot['EBAY_CLIENT_ID'],
      "response_type": "code",
      "redirect_uri": ebayAuthSnapshot['EBAY_REDIRECT_URI'],
      "scope":
          "https://api.ebay.com/oauth/api_scope https://api.ebay.com/oauth/api_scope/buy.order.readonly 
    };
    // Construct the url
    final url = Uri.https(base, path, queryParams);

    // Present the dialog to the user
    final result = await FlutterWebAuth.authenticate(
        url: url.toString(), callbackUrlScheme: "/auth.html");
   print(result); // never print
auth.html file:
<!DOCTYPE html>
<title>Authentication complete</title>
<p>Authentication is complete. If this does not happen automatically, please
close the window.
<script>
 window.opener.postMessage({
   'flutter-web-auth': window.location.href
 }, window.location.origin);
 localStorage.setItem('url', window.location.href);
 window.close();
</script>

The redirect url after a succesful grants was set on the ebay developers account. What is wrong?

emporioreale avatar Jul 23 '22 07:07 emporioreale

Can you debug if window.opener.postMessage in auth.hmtl is called? Or in your case the URL is stored to local storage?

czepiec avatar Jul 23 '22 08:07 czepiec

There is no window.opener.postMessage message called.

emporioreale avatar Aug 27 '22 16:08 emporioreale

Please read the trouble shooting section at the bottom of the readme.md in

https://github.com/harrowmykel/flutter_web_auth#troubleshooting

harrowmykel avatar Oct 18 '22 15:10 harrowmykel

There is no window.opener.postMessage message called.

Your page must call window.opener.postMessage in order to signal that the authentication is complete.

Is the user redirected to the auth.html page at all?

Please also take a look at the troubleshooting and see if that helps you, if not we can reopen

https://github.com/LinusU/flutter_web_auth#troubleshooting

LinusU avatar Nov 01 '22 08:11 LinusU