I'm implementing a JWT authenfication in AngularJS for front-end and PHP for back-end, and I just set the header authorization :
.run(['$http', function($http) {
$http.defaults.headers.common['Authorization'] = 'Bearer '+localStorage.getItem('tokenAPI');
}])
Since i added this lines , no $_POST variable pass in my POST request
Here is how i send this variables :
let body = new URLSearchParams();
body.set('username', $scope.username);
body.set('password', $scope.pwd);
body.set('project', $rootScope.project);
//Request options
var req = {
method: 'POST',
url: Global.url_api+'action=Connection',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: body.toString()
}
And here how i receive :
$project = $_POST['project'];
$username = $_POST['username'];
$password = $_POST['password'];
Another thing since i added this header, my request method became an Option method not POST anymore.