I have two projects, one is asp.net web api and another is angular js. And I want to use token based authentication in api. Now my question is how angular project will connect with api, and where and how to save token in angular project.
login server), then the token usually is stored in a cookie.
Thanks for your post.
According to your description,
Now my question is how angular project will connect with api, and where and how to save token in angular project.
I think store the generated token in client local storage so this token can be sent with each request to access secure resources on the back-end API
The best way to store this token is to use AngularJS module named “angular-local-storage” which gives access to the browsers local storage with cookie
fallback if you are using old browser, so I will depend on this module to store the token .please check this:
#AngularJS Token Authentication using ASP.NET Web API 2, Owin, and Identity
#CRUD with SPA, ASP.NET Web API and Angular.js
Hope this can be helpful.
I have implemented your link example and it works fine. But when I am going to do fluent api, it gives 500 error and it says "Cross-Origin Request Blocked: The Same Origin Policy
disallows reading the remote resource at http://localhost:81/token. This can be fixed by moving the resource to the same domain or enabling CORS".
public class TaskApiContext : DbContext
protected override void OnModelCreating(DbModelBuilder modelBuilder)
If I remove OnModelCreating method then it’s OK.