Michel Andrade
Michel Andrade

Reputation: 4196

ASP.NET Web API - Authetication in Windows Forms Application

I developed a web system using ASP.NET MVC 4 and I must perform an integration using .NET Web API and Windows Forms Application.

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

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

For data consumption through the client (Windows Forms Application) currently I use the library Microsoft ASP.NET Web Client API.

How can I accomplish this task safely? Does anyone have any suggestions?

Upvotes: 5

Views: 3790

Answers (2)

Kevin Junghans
Kevin Junghans

Reputation: 17540

Take a look at this Q&A which describes creating a custom AuthorizeAttribute for Web API that also authenticates the user using http basic security and grabbing the credentials from the HTTP header. Note that there is a different AuthorizeAttribute for ASP.NET Web API (System.Web.Http.AuthorizeAttribute) as opposed to the one for an MVC controller (System.Web.Mvc.AuthroizeAttribute). They have different behaviors. You do not want a call to a Web API being redirected to a logon page.

Upvotes: 0

Wouter de Kort
Wouter de Kort

Reputation: 39898

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

Here is the complete List of ASP.NET Web API and HttpClient Samples

Upvotes: 4

Related Questions