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
login
method on a service,AuthService
.AuthService.login()
attempts to make an Angular$http
request to/users/me
. - If the user is logged in on the server, their JSON data is returned, and
SessionService.authenticated
is set to true, andSessionService.user
is populated with the user data. - If the user is not logged in, then a 401 response is returned,
SessionService.authenticated = false
andSessionService.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
MainCtrl
tries 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
AuthService
to verify that a user is logged in.