ASP.NET Web API - Authentication in a Windows Forms Application

I developed a web system using ASP.NET MVC 4 and I have to integrate using the .NET Web API and the Windows Forms application.

So far, everything was fine, but now I need to authenticate users using the Windows Forms application, and this application will be open on the Internet.

My application already contains users who are registered in the database and are currently authenticated using the Authorize component of ASP.NET MVC.

To use data through the client (Windows Forms application), I currently use the ASP.NET Web Client API library.

How can I complete this task safely? Anyone have any suggestions?

+4
source share
2 answers

You can extend HttpClient to add authentication. One example can be found here . It shows how to add an HttpMessageHandler to your pipeline for OAuth authentication.

Here is a complete list of ASP.NET Web APIs and HttpClient Samples

+3
source

Take a look at this Q&A that describes how to create a custom AuthorizeAttribute for the web API, which also authenticates the user using basic HTTP security and capturing credentials from the HTTP header. Note that there is another AuthorizeAttribute attribute for the ASP.NET Web API (System.Web.Http.AuthorizeAttribute), not one for the MVC controller (System.Web.Mvc.AuthroizeAttribute). They have different behaviors. You do not want the web API call redirected to the login page.

0
source

Source: https://habr.com/ru/post/1445760/


All Articles