Lydia Ra
Lydia Ra

Reputation: 155

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 :)

Upvotes: 2

Views: 400

Answers (2)

DaxDev
DaxDev

Reputation: 651

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 :)

Upvotes: 1

Marcin.ka
Marcin.ka

Reputation: 87

Please check it like below:

        let headers = new Headers();
    headers.append('Authorization', 'Bearer ' + YourToken);

    let options = new RequestOptions({ headers: headers });

    this.http.get('YourUrl', options)

This should work

Upvotes: 0

Related Questions