0

I'm having the same issue described in this question: Angularjs set a authorization header

I need to include an authorization token in my request headers. I have tried this using a few methods- I tried setting $http defaults as follows:

app.config(function($httpProvider) {
    $httpProvider.defaults.headers.common['Authorization'] = '1234567';
});

and also like this:

app.run(function($http) {
    $http.defaults.headers.common['Authorization'] = '1234567';
});

Additionally I tried structuring my requests like this in a method on my service:

var request = {
    method: 'GET',
    url: 'my/api/endpoint',
    headers: {
        'Authorization': '1234567'
    }
};

$http(request).then(function(response) {
    console.log(response);
});

In all of these cases, what I end up seeing in my request headers looks like this:

Access-Control-Request-Method: GET
Origin: http://localhost:8000
Access-Control-Request-Headers: accept, authorization
Accept: */*
Referer: http://localhost:8000/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8

I would expect to see another key-value pair in there, like:

Authorization: '1234567'

But, I don't.

I'm using Angular version 1.4.9, I wonder if this issue is specific to this version?


Solved: It turned out this was resolved in Apache configuration server-side. However- it's worth noting that the authorization headers are actually included in the preflight request header rather than the main request, which is why it appeared to not be in the header.

0

1 Answer 1

0

I do it in Interceptor which can intercept all requests and add Auth to header.Maybe you can try it . [like this

Sign up to request clarification or add additional context in comments.

1 Comment

It ended up being an issue on the server side, but still upvoting because this is a good suggestion. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.