dart-lang / tools

This repository is home to tooling related Dart packages.
BSD 3-Clause "New" or "Revised" License
30 stars 21 forks source link

Login with Firefox #383

Open markbeij opened 9 months ago

markbeij commented 9 months ago

I have an app that uses oauth2 for login. On Android with Chrome as the default browser everything works as expected. When Firefox is your default browser however, it does not work. I use lanchUrl to open the login page and then wait untill the login is finished,

Code:

await launchUrl(
  loginUri,
  mode: LaunchMode.inAppBrowserView,
  webOnlyWindowName: '_self',
);

final incomingUri = await _appLinks.uriLinkStream.first;

client = await grant.handleAuthorizationResponse(
  incomingUri.queryParameters,
);

Relevant dependencies:

oauth2: ^2.0.2
url_launcher: ^6.2.1
app_links: ^3.4.5

After login, the app look like it restarts and comes up with a new login screen. For Chrome however the app gets resumed and I can store the access token and have a happy life.

Chrome

I/flutter ( 3127): appstate = AppLifecycleState.inactive
I/flutter ( 3127): appstate = AppLifecycleState.hidden
I/flutter ( 3127): appstate = AppLifecycleState.paused //After this, the login screen shows
I/flutter ( 3127): appstate = AppLifecycleState.hidden
I/flutter ( 3127): appstate = AppLifecycleState.inactive
I/flutter ( 3127): appstate = AppLifecycleState.resumed //After this, I can require an access token

Firefox

I/flutter ( 3697): appstate = AppLifecycleState.inactive
I/flutter ( 3697): appstate = AppLifecycleState.hidden
I/flutter ( 3697): appstate = AppLifecycleState.paused //After this, the login screen shows
I/flutter ( 3697): appstate = AppLifecycleState.inactive
I/flutter ( 3697): appstate = AppLifecycleState.hidden
I/flutter ( 3697): appstate = AppLifecycleState.paused //After this, the login screen shows

This doesn't seem the perfect place to ask this question, but someone has any tips.

markbeij commented 9 months ago

Also created issue in url_launcher repo: https://github.com/flutter/flutter/issues/141601