Search code examples
angularjssymfonygethttp-status-code-401unauthorized

Symfony + AngularJS 401 unauthorized error after Get method


I have some concerns(marigolds) with my method GET when I send my request. I have received an error 401 and I am disconnected from the application, knowing that the token which I obtain in the console is very valid when I test on postman. I does not really understand(include) why that does not work I have to add some things or I have pain make something.

var list = function(){
    var mytoken = window.localStorage.getItem('token');
    return $http({
            method  : 'GET',
            url     : apiEndpoint.url + '/list',
            withCredentials : true,
            headers : {Authorization : 'Bearer ' + mytoken}
        }).then(function(res) {
        console.log(res.data);
    });
}; 

If somebody could me helped please, thank you :)


Solution

  • I think that she uses of the angularJS in her project, while RequestOptions is a class which we find that in Angular 2. That's why the import does not work

    It must be added in the conf of apache:

    SetEnvIf Authorization. + HTTP_AUTHORIZATION = $ 0
    

    It should work for your case :)