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?

1
  • 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. Commented May 11, 2015 at 22:33

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.