title: Authenticate flutter app with keycloak and openid_client
body: <p>I'm trying to authenticate my flutter app to keycloak through <a href="https://pub.dev/packages/openid_client" rel="noreferrer">openid_client</a></p>
  
  <p>following the repo example, I've wrote an authentication function like this</p>
  
  <pre><code>authenticate() async {
  
    // parameters here just for the sake of the question
    var uri = Uri.parse('https://keycloak-url/auth/realms/myrealm');
    var clientId = 'my_client_id';
    var scopes = List&lt;String&gt;.of(['openid', 'profile']);
    var port = 4200;
    var redirectUri = Uri.parse('http://localhost:4200');
  
    var issuer = await Issuer.discover(uri);
    var client = new Client(issuer, clientId);
  
    urlLauncher(String url) async {
      if (await canLaunch(url)) {
        await launch(url, forceWebView: true);
      } else {
        throw 'Could not launch $url';
      }
    }
  
    var authenticator = new Authenticator(client,
        scopes: scopes,
        port: port,
        urlLancher: urlLauncher,
        redirectUri: redirectUri);
  
    var c = await authenticator.authorize();
    closeWebView();
  
    var token= await c.getTokenResponse();
    print(token);
    return token;
  }
  </code></pre>
  
  <p>when I call the function, a webview popup appears and I can login through keycloak, but when the popup closes I get this error at the <code>c.getTokenResponse()</code>:</p>
  
  <blockquote>
    <p>Exception has occurred.
    NoSuchMethodError (NoSuchMethodError: The getter 'length' was called on null.
    Receiver: null
    Tried calling: length)</p>
  </blockquote>
  
  <p>inspecting the Credential <code>c</code>, I can see that the TokenResponse has only "state", "session_state" and "code" fields</p>
  
  <p>what am I missing?</p>