As far as I can tell from your post you are using Asp.Net WebAPI/MVC as the backend/server technology, I am in the exact same situation plus the fact that I’m using Windows Azure ACS as the authentication system (for that matters), I’ve setup my solution in the following manner:
- I have enabled FormsAuthentication on the server (web.config);
- Configured, in the web.config, a route (/security/signin) to be not secured, so everyone can reach it;
- told to FormsAuth that the login page is “/security/signin”;
What happens when an anonymous users (no formsauth cookie) arrives is that asp.net redirects the user to /security/signin. I have setup 2 different AngularJS SPA, one just for authentication and one for the application.
Side-note: why 2? Because security concerns are important, having 2 completely different applications where moving from one to the other is controlled server side let me with the safety that a power user cannot mess up client side code with F12 browser tools and change the security behavior.
Now, you are an anonymous user and you are redirected in what I call the “acs.app”, one single page with one single view/controller whose role is just to allow the user to perform authentication, authentication is performed “server side” or via the Azure ACS, it is just not relevant to the SPA, the SPA simply sends credentials to the server and wait for an HTTP response, it the response is a redirect it honors it and if the server has set the Auth cookie everything works as expected on the client there is no need to determine if the user is authenticated or not, you just need to authorize the user but that is a different story.
Once the above is setup the browser at each “ajax” call to the WebAPI backend sends back all the cookies and thus you can use standard .net tools to determine on the server if the user is authenticated or not, and in the case he/she is not authenticated you simply returns the correct http response and the only role of the SPA is just to redirect to the login page (or do whatever you like to tell to the user that he/she is not authenticated).
.m
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.
Hi,
You can take a look at the:
http://witoldsz.github.io/angular-http-auth/
It is a working example of the concept described in detail, check the links on that page.
Of course, it does not persist sessions between page reloads (server-side is mocked in that app), but if your server uses cookies, the session will "survive".
Regards,
Witold Szczerba
--
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/WXpabbN38kQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.