Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Could you please let me know what is the best way to secure the Web API calls.

As you might already know, URL is enough to call and get the data from the Web API if we don't secure it. Ours is a intranet application, but we would like to restrict the access to web api only from the application, not by hitting url from the browser.

Thank you.
Posted
Comments
Afzaal Ahmad Zeeshan 12-Nov-15 8:31am    
There are many possible answers for this question. They all depend on the purpose of securing, like security from what? Hack attacks, SQL injections, what?

Hi,
For a Intranet Web App , you can Set a private key in your App config.
For every user who first login into your App sends his credential over HTTP and get a unique identifier (Token) which will be used further on every call to HTTP Web API in header. On the Server side, you can decrypt the token using the private key.

This might help you
http://programmers.stackexchange.com/questions/196421/what-are-the-best-practices-to-secure-a-web-api[^]

Thanks
 
Share this answer
 
v2
You need to send your token with each request in the Authorization Header.
Try this out[^].
 
Share this answer
 
Comments
Ravindranath.net 12-Nov-15 8:26am    
the user comes to our application from a different application which is not a .Net application, and we don't authenticate user other than validation his windows user id against the transaction info they pass. How Can I generate the token in that case?
Web API is actually accessible through HTTP protocol, it doesn't say whether it is accessed by a web browser or an application. Web API would always respond to requests coming on HTTP, web browsers do send the requests through HTTP, that is why Web API is always accessible from a web browser whereas in case of an application you have to use libraries.

Now, the concept of securing them (as already stated in the comment to your question) depends entirely on how you want to secure the application. There may be many ways to do this (to accept a few requests and not accept the others), but simplest would be to add a QueryString to the URL to trigger the Web API, otherwise, send a 503 (Service Unavailable; to the web browser). For example you may consider accepting the URLs like,

http://www.yourwebsite.com/api/controller?from_app=true


But that still doesn't secure your website, because anyone can write that in the URL that is why you should consider creating and using a token for your users or applications. A token like GUID[^] that cannot be guessed by an ordinary user but your application knows it.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900