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

Unhandled Exception: Bad state: Stream was already listened to #104

Open
avi8dev opened this issue Nov 3, 2023 · 0 comments
Open

Unhandled Exception: Bad state: Stream was already listened to #104

avi8dev opened this issue Nov 3, 2023 · 0 comments

Comments

@avi8dev
Copy link

avi8dev commented Nov 3, 2023

Hey there,

Hoping to get some help on the issue I'm facing. When trying to implement an OIDC connection I get an unhandled exception. The full error I'm getting:

[VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: Bad state: Stream was already listened to
#0      _RawServerSocket.listen (dart:io-patch/socket_patch.dart:1726:7)
#1      new _ForwardingStreamSubscription (dart:async/stream_pipe.dart:114:10)
#2      _ForwardingStream._createSubscription (dart:async/stream_pipe.dart:86:16)
#3      _ForwardingStream.listen (dart:async/stream_pipe.dart:81:12)
#4      _ServerSocket.listen (dart:io-patch/socket_patch.dart:2004:71)
#5      _HttpServer.listen (dart:_http/http_impl.dart:3235:19)
#6      _StreamIterator._initializeOrDone (dart:async/stream_impl.dart:1028:33)
#7      _StreamIterator.moveNext (dart:async/stream_impl.dart:1004:12)
#8      Authenticator._startServer.<anonymous closure>
#9      Authenticator._startServer.<anonymous closure>
openid_client_io.dart:120
#10     _rootRunUnary (dart:async/zone.dart:1434:47)
#11     _CustomZone.runUnary (dart:async/zone.dart:1335:19)

My implementation:

Future<oidc.TokenResponse> authenticate(
      Uri uri, String clientId, List<String> scopes) async {
    var issuer = await oidc.Issuer.discover(uri);
    var client = oidc.Client(issuer, clientId);

    urlLauncher(String url) async {
      if (await canLaunch(url)) {
        await launch(url, forceWebView: true, enableJavaScript: true);
      } else {
        throw 'Could not launch $url';
      }
    }

    var authenticator = oidc.Authenticator(
      client,
      scopes: scopes,
      urlLancher: urlLauncher,
      port: 3000,
      redirectUri: Uri.parse('XXXXX')
    );

    var c = await authenticator.authorize();
    closeWebView();

    var res = await c.getTokenResponse();
    return res;
  }

If more info is needed, please let me know.

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

1 participant