Proposed improvement to user authentication for the MEAN boilerplate. See linnovate/mean#121
- An express route for
/auth/<service_provider>uses passport to redirect to the oauth service provider - The OAuth provider redirects back to
/auth/<service_provider>/callback - Finally, Express redirects to
/. Once authenticated, user data is available as JSON from/users/me.
- There is a main controller set on the body element,
MainCtrl. - It calls the
loginmethod on a service,AuthService.AuthService.login()attempts to make an Angular$httprequest to/users/me. - If the user is logged in on the server, their JSON data is returned, and
SessionService.authenticatedis set to true, andSessionService.useris populated with the user data. - If the user is not logged in, then a 401 response is returned,
SessionService.authenticated = falseandSessionService.user = null
- To logout, a user is directed to an Express route,
/logout. This route calls passport'sreq.logout()method, and then redirects to/. - Upon redirect, the angular app is reloaded, and
MainCtrltries to callAuthService.login(), getting a 401 error.
- An auth token shared between the server-side Node layer and client-side Angular layer, to verify client's identity (I think?). See https://github.com/mrgamer/angular-login-example
- Additional logic in
AuthServiceto verify that a user is logged in.