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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
kfhohn
  • 135
  • 1
  • 3
  • 7

1 Answers1

0

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

Eric.guo
  • 74
  • 14
  • It ended up being an issue on the server side, but still upvoting because this is a good suggestion. :) – kfhohn Mar 08 '16 at 22:17