appsup-dart / openid_client

Library for working with OpenID Connect and implementing clients.
BSD 3-Clause "New" or "Revised" License
89 stars 117 forks source link

OS Error: Address already in use, errno = 48 #100

Open harshitwe360 opened 1 year ago

harshitwe360 commented 1 year ago

I'm using opened_client for keycloak authentication and its working fine in android devices but when I run in IOS simulator it will throw error

  Unhandled Exception: SocketException: Failed to create server socket (OS Error: Address already in use, errno = 48), address = 0.0.0.0, port = 8765
  #0      _NativeSocket.bind (dart:io-patch/socket_patch.dart:1030:7)
  <asynchronous suspension>
  #1      Authenticator.authorize (package:openid_client/openid_client_io.dart:87:5)

// and the code I used

Future<bool> keyClockAuth() async  {

   String urlStr = domain.apiKeycloakRealm!=null
        ? "${domain.apiKeycloakUrl}/realms/${domain.apiKeycloakRealm}/"
        : AppConstants.keycloakUrl;
    Uri uri = Uri.parse(urlStr);

    // create the client
    var issuer = await Issuer.discover(uri);
    var client = Client(issuer, clientId);

    // create a function to open a browser with an url
    urlLauncher(String url) async {
      if (await canLaunchUrlString(url)) {
        await launchUrlString(url);
      } else {
        throw 'Could not launch $url';
      }
    }

    // create an authenticator
    var authenticator = Authenticator(client, port: 8765,
        urlLancher: urlLauncher);

    // starts the authentication
    var c = await authenticator.authorize();

    // close the webview when finished
    closeInAppWebView();

}

Thankyou

rbellens commented 1 year ago

did you try using another port?