title: AngularJS - store basic authentication on login
body: <p>I'm banging my head on a wall with this - I'm relatively new to working with APIs and have yet to do anything that requires authentication. </p>
  
  <p>I'm stuck with sending a POST request to the API. The endpoint for creating a piece of content is:</p>
  
  <pre><code>/entity/node
  </code></pre>
  
  <p>I can send a successful POST request if I send the following:</p>
  
  <pre><code>headers: {
         "Authorization": "Basic YWRtaW46MTIzcXdl", //admin:123qwe
     },
  </code></pre>
  
  <p>The problem I am having is with Authorization. I'm specifying Basic and then an encoded string here, which is my admin login. So when hardcoded, I can post.</p>
  
  <p>My question - when the user logs in correctly, I need the headers to be set so that all future post requests work. How can I do this in AngularJS?</p>
  
  <p>I have tried passing a dynamically generated code:</p>
  
  <pre><code>"Authorization": "Basic " + auth,
  </code></pre>
  
  <p>where <strong>auth</strong> is a base64 encoded user:pass, but this does not work. My thinking is that this value needs to be stored somewhere for retrieval whenever a POST request is made. But how?</p>