In this article, we will discuss about solving curl token "The input is not a valid base 64 encoded string" error. curl is a very popular open source tool used in both Linux and Windows based system to manage APIs call. Although curl is an excellent CLI based tool but sometimes it can cause frustrations with different error that you might get while passing headers and data. One such error that can cause your life miserable is the Unauthorized Token error which usually comes when you are trying pass the authorization bearer token through curl utility. Here we will see all the possible scenarios which can cause this error and how to solve it.
Solved: curl token "The input is not a valid base 64 encoded string" error
Also Read: How do I install the linux library libc.so.6 in 5 Easy Steps
Ideally there could be lot of situations due to which you might get "Unauthorized Token. The input is not a valid base 64 encoded string"
error while trying to use the bearer token. But here we will discuss two of the most common scenarios that can cause this error.
Scenario #1: Using braces with bearer token
This is the most common error done mostly by the newbies or beginners where a braces is used with the bearer token. Let's try to understand this through below curl example. In the given below example, we are sending a POST
request to update the color of Customer's car.
NOTE:
$token
variable. If you want you can also pass it directly without using any variable. It all depends on you and how you would like to pass it.cyberithub@ubuntu:~$ curl -X POST https://app.cyberithub.com/service/car/color -H "Content-Type: application/json" -H "Authorization: Bearer {$token}" -H "apikey: KVb86hgodjdhiq47odjio759GDHjud38" -d "<some_data>" -k
But when you run the above request, you will end up having "Token can not be verified. The input is not a valid base 64 encoded string"
error with https status code 401
. This is simply because of the use of braces with bearer token. So, to solve the above error, you need to simply remove the braces and run the above curl request again as shown below.
cyberithub@ubuntu:~$ curl -X POST https://app.cyberithub.com/service/car/color -H "Content-Type: application/json" -H "Authorization: Bearer $token" -H "apikey: KVb86hgodjdhiq47odjio759GDHjud38" -d "<some_data>" -k
You will notice that your error will be solved and you will be able to send the POST request.
Scenario #2: Using Incorrect base64 encoded string
The other most common scenario is that URL does expecting bearer token in base64 encoded format but the passed string is either in plain text or not encoded properly using base64 encoding. So to solve this problem you need to encode the token properly. If you are using a Linux or Unix based system then you should have a utility called base64
installed in your System. You can check How to Perform base64 Encoding and Decoding Using Linux Command Line to know more about this utility. So if you need to pass base64 encoded bearer token then you need to first encode it using below command.
cyberithub@ubuntu:~$ echo -n '<authorization_token>' | base64
Then take the output and pass the encoded string to the Authorization header(-H). Then run the curl POST
request again. You will notice that you will not get "Unauthorized token. The input is not a valid base 64 encoded string"
error again.
Hope above solution helped you solving "Unauthorized token. The input is not a valid base 64 encoded string"
error if you are also getting this. Please let me know your feedback in the comment box !!