title: angularjs resource Authentication Header based on request body
body: <p>I'm trying to use Resource with APIs protected by HMAC authentication methods. So I need to append "Authentication" header to the request.</p>
  
  <p>In this example code I get the Article from the API with GET and update it with "update" custom method. For the update I need Authentication header. The problem is that <code>$scope.article</code> is <code>undefined</code> when I define the header.</p>
  
  <p><code>getAuth</code> function calculates the sign.</p>
  
  <p>Suggestions?</p>
  
  <pre><code>function EditCtrl($scope,$resource,articleId) {
      var Article = $resource('/blog/articles/:articleId',
      {articleId:articleId}, {
          update: {
              method:'PUT',
              headers: {Authentication: getAuth('key','PUT','/blog/articles/'+articleId,$scope.article)}
          }
      });
  
      var article = Article.get();
      $scope.article = article;
  
      $scope.save = function(){
          article.$update();
      }
  }
  
  function getAuth(key,verb,resource,data) {
      //data is undefined there
  
      content_md5 = CryptoJS.MD5(JSON.stringify(data));
      message = verb+'\n'+resource+'\n'+content_md5;
      hash = CryptoJS.HmacSHA512(message, key);
  
      var sign = "AuthHMAC 0123456789:"+hash.toString(CryptoJS.enc.Base64);
  
      return sign;
  }
  </code></pre>