Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect url after login in Flutter web does not work #99

Closed
2 tasks done
volkanustekidag opened this issue Feb 27, 2024 · 4 comments
Closed
2 tasks done

Redirect url after login in Flutter web does not work #99

volkanustekidag opened this issue Feb 27, 2024 · 4 comments
Assignees
Labels
invalid This doesn't seem right

Comments

@volkanustekidag
Copy link

Description

I'm trying to provide login using package in a web application. I open the link I created and log in, but the tab is closed and I cannot receive the code I expect. I couldn't understand what I was missing.

Minimal Reproduction

Steps to reproduce the behaviour:

  1. Use the following code:
    final authorizationUrl = Uri.https(
        ServicesConstants.authorizationUrlProd, '/connect/authorize', {
      'response_type': 'code',
      'client_id': newClientId,
      'redirect_uri': "worksy://auth",
      'grant_type': 'authorization_code',
      'code_challenge': codeChallenge,
      'code_challenge_method': 'S256',
      'scope': 'openid profile offline_access email',
      'state': _generateRandomString(16),
      'nonce': _generateRandomString(16),
      'prompt': 'login'
    });
    
      final result = await FlutterWebAuth2.authenticate(
        url: authorizationUrl.toString(),
        callbackUrlScheme: "worksy",
      );
    
      final code = Uri.parse(result).queryParameters['code'];
    

<!DOCTYPE html>
<title>Authentication complete</title>
<p>Authentication is complete. If this does not happen automatically, please close the window.</p>
<script>
    function postAuthenticationMessage() {
        const message = {
            'flutter-web-auth-2': window.location.href
        };

        if (window.opener) {
            window.opener.postMessage(message, window.location.origin);
            window.close();
        } else if (window.parent && window.parent !== window) {
            window.parent.postMessage(message, window.location.origin);
        } else {
            localStorage.setItem('flutter-web-auth-2', window.location.href);
            window.close();
        }
    }

    postAuthenticationMessage();
</script>

Exception or Error

It does not redirect after login and the expected code is not returned

Expected Behaviour

Redirect after login and continue from the first tab

Screenshots

a

Additional context

No response

Device

Mac

OS

MacOS

Browser

Chrome

Flutter version

Channel stable, 3.13.5,

flutter_web_auth_2 version

flutter_web_auth_2 3.1.1

Checklist

  • I have read and followed the entire troubleshooting guide and it has not provided the solution I need.
  • I have provided all the information I can.
@volkanustekidag volkanustekidag added the bug Something isn't working label Feb 27, 2024
@ThexXTURBOXx
Copy link
Owner

You need to follow exactly the steps in https://github.com/ThexXTURBOXx/flutter_web_auth_2?tab=readme-ov-file#web
If you are building a Flutter Web application, you should not redirect to some URL scheme, but your redirect URL needs to point to the auth.html file that is provided in the setup guide.

@ThexXTURBOXx ThexXTURBOXx added invalid This doesn't seem right and removed bug Something isn't working labels Feb 27, 2024
@stan-at-work
Copy link

stan-at-work commented May 13, 2024

You need to follow exactly the steps in https://github.com/ThexXTURBOXx/flutter_web_auth_2?tab=readme-ov-file#web If you are building a Flutter Web application, you should not redirect to some URL scheme, but your redirect URL needs to point to the auth.html file that is provided in the setup guide.
@ThexXTURBOXx

Why is http://localhost:5200/auth.html not a valid callbackUrlScheme ?

It get's blocked by the _assertCallbackScheme function.

The regex: RegExp(r'^[a-z][a-z\d+.-]*$') does not allow this: http://localhost:5200/auth.html.

Can you give an example of a valid callbackUrlScheme on WEB ?

If u use Microsoft you can't add a callbackUrlScheme in the settings without providing the prefix: http://...

@ThexXTURBOXx
Copy link
Owner

@stan-at-work Because you are supposed to provide a callback URL scheme, not a full URL.
Furthermore, as seen in this line, on Web the callback URL scheme gets ignored anyway, so just provide anything (in your case, just supply http).
In general, this is a case of RTFM.

Your comment does also seem to be not related to this issue - so for the future, open an own issue for that.
I will also close this issue here as stale.

@stan-at-work
Copy link

@stan-at-work Because you are supposed to provide a callback URL scheme, not a full URL. Furthermore, as seen in this line, on Web the callback URL scheme gets ignored anyway, so just provide anything (in your case, just supply http). In general, this is a case of RTFM.

Your comment does also seem to be not related to this issue - so for the future, open an own issue for that. I will also close this issue here as stale.

Thanks, that works. You should really consider adding this to the documentation:

Web: callbackscheme = 'http'

This would help ALLOT.

Thanks for the quick response :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants