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

Exception thrown in flutter_example/lib/openid_browser.dart #76

Closed
hubertvolz opened this issue Jan 4, 2023 · 5 comments
Closed

Exception thrown in flutter_example/lib/openid_browser.dart #76

hubertvolz opened this issue Jan 4, 2023 · 5 comments

Comments

@hubertvolz
Copy link

Unfortunately the throw Exception('Will never reach here'); is executed:

Future<Credential> authenticate(Client client,
    {List<String> scopes = const []}) async {
  var authenticator = browser.Authenticator(client, scopes: scopes);

  authenticator.authorize();

  throw Exception('Will never reach here');
}

output:

The Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9105?uri=http://127.0.0.1:50809/w5nk5QXjN2k=

Error: Exception: Will never reach here

    at Object.throw_ [as throw] (http://localhost:50669/dart_sdk.js:5241:11)
    at authenticate (http://localhost:50669/packages/example/openid_browser.dart.lib.js:38:17)
    at authenticate.next (<anonymous>)
    at runBody (http://localhost:50669/dart_sdk.js:40595:34)
    at Object._async [as async] (http://localhost:50669/dart_sdk.js:40626:7)
    at Object.authenticate (http://localhost:50669/packages/example/openid_browser.dart.lib.js:26:18)
    at main._MyHomePageState.new.<anonymous> (http://localhost:50669/packages/example/main.dart.lib.js:466:58)
    at Generator.next (<anonymous>)
    at runBody (http://localhost:50669/dart_sdk.js:40595:34)
    at Object._async [as async] (http://localhost:50669/dart_sdk.js:40626:7)
    at http://localhost:50669/packages/example/main.dart.lib.js:464:145
    at ink_well._InkResponseState.new.handleTap (http://localhost:50669/packages/flutter/src/material/icon_button.dart.lib.js:42992:31)
    at tap.TapGestureRecognizer.new.invokeCallback (http://localhost:50669/packages/flutter/src/gestures/recognizer.dart.lib.js:214:18)
    at tap.TapGestureRecognizer.new.handleTapUp (http://localhost:50669/packages/flutter/src/gestures/tap.dart.lib.js:429:20)
    at [_checkUp] (http://localhost:50669/packages/flutter/src/gestures/tap.dart.lib.js:220:12)
    at tap.TapGestureRecognizer.new.handlePrimaryPointer (http://localhost:50669/packages/flutter/src/gestures/tap.dart.lib.js:167:23)
    at tap.TapGestureRecognizer.new.handleEvent (http://localhost:50669/packages/flutter/src/gestures/recognizer.dart.lib.js:474:16)
    at [_dispatch] (http://localhost:50669/packages/flutter/src/gestures/pointer_router.dart.lib.js:89:9)
    at http://localhost:50669/packages/flutter/src/gestures/pointer_router.dart.lib.js:115:26
    at LinkedMap.new.forEach (http://localhost:50669/dart_sdk.js:27933:11)
    at [_dispatchEventToRoutes] (http://localhost:50669/packages/flutter/src/gestures/pointer_router.dart.lib.js:113:29)
    at pointer_router.PointerRouter.new.route (http://localhost:50669/packages/flutter/src/gestures/pointer_router.dart.lib.js:108:37)
    at binding$5.WidgetsFlutterBinding.new.handleEvent (http://localhost:50669/packages/flutter/src/gestures/binding.dart.lib.js:377:26)
    at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:50669/packages/flutter/src/gestures/binding.dart.lib.js:365:24)
    at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:50669/packages/flutter/src/rendering/view.dart.lib.js:680:13)
    at [_handlePointerEventImmediately] (http://localhost:50669/packages/flutter/src/gestures/binding.dart.lib.js:341:14)
    at binding$5.WidgetsFlutterBinding.new.handlePointerEvent
    (http://localhost:50669/packages/flutter/src/gestures/binding.dart.lib.js:311:43)
    at [_flushPointerEventQueue] (http://localhost:50669/packages/flutter/src/gestures/binding.dart.lib.js:300:14)
    at [_handlePointerDataPacket] (http://localhost:50669/packages/flutter/src/gestures/binding.dart.lib.js:288:38)
    at Object.invoke1 (http://localhost:50669/dart_sdk.js:196999:7)
    at _engine.EnginePlatformDispatcher.new.invokeOnPointerDataPacket (http://localhost:50669/dart_sdk.js:172339:15)
    at [_onPointerData] (http://localhost:50669/dart_sdk.js:173317:49)
    at http://localhost:50669/dart_sdk.js:173842:30
    at http://localhost:50669/dart_sdk.js:173785:9
    at loggedHandler (http://localhost:50669/dart_sdk.js:173490:11)
    at http://localhost:50669/dart_sdk.js:173408:91
    at Object._checkAndCall (http://localhost:50669/dart_sdk.js:5438:16)
    at Object.dcall (http://localhost:50669/dart_sdk.js:5443:17)
    at ret (http://localhost:50669/dart_sdk.js:62137:21)
Flutter Web Bootstrap: Programmatic

Steps to reproduce:

  • start keycloak as mentioned in example.md
  • flutter run -d chrome
  • press login button

The error happens after pressing the Login button in chrome and before Login Screen of keycloak is shown.

Everything works fine if I run flutter run -d macos.

@rbellens
Copy link
Contributor

rbellens commented Jan 4, 2023

Ok, that's unfortunate indeed, but if I understand correctly, you are still redirected to the login screen and you are still able to login?

I should probably replace that line with a never completing Future.

@hubertvolz
Copy link
Author

Yes, I got redirected and I'm able to login, so your code works perfectly. Only the exception was misleading me.

@gitvadim
Copy link

gitvadim commented Aug 20, 2023

Faced the same issue, however got it fixed by changing the method a bit into:

void authenticate(Client client, {List<String> scopes = const []}) {
  var authenticator = browser.Authenticator(client, scopes: scopes);
  authenticator.authorize();
}

Can someone please explain to me why the original method in the example is async to begin with and its signature says it's returning a Future<Credential> if it's not returning anything?

@LinetCheese
Copy link

LinetCheese commented Sep 6, 2023

It seems just making the authenticate() function call the authorize() like @gitvadim wrote above is enough - just need to reduce the Login button callback to it:

// ...
OutlinedButton(
    child: const Text('Login'),
    onPressed: () {
      authenticate(client, scopes: scopes);
    }),
// ...

Still feels awkward for a solution though...

Edit: removed forgotten async from the callback.

@rbellens
Copy link
Contributor

should be fixed in version 0.4.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants