Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET web service using forms authentication from a windows app

Tags:

asp.net

I have an ASP.NET web service that I can access via a windows program but now I want to secure the web service. I can secure the web service using forms authentication. How do you access the secured web service from a windows forms application?

like image 540
Rob Avatar asked Nov 05 '22 14:11

Rob


1 Answers

Although this is not the right approach, tt is theoretically possible to use forms authentication in the manner you describe. This could be accomplished by either:

  1. Using a WebRequest to send your requests in raw form to the web service. This will involve inspecting the response, extracting the relevant forms-authentication fields, and sending a response back which logs the user in. This will generate a cookie which you must send along with each subsequent response to the service
  2. Generate the FormsAuhentication authentication cookie yourself. This is complex as it involves synchronising the machine key on the calling application, and artificially manipulating the headers being sent to the machine hosting the service.
  3. Display the forms-authentication form for the user to log in to at the beginning of a session requiring interaction with the web-service. You can then harvest the generated cookie and present it to the service in HTTP headers as in option (2).

As you can see, these methods are highly complex, and are fundamentally a hack to use forms-authentication where it was never intended.

Microsoft intended us to use either Windows authentication, or SSL certs to secure access to ASP.NET web services. See HTTP Security and ASP.NET Web Services on MSDN.

If you are able to use WCF, then a few more options present themselves, including the ability to build a custom authentication mechanism into the SOAP, with some support from WCF.

For the most part, securing web services is one of the trickiest parts of the job. Many live solutions which I have seen are compromises such as the ones above.

like image 127
goofballLogic Avatar answered Nov 15 '22 05:11

goofballLogic