title: How make basic http authorization with angular.js?
body: <p>My backend is structured similar to <a href="http://blog.miguelgrinberg.com/post/restful-authentication-with-flask" rel="nofollow noreferrer">this</a> article.</p>
  
  <p>So I would like to send GET request with angular.js similar to how curl does it, authorizing via http headers:</p>
  
  <pre><code>$ 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"
  }
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/11876777/angularjs-set-http-header-for-one-request">This</a> is not duplicate, answer doesn't describe how to send username and password together in http header, also last comment states that solution doesn't work at all. And please notice not even from my question or that question is possible to understand for random user how to send username:password via http headers.. nobody told anything about base64 yet.. ?:)</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>and full and normal answer IS:</p>
  
  <pre><code>$http.get(config.apiUrl + '/api/token', { headers: {'Authorization': 'Basic '+ base64.encode( $scope.username + ':' + $scope.password) } })
  </code></pre>
  
  <p><strong>Update 3</strong></p>
  
  <p>This is not easy as I thought, passing this dictionary in .get() won't solve anything. I found this answer helpfull: <a href="https://stackoverflow.com/questions/17959563/how-do-i-get-basic-auth-working-in-angularjs">How do I get basic auth working in angularjs?</a></p>