coinbase api always 401 unauthorized

Viewed 830

I have waited faithfully for well over 48 hours since generating api keys as suggested and no matter what I do, every coinbase api call gives 401 Unauthorized

  • I have checked basic non-authentication required calls like /time and /exchange_rates and they work fine
  • I am using coinbase and not coinbase pro so this is a simple api key and header based call
  • Have triple checked the hashing and decoding requirements, and nothing is apparent as an issue

Rather than asking to resolve coding problems from the standard examples, the ask is either

  1. Is anyone aware of general authorization issues with the coinbase service right now ? (nothing published by coinbase)
  2. Is there anything outside of the general code samples and documentation that needs to be done to get this damn thing authorizing ?

Any and all help appreciated. References used : https://developers.coinbase.com/docs/wallet/api-key-authentication#

Have added the basic code used for completeness here :

// Remove insecure protocols (SSL3, TLS 1.0, TLS 1.1)
ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls;
ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls11;
// Add TLS 1.2
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

HttpClient client = new HttpClient();   
string sTimeStamp = Convert.ToInt64(DateTime.Now.Ticks).ToString("F0", CultureInfo.InvariantCulture);
client.BaseAddress = new Uri(sUrl + sOperation);

var convertedString = Convert.FromBase64String(sAPI_EXCHANGE_SECRET);
var prehash = sTimeStamp + "GET" + sOperation + "";   // no content for now
string sSignature =  HashString(prehash, convertedString);


// bunch of headers for coinbase
// Add an Accept header for JSON format.
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("User-Agent", "CryptoAppClient");  // arbitrary user agent name
client.DefaultRequestHeaders.Add("CB-ACCESS-KEY", sAPI_EXCHANGE_KEY);
client.DefaultRequestHeaders.Add("CB-VERSION", sAPI_EXCHANGE_VERSION);
client.DefaultRequestHeaders.Add("CB-ACCESS-SIGN", sSignature);
client.DefaultRequestHeaders.Add("CB-ACCESS-TIMESTAMP", sTimeStamp);


// set up the actual call
HttpResponseMessage response = client.GetAsync("").Result;  
.....

//----------------------------------------------------------------------------
private string HashString(string str, byte[] secret)
{
    var bytes = System.Text.Encoding.UTF8.GetBytes(str);
     using (var hmaccsha = new HMACSHA256(secret))
     {
        return Convert.ToBase64String(hmaccsha.ComputeHash(bytes));
      }
}
1 Answers

Finally go it sorted, combination of timestamp value wrong and the right .net functions to encrypt the message

Related