I am creating 1 website using Web api and angular js and i am so much confused about Authentication to be used in my web site.
I have created one login.js in which there would be my Login method which will post my Username/Emailid and password to my Web Api and the method in web api will authenticate that user.
Code:
$scope.Login()
{
$.post("api/Authentication/Login",Username,Password)
{
}
}
Web api code:
[Route]
Public Task<object> Login([FromBody] username,password)
{
//method to authenticate user from database.
//Now the tricky parts comes like after authenticating user should i
//just store the user id in my session like this Session["userid]=id or
//Should i go for storing whole user object in my cookie as i have read
//that storing data in session is very bad idea and disaster too as session is very memory
//and so i think i would go for cookie which will be saved on client side.
//but what if cookie isnt supported by browser??
}
Using session is disaster as pointed out by Darin Dimitrov in his answer and comments. So i have decided to use cookie as per this answer and one of the ecommerce site that is Nop Commerce uses cookie too to store currently login customer object as per this question and answer Question
I am following this code suggested by LukeP in this Question for authentication purpose and maintaining currenlty login user object across my whole appilcation.
I have read about asp.net claim identity too but dont know whether i can use it in my asp.net web api and angular js.
So can anybody tell me whats the correct approach to use for authentication in asp.net web api and angular js and what all the changes to be done in LukeP code to work with web api and angular js??
Can anybody explain me about this appraoch which i have pointed above with some detail description and some codes too as it can help me and some others too if they are searching for the same.
Later i will offer 100 bounty to the answer addressing all above concern with some codes.