title: Flutter OAuth request fails when using self-signed certificate
body: <p>I have a server that supports oauth2.0 with authorization code grant. server uses a self-signed certificate which i have manually installed on my android device. I am using the standard oauth2 library <a href="https://pub.dev/packages/oauth2" rel="nofollow noreferrer">https://pub.dev/packages/oauth2</a> to perform oauth flow. Now everything works fine until this step</p>
  
  <pre><code>var client = await grant.handleAuthorizationResponse(responseUrl.queryParameters);
  </code></pre>
  
  <p>Where client has to make a post request using code fetched during authorization to get an access token. (see example from <a href="https://pub.dev/packages/oauth2#authorization-code-grant" rel="nofollow noreferrer">https://pub.dev/packages/oauth2#authorization-code-grant</a>)
  here I get a</p>
  
  <pre><code>HandshakeException: Handshake error in client (OS Error: 
  E/flutter (11483):  CERTIFICATE_VERIFY_FAILED: self signed certificate in certificate
  </code></pre>
  
  <p>Now I already know how to allow my certificate or completely bypass certificate check using a HttpClient object. problem is, HttpClient is part of the library dart._http which is under http.dart, but the Client object oauth2.dart uses is from http library under client.dart. even though they both seem to be http clients and support post methods only the former supports a custom SecurityContext. and there's no way apparently I can cast one into the other. I have a two part question:</p>
  
  <ol>
  <li>has anyone had a similar experience with this OAuth2.0 library or know if I can make it work with my self-signed certificate at all?</li>
  <li>my latest idea is to create a custom client class extending http.BaseClient. since I noticed OAuth2.0 only uses post method from the client object I am thinking of overriding this method and use a HttpClient object to perform the post request. however, post method from HttpClient only takes a Uri whereas the one from BaseClient takes in url, headers, body, and encoding. any idea how I can set those on HttpClient's request?</li>
  </ol>
  
  <p>I've also looked into oauth2_client but it doesn't even support a custom http client and oauth_dio but that one only implements client credentials grant whereas my server only supports authorization code grant.</p>