'Authorization header malformed WP JWT Authentication for WP REST API

I have managed to get the token using user and pass and now I am passing the token using this ajax call in order to create a new post , like this :

$.ajax({
            url: "http://apibind.com/wp/wp-json/wp/v2/posts",
            type: "POST",               
            headers: { "Authorization": "Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" },
            success: function (data) {
            console.log(data);
            },
            error:function(data){
              console.log(data);
            }
        });

and I get this error : Authorization header malformed . Anyone knows what is wrong with the header?



Solution 1:[1]

simple misstake : Bearer instead of Basic (I'm using a token based authorization)

Solution 2:[2]

Remove the JWT related plugins from your WordPress(for my case , it's "Simple JWT Login"). They help if you are developing mobile apps for site but they interfere with the rest api call.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andreea Onica
Solution 2 zawhtut