My backend setup follows a structure similar to what is explained in this article.
I am looking to make a GET request using angular.js, just like curl does it, with authorization via HTTP headers:
$ curl -u miguel:python -i -X GET http://127.0.0.1:5000/api/token
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 139
Server: Werkzeug/0.9.4 Python/2.7.3
Date: Thu, 28 Nov 2013 20:04:15 GMT
{
"token": "eyJhbGciOiJIUzI1NiIsImV4cCI6MTM4NTY2OTY1NSwiaWF0IjoxMzg1NjY5MDU1fQ.eyJpZCI6MX0.XbOEFJkhjHJ5uRINh2JA1BPzXjSohKYDRT472wGOvjc"
}
Update:
The answer provided in this post is not the same, as it does not explain how to send both username and password together in the HTTP header. In fact, the solution mentioned there doesn't work at all. It seems that from my question or the one mentioned, it is not clear to a random user how to send username:password via HTTP headers without mentioning base64 encoding yet.
Update 2
A complete and proper solution would be:
$http.get(config.apiUrl + '/api/token', { headers: {'Authorization': 'Basic '+ base64.encode( $scope.username + ':' + $scope.password) } })
Update 3
It turns out this task is more complex than I initially thought, simply passing this dictionary in .get() won't resolve the issue. I found the information in response to this question very useful: How do I get basic auth working in angularjs?