Subscription Authentication Error

Here is one of the subscription messages that was sent which resulted in the authentication error message:

{“api_key”:“xxx”,“channel”:“level2”,“product_ids”:[“BTC-USD”],“signature”:“1b51efa99e695460d3a1a0f2eef2d628e561d060e86ccf7b98600936ad496baf”,“timestamp”:1673721105,“type”:“subscribe”}

Authentication error just means that your signature is wrong, there is nothing more informative coinbase could provide…

Maybe try to set timestamp in subscribe message as string?

For me it was the conversion to hex that was messing with the subscription. Its been so long since I’ve looked at c++… what does your prehash look like?

And yes timestamp should be a string

Hi muktupavels. Good suggestion regarding changing the type of the timestamp to string. I changed this line:

root[“timestamp”] = now

to

root[“timestamp”] = std::to_string(now);

however I still get an authentication error when subscribing.

I have a test where I generate the signature using crypto-js in javascript. The signature matches the output of my c++ signature based on the same inputs.

An error message something like

{“type”:“error”,“message”:“authentication failure - invalid signature”}

would be more helpful, don’t you think?

This is what my pre-hash looks like:

1673722981level2BTC-USD

Yes, error message can be better… What I meant was that coinbase can not provide more info why your signature is wrong.

Are you sure that your API key and/or secret is correct?

Yes, I just checked that the api_key and secret that I am using are correct.

Here is an example of generating the signature using javascript. The secret is not a valid one, it’s from an api_key that was deleted.

const CryptoJS = require(‘crypto-js’);
console.log('signature: ’ + ‘1673628642level2BTC-USD’);
console.log('secret: ’ + ‘s146NOJtMeGgZ6SbIRblSJCWIcMUCauX’);
const hash = CryptoJS.HmacSHA256(‘1673628642level2BTC-USD’, ‘s146NOJtMeGgZ6SbIRblSJCWIcMUCauX’);
console.log(hash.toString());

This is the output: cd400f44fce2e88c6b6a6a1fa298b112aec7706d7a9540cded0331bed54c09c8

If these same inputs are used using the c++ code I provided the exact same output is produced.

Same output just shows that you are generating signature correctly. As other things looks correct my guess is that there are some problems with api key and/or secret.

Thanks muktupavels, I agree with your guess. I have a support ticket opened with coinbase. They weren’t able to provide any insight and suggested I post to this forum. I’ll get back to them with your suggestion about verifying that the api key and secret that I am using are valid.