title: Handling OAuth token-based authentication with Angular.js?
body: <p>I have set up my back end code in Node.js to authenticate with GitHub successfully using passport. I am able to generate a token using jsonwebtoken. However, I am having trouble managing the front end because of the flow of OAuth.</p>
  
  <p>If this was based on a form where they input the email and password, the view might be a bit like this:</p>
  
  <pre><code>&lt;form ng-submit="login()"&gt;
    &lt;input ng-model="user.email" type="email" name="email" id="email" ng-required /&gt;
    &lt;input ng-model="user.password" type="password" name="password" id="password" ng-required /&gt;
    &lt;button type="submit"&gt;Log in&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>in this flow, a controller could use <code>login()</code> to make a request to a route and receive back an object containing the <code>currentUser</code> and token on success, and redirect on a callback.</p>
  
  <p>The flow of OAuth is causing me some trouble here. In OAuth, you redirect the user off of the site, and it returns to a callback url on the node.js side where the currentUser is set on the server. I don't know how to connect the angular front end to this process.</p>
  
  <p>In angular, how are you supposed to handle this such that clicking a "login with github" button will update <code>$window.sessionStorage.token</code> variable and <code>$rootScope.currentUser</code> object?</p>