Skip to content

Support for more native platforms (MacOS, Windows, Linux) #22

Open

Description

@eldadfux

I Really loved this plugin, great work @LinusU. It would be great to see support for more platforms as Flutter is rising to become the leading SDK for cross-platform development.

I think support for macOS, Windows, and Linux for a start would be really helpful. I would have loved to help with this one, but I have no native development experience in any of these platforms.

I saw there is already a PR #20 trying to add macOS support, would be great to see more platforms soon.

  • MacOS
  • Windows
  • Linux

Activity

  1. LinusU commented on Dec 11, 2021

    @LinusU
    Owner

    I've been doing some preliminary research on how to add Windows & Linux support. As far as I can tell, there isn't really an equivalent to an SFAuthenticationSession on these platforms, but I think that we could provide something similar.

    There is already #74 open for Linux support, but I believe that it takes the wrong approach since it shows its own WebView instead of integrating with the user's browser. This means that the user won't be logged in to the services, which I believe the point of this package in. (I think that the other approach is better suited for the flutter_webview package)

    My idea is roughly this, which has to be done independently for Windows & Linux. (and potentially for macOS as well if the users default browser isn't Safari)

    1. Register the app (or probably, a small shim that sends the result to the app) as the protocol handler for callbackScheme
    2. Detect the default browser
    3. Launch the browser with appropriate flags to show the authentication window
    4. Wait for the callback from the browser

    I think that a good approach for developing this would be:

    1. Callback proof of concept:
      1. Create a small binary that writes it arguments into file
      2. Manually register this binary as the protocol handler for any protocol
      3. Manually click a link to this protocol in Chrome/Firefox/Edge
      4. Verify that the full url was written to file
      5. Create a Flutter app and use it instead of the small binary
      6. See if there is a way to get the link via an event, or if it launches a new instance of the Flutter app
    2. Popup proof of concept:
      1. Read the documentation on flags for Chrome/Firefox/Edge
      2. Figure out how to launch a new window, preferably without chrome, to a specific url
      3. Figure out how/if we can close this window programmatically
      4. Try this out together with callback proof of concept
    3. Put everything together:
      1. Set up a new example app for this platform
      2. Create a new platform file in the library
      3. Implement the steps from 1 & 2
      4. Test it
  2. masewo commented on Dec 12, 2021

    @masewo

    @LinusU For Windows and Linux I am using a different approach:
    i. Start a HttpServer that listens on localhost
    ii. Launch url with url_launcher
    iii. Fetch redirect url and serve some HTML content like: Authenticated! You can close this tab.
    Downside of this approach is that there will a useless tab left open for the user. This behaviour can also be seen on other applications (IntelliJ / Github Login).

  3. Jon-Salmon commented on Jan 14, 2022

    @Jon-Salmon

    I have produced a Windows implementation (https://github.com/Jon-Salmon/flutter_web_auth/tree/windows-implementation) but creating a PR is currently blocked by #98

    If anybody wants to use this in the meantime, this is what you would need:

    dependencies:
      flutter_web_auth:
        git:
          url: https://github.com/Jon-Salmon/flutter_web_auth.git
          ref: windows-implementation
          path: flutter_web_auth
    
    dependency_overrides:
      flutter_web_auth_platform_interface:
        git:
          url: https://github.com/Jon-Salmon/flutter_web_auth.git
          ref: windows-implementation
          path: flutter_web_auth_platform_interface
      flutter_web_auth_windows:
        git:
          url: https://github.com/Jon-Salmon/flutter_web_auth.git
          ref: windows-implementation
          path: flutter_web_auth_windows
    
  4. Sesa1988 commented on Jan 26, 2022

    @Sesa1988

    I have produced a Windows implementation (https://github.com/Jon-Salmon/flutter_web_auth/tree/windows-implementation) but creating a PR is currently blocked by #98

    If anybody wants to use this in the meantime, this is what you would need:

    dependencies:
      flutter_web_auth:
        git:
          url: https://github.com/Jon-Salmon/flutter_web_auth.git
          ref: windows-implementation
          path: flutter_web_auth
    
    dependency_overrides:
      flutter_web_auth_platform_interface:
        git:
          url: https://github.com/Jon-Salmon/flutter_web_auth.git
          ref: windows-implementation
          path: flutter_web_auth_platform_interface
      flutter_web_auth_windows:
        git:
          url: https://github.com/Jon-Salmon/flutter_web_auth.git
          ref: windows-implementation
          path: flutter_web_auth_window
    

    Im waiting for the merge, this would be great.

    Im getting an error if I try to integreate your current dependencies.
    Could not find a file named "flutter_web_auth_window/pubspec.yaml" in https://github.com/Jon-Salmon/flutter_web_auth.git

  5. Jon-Salmon commented on Jan 26, 2022

    @Jon-Salmon

    @SergejSachs Typo in my comment, try adding an s

          path: flutter_web_auth_windows
    
  6. Sesa1988 commented on Jan 26, 2022

    @Sesa1988

    @SergejSachs Typo in my comment, try adding an s

          path: flutter_web_auth_windows
    

    Its working but I'm missing how to setup, its different from the current flow.

        final url = Uri.https(EnvironmentHelper.authUrl, {  'provider': 'google', 'redirect_to': "myapp://callback"});
        final String callbackUri = await FlutterWebAuth.authenticate(url: url.toString(), callbackUrlScheme: "myapp");
        final session = await _supabaseClientService.get().auth.getSessionFromUrl(Uri.parse(callbackUri));
        final user = session.user;
    
  7. Sesa1988 commented on Jan 26, 2022

    @Sesa1988

    I changed it to this but it does not get a valid session back:

    'redirect_to': "http://localhost:3000/myapp",
    
    final String callbackUri = await FlutterWebAuth.authenticate(
              url: url.toString(), callbackUrlScheme: "http://localhost:3000/myapp");
    

    The server returns http://localhost:3000/myapp on .authenticate() as URL but without any access token, that's the issue.

    If I pass the URL from the browser to getSessionFromUrl everything works.

    Is something with my scheme wrong?
    I get this in the browser URL:
    http://localhost:3000/cryptowulf#access_token=<token> and refresh token and all other data.

    _server!.listen((req) request doesnt contain the query parameters.

  8. Jon-Salmon commented on Jan 27, 2022

    @Jon-Salmon

    @SergejSachs Yes, you are right you have to use localhost as windows doesn't support custom URI schemes. I would advise checking your browsers network devtools to see what addresses are actually being called.

    You should also probably use a more obscure port. The authentication will fail if something else is using that port on Windows so best practice is to use something random in the 5 digit range.

  9. Sesa1988 commented on Jan 31, 2022

    @Sesa1988

    @Jon-Salmon

    I tried it with other ports as well. The page calls access granted but the returned URL contains only the baseurl.
    Im not sure if supabasees "Additional Redirect URLs" comes in place here and does not allow it.

  10. Sesa1988 commented on May 8, 2022

    @Sesa1988

    Something new on this?

  11. gabrc52 commented on Jan 11, 2023

    @gabrc52

    The URL scheme is probably better, but in the meantime if that's too hard to implement, it's best to first have something than nothing, and a localhost URL works fine.

    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions