flutter_web_auth
flutter_web_auth copied to clipboard
Support for more native platforms (MacOS, Windows, Linux)
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.
- [x] MacOS
- [ ] Windows
- [ ] Linux
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)
- Register the app (or probably, a small shim that sends the result to the app) as the protocol handler for
callbackScheme
- Detect the default browser
- Launch the browser with appropriate flags to show the authentication window
- Wait for the callback from the browser
I think that a good approach for developing this would be:
- Callback proof of concept:
- Create a small binary that writes it arguments into file
- Manually register this binary as the protocol handler for any protocol
- Manually click a link to this protocol in Chrome/Firefox/Edge
- Verify that the full url was written to file
- Create a Flutter app and use it instead of the small binary
- See if there is a way to get the link via an event, or if it launches a new instance of the Flutter app
- Popup proof of concept:
- Read the documentation on flags for Chrome/Firefox/Edge
- Figure out how to launch a new window, preferably without chrome, to a specific url
- Figure out how/if we can close this window programmatically
- Try this out together with callback proof of concept
- Put everything together:
- Set up a new example app for this platform
- Create a new platform file in the library
- Implement the steps from 1 & 2
- Test it
@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).
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
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
@SergejSachs Typo in my comment, try adding an s
path: flutter_web_auth_windows
@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;
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.
@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.
@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.
Something new on this?
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.