Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have recently started learning AngularJS and I'm trying to create a simple login system. Some of the methods for creating and storing a cookie for authorisation looked a lot more complicated than the .net approach I was use to so my first thought was to keep using that method of authentication by doing a call to the API and keeping the angular UI side free of all that.

This option was suggested in this post here -

How to handle authentication in Angular JS application

However when I try to implement this it authenticates fine, but it does not save this cookie. If I access the API again and try anything referencing the cookie like,

FormsAuthentication.GetAuthCookie(userName, createPersistentCookie);

It will just say that there is nothing there.

Is there a simple way of retaining this cookie in the API that I am not using?

share|improve this question
1  
The new standard for authentication with SPA and Web Apps is using JSON Web Tokens (JWT). Using JWT, all your security information is encapsulated in a token which can be encrypted, and all the authentication data can be serialized on either side, including claims, roles, grants, etc. – Claies May 11 '15 at 22:33

Here is how you can do it, this will also let you include custom information with the auth cookie.

http://stackoverflow.com/a/10524305/1121845

share|improve this answer
    
Hi, thanks for the response. I won't be able to try this out till tomorrow but I assume the difference is with this that the HttpCookie should remain persistent between API calls unlike the FormsAuthentication AuthCookie? – user3407039 May 11 '15 at 22:51
    
Yes, the FormsAuthentication.GetAuthCookie method only creates a new cookie. It does not get you the earlier made cookie. The Response.Cookies[FormsAuthentication.FormsCookieName] on the other hand will get you the existing auth cookie. – nickmkk May 11 '15 at 23:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.