0

I'm looking for a way to do token authentication for the Web API controllers I have created within an MVC 5 application (I need a way to do it without creating a separate Web API project within the solution). My endpoints are in the Controllers folder at the project level and the controller types are Web API 2 Controllers. How can I generate a token for a user that logs in on the mobile application that uses the Web API and use that token for the endpoints that are contained in the API?

  • https://stackoverflow.com/a/38661720/4228458 – CodingYoshi Jul 23 '18 at 17:03
  • As I said in my post, my project is an MVC 5 project so I need it to work within that project. – Christian Chavez Jul 23 '18 at 17:11
  • You can use existing frameworks that work with MVC5 (it's not a "separate project") or cobble your own. What are you looking for? – EdSF Jul 23 '18 at 18:00
  • The Api controllers that are already working exist in the MVC project, so I need a way to setup token authorization works with those endpoints – Christian Chavez Jul 23 '18 at 18:31
  • Go through [this resource](https://learn.microsoft.com/en-us/aspnet/web-api/overview/security/authentication-and-authorization-in-aspnet-web-api#authorization) for your options. As stated, you can _use_ and implement frameworks, or write something like a custom `AuthorizationFilterAttribute` based on how you want to implement your stated token based access (e.g. `JWT`) - which you'll also have to build into your process (_how_ do clients send your app the `token` it expects). – EdSF Jul 23 '18 at 20:52
  • You can try this one .I implemented and its working good. http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/ – Tonmoy Saha Jul 24 '18 at 06:11

0 Answers0