title: AngularJS using RESTful web service authentication
body: <p>I am trying to build an AngularJS app that would require users to login. </p>
  
  <p>When they first visit the application, they would get redirected to a login page (<a href="http://domain.my:3000/login">http://domain.my:3000/login</a>). When the user enters his username and password, a webservice will be called (<a href="http://domain.my:4788/WebServices/user/login?username=XXX&amp;password=YYYY">http://domain.my:4788/WebServices/user/login?username=XXX&amp;password=YYYY</a>) which returns JSON data with the user's id, name, etc. that would need to be stored somewhere (cookies/localstorage?).</p>
  
  <p>How could I go about doing that? Would I need to create a server (on nodejs perhaps) to handle the requests to the web service or would an angularjs service suffice? </p>
  
  <pre><code>app.service("UserService", function($http) {
  }
  </code></pre>
  
  <p>My idea was to create a service in angular that would do all the work (create cookie/entry in localstorage) while the login controller would authenticate the user using $http.</p>
  
  <p>I have looked into things Passport with local strategy or examples like <a href="https://github.com/fnakstad/angular-client-side-auth">https://github.com/fnakstad/angular-client-side-auth</a>, but I don't think they cover what I'm trying to achieve or I can't simply understand them.</p>
  
  <p>I hope this is not too general of a question and thanks in advance for any replies.</p>