3

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?

Community
  • 1
  • 1
user3407039
  • 1,285
  • 5
  • 25
  • 51
  • 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

1 Answers1

1

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

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

Community
  • 1
  • 1
Nicholas J. Markkula
  • 1,542
  • 4
  • 18
  • 30
  • 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. – Nicholas J. Markkula May 11 '15 at 23:16