title: OAuth invalid_grant error on coinbase using oauth2_client flutter package
body: <p>I am using the <a href="https://pub.dev/packages/oauth2_client#faq" rel="nofollow noreferrer">oauth2_client package for flutter</a>, connecting to the <a href="https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating" rel="nofollow noreferrer">Coinbase API via OAuth 2.0</a>.</p>
  <p>From what I can tell, Coinbase uses the code flow for authentication. This is the same as Github. This is important to note because I can successfully auth into Github using the oauth2_client package for flutter.</p>
  <p>To connect to Github I used the existing client:</p>
  <pre><code>import 'package:oauth2_client/oauth2_client.dart';
  import 'package:meta/meta.dart';
  
  /// Implements an OAuth2 client against GitHub
  ///
  /// In order to use this client you need to first create a new OAuth2 App in the GittHub Developer Settings (https://github.com/settings/developers)
  ///
  class GitHubOAuth2Client extends OAuth2Client {
    GitHubOAuth2Client(
        {@required String redirectUri, @required String customUriScheme})
        : super(
              authorizeUrl: 'https://github.com/login/oauth/authorize',
              tokenUrl: 'https://github.com/login/oauth/access_token',
              redirectUri: redirectUri,
              customUriScheme: customUriScheme) {
      accessTokenRequestHeaders = {'Accept': 'application/json'};
    }
  }
  </code></pre>
  <p>Then I created a method to call within the app:</p>
  <pre><code>
  void _oauthMethod() async {
      //clientID
      String cID = 'x';
  
      //clientSecret
      String cSecret = 'y';
  
      OAuth2Client client = GitHubOAuth2Client(
          redirectUri: 'my.app://oauth2redirect', customUriScheme: 'my.app');
  
      AccessTokenResponse tknResp = await client.getTokenWithAuthCodeFlow(
          clientId: cID, clientSecret: cSecret, scopes: ['repo']);
  
      http.Response resp = await http.get('https://api.github.com/user/repos',
          headers: {'Authorization': 'Bearer ' + tknResp.accessToken});
     
    }
  
  </code></pre>
  <p>Calling this function brings up the OAuth page for Github, I can sign in, and if I print <code>resp</code> it shows a list of my repos. As expected.</p>
  <p>Using the same method for Coinbase, I first create the new class:</p>
  <pre><code>class MyOAuth2Client extends OAuth2Client {
    MyOAuth2Client(
        {@required String redirectUri, @required String customUriScheme})
        : super(
              authorizeUrl:
                  'https://www.coinbase.com/oauth/authorize', //Your service's authorization url
              tokenUrl:
                  'https://api.coinbase.com/oauth/token', //Your service access token url
              redirectUri: redirectUri,
              customUriScheme: customUriScheme) {
      this.accessTokenRequestHeaders = {'Accept': 'application/json'};
    }
  }
  </code></pre>
  <p>Then I create the method to call:</p>
  <pre><code>void _coinbaseAuth() async {
      String cID = 'x';
      String cSecret = 'y';
      MyOAuth2Client client = MyOAuth2Client(
          redirectUri: 'my.app://oauth2redirect', customUriScheme: 'my.app');
  
      AccessTokenResponse tknResp = await client.getTokenWithAuthCodeFlow(
          clientId: cID, clientSecret: cSecret, scopes: ['wallet:user:read']);
  
      print(tknResp);
  
  
      //code fails 
      //http.Response resp =
      //        await http.get('https://api.coinbase.com/v2/user', headers: {
      //      'Authorization': 'Bearer ' + tknResp.accessToken,
      //      'Content-Type': 'application/json',
      //      'Charset': 'utf-8'
      //    });
  
  
    }
  </code></pre>
  <p>I can't run the http.Response part, because it is filled with nulls. The <code>tknResp</code> prints:</p>
  <blockquote>
  <p>HTTP 401 - invalid_grant The provided authorization grant is invalid,
  expired, revoked, does not match the redirection URI used in the
  authorization request, or was issued to another client.</p>
  </blockquote>
  <p>I have tried creating a new OAuth application in Coinbase, however this doesn't work.</p>
  <p>Does anyone know why I'm getting this error? It's confusing for me as the code worked with Github using the exact same OAuth flow.</p>