I have an existing WEB API 2 project with JWT authentication.
how I merge my WEB API application so it's similar like Administration project.
the route will be something like localhost/api/[myApiRoute]
I know there's an alternative way using plugin, but I got a dead end implementing JWT and my customization handler.
Asked
Active
Viewed 742 times
0

vantian
- 848
- 3
- 10
- 25
-
web api version ? how about just adding a reference to Nop.Web ? – Idrees Khan Jan 07 '16 at 07:11
-
@DotNetDreamer does it mean my WEB API would run under NOP.WEB project? – vantian Jan 07 '16 at 07:28
-
yes. and you have to add the Startup file to Nop.Web as well. Your web api will be in different solution project just like you said. You can make it as a plugin but in any case, you have to add `Startup.cs` file you Nop.Web – Idrees Khan Jan 07 '16 at 07:34
1 Answers
0
So I ended up by adding a Web API to NOP.WEB project.
The steps I needed to perform were:
- Add Web API Packages (How to add Web API to an existing ASP.NET MVC 4 Web Application project?)
- Add OWIN Packages (http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/)
- Configure the
Startup.cs
now you can use [System.Web.Http.Authorize]
attribute to authorize your API using OWIN Authentication.
I also add new folder called API and put all API files there (Controller, Models, Provider, Handlers, etc.) so it would easy to maintain.
For API routing, I'm using Attribute Routing (http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2). you can add config.MapHttpAttributeRoutes()
at Startup.cs