Hana Aanaa

Hana Aanaa

  • NA
  • 38
  • 561

How to store cookies in Asp.Net Identity for webApi

Apr 15 2019 9:29 AM
Hello all,
 
I have Asp.net web Application project with WebApi and individuals user Account. I implemented Registration and login, and I used angularjs in front end.
 
Now, I need to store cookies in browser.
 
I'm confused if authentication based on cookies store cookies in browser?
 
In my project I authenticate users based on token.
 
I do research but it confuse me and I did't find a clear guide to store cookies using Asp.Net Identity webApi?
 
Also, I don't understand if I need to use claims?
 
This is the mothed for check user authentication:
  1. public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)  
  2. {  
  3. var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();  
  4. ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);  
  5. if (user == null)  
  6. {  
  7. context.SetError("invalid_grant""The user name or password is incorrect.");  
  8. return;  
  9. }  
  10. ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager);  
  11. ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager);  
  12. AuthenticationProperties properties = CreateProperties(user.UserName);  
  13. AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);  
  14. context.Validated(ticket);  
  15. context.Request.Context.Authentication.SignIn(cookiesIdentity);  
  16. }  

Answers (1)