title: Symfony2 RESTful API + AngularJS
body: <p>I've been working on an e-commerce project built on Symfony2 (for the backend) and AngularJS for the frontend. Currently the Symfony part is used only as an API, which has three different user levels (guest, customer &amp; admin). Different actions that can be done within the system (like add/remove data) are secured by:</p>
  <ol>
  <li>Symfony2 firewall with user roles/access control <br /></li>
  <li>JMS security extra (@PreAuthorize expressions)</li>
  </ol>
  <p>For the parts that are secure everything works as intended and I'm very happy with the way things work.</p>
  <p><strong>Problem:</strong></p>
  <p>There are parts of the API which are public (like retrieving product information, categories, etc.). I'm retrieving such data in Angular with Ajax calls to my API that returns the data in JSON format. One example would be:</p>
  <blockquote>
  <p>/api/product/get-all/?page=1&amp;count=10&amp;sorting[id]=asc</p>
  </blockquote>
  <p>The problem is that anyone could look at the requests in browser and copy the path and have access to all the data (such as all the products) and could just download a JSON of all the information. Although this data is &quot;public&quot;, I don't want to give others such an easy way of &quot;stealing&quot; my data.</p>
  <p><strong>Ideas &amp; possible solutions:</strong></p>
  <ol>
  <li>I was looking at the JWT (Json Web Token) standard to try and secure the public calls to my API and implement it in such a way that I generate a token for &quot;real&quot; users that are on the website, and such limit direct access to public API links.</li>
  </ol>
  <p>What do you think? Would this be a possible solution?</p>
  <ol start="2">
  <li><p>I was also reading in some other question on StackOverflow that I could check the HTTP_X_REQUESTED_WITH header from the request, but we all know this can be easily spoofed by an attacker.</p>
  </li>
  <li><p>Finally, I read a similar approach to &quot;solution&quot; 1) here : <a href="http://engineering.talis.com/articles/elegant-api-auth-angular-js/" rel="nofollow noreferrer">http://engineering.talis.com/articles/elegant-api-auth-angular-js/</a> but I'm not entirely sure that this fits my purpose.</p>
  </li>
  </ol>
  <p>Additional notes:</p>
  <ul>
  <li>I don't want to make this bullet-proof, but I also don't want to give people the option to click 2 buttons and get all my data. I know that eventually all the information can be &quot;stolen&quot; (e.g.: by using a web <strong>scraper</strong> ), but &quot;securing&quot; the system in such a way that people would have to make a bit of an effort is what I have in mind.</li>
  <li>I can't really re-model my API too much at this stage, but any ideas would be appreciated</li>
  </ul>
  <p>Thanks for taking the time to read my question and I'm looking forward for any feedback.</p>