Search code examples
jsonauthenticationcurltoken

Passing X-Authentication via CURL on command line


I'm trying to curl a URL using GET which requires authorisation but no matter how I pass the token, I'm getting this returned:

{
  "response": {
    "error": "Authentication required",
    "error_code": 1
  }
}

I've asked the developer of the API I'm using but all I've been told is "The token must be included in the X-Authorization HTTP header" which doesn't tell me what I'm doing wrong.

Here's an example of one of the commands I've tried:

curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer MyTokenGoesHere" -k https://example.com/SomeFolder/endofAPIURL?ArgumentOne=foo&ArgumentTwo=bar

I've tried multiple ways to pass the token but I'm clearly doing something wrong because none of them seem to be even passing the token as I'm getting "Authentication required" instead of incorrect/invalid.

Here are all the ways I've tried passing the token:

-H "Authorization: MyTokenGoesHere"
-H "Authorization: Basic MyTokenGoesHere"
-H "Authorization: Bearer MyTokenGoesHere"
-H "Authorization: Oauth MyTokenGoesHere"
-H "X-Auth-Token: MyTokenGoesHere"
-H "X-Auth-Token: Basic MyTokenGoesHere"
-H "X-Auth-Token: Bearer MyTokenGoesHere"
-H "X-Auth-Token: Oauth MyTokenGoesHere"

All of these different ways of passing the token have been taken from various posts on this site.

I feel I'm missing something obvious but I just can't see it.


Solution

  • So it turns out that the API was using a custom header but didn't have it documented anywhere. The documentation provided also used X-Auth-Token (which I believe is custom in itself but could be mistake) which is why I was trying that.

    In my particular case, what I needed was -H "AuthTo: MyTokenGoesHere"