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.
If this was based on a form where they input the email and password, the view might be a bit like this:
<form ng-submit="login()">
<input ng-model="user.email" type="email" name="email" id="email" ng-required />
<input ng-model="user.password" type="password" name="password" id="password" ng-required />
<button type="submit">Log in</button>
</form>
in this flow, a controller could use login() to make a request to a route and receive back an object containing the currentUser and token on success, and redirect on a callback.
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.
In angular, how are you supposed to handle this such that clicking a "login with github" button will update $window.sessionStorage.token variable and $rootScope.currentUser object?
<button ng-click="openWindow()">github login</button>