Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate SAML authentication into WCF web service application

Tags:

wcf

saml

saml-2.0

I have a WCF web service application built and tested on IIS7. Regarding authentication I wanted to implement a sql server hosted userd id and password authentication for consumers accessing the operations in the web service. However I was told that my company policy dictates that I implement SAML into my web service. That means any client that is accessing my web service operations need to be authenticated using SAML 2.0. I am not familiar with SAML but like to know and get started on how to implement it within my web serivice. I keep hearing two terms - Service Provider and Identity Provider, based on definitions on the web, I am assuming the service provider is my web service. identity provider is where the user authenticates to and the identity provider provides a assertion to my web service and then I let the client access the operations. I understand the theory but not sure how to put into practical implementation. Clients accessing my web service are not internal , i.e. they are external (extranet clients), so in this case what will be the identity provider and how do I add code to my web serice to make it a service provider?

I hope you understand my dilemma, can anyone explain the approach I need to take and any samples or tutorials that help me complete the web service is greatly appreciated.

like image 986
wcfvemi Avatar asked Sep 04 '11 04:09

wcfvemi


2 Answers

I think SAML 2.0 is not provided by standard WCF. To make it work you must combine WCF with WIF (Windows identity foundation). Here you have very complex example of usage WCF with WIF and claim based authorization. The example uses SAML 1.1 but it is only configuration change to make it work with SAML 2.0.

Your problem is generally called Federated authentication or Federated identity where user authenticates against STS (service token service) and it receives security token (it can be for example SAML token). Than the client calls real service (RP - relaying party) where it passes its security token. So what are you going to build? If your company policy demands SAML usage they most probably already have STS and you just need to authenticate clients by SAML tokens as mentioned in the article.

like image 172
Ladislav Mrnka Avatar answered Sep 22 '22 14:09

Ladislav Mrnka


Since 2011, support for Claims-Aware WCF Services has apparently improved with the release of .NET 4.5. I'll copy info from that article in case it ever changes, but as of the time of this answer, the process appeared to be as simple as:

  1. Adding a reference to WIF (Microsoft.IdentityModel.dll) in your WCF Service project. Since this is delivered with .NET 4.5, I do not believe a NuGet package is necessary.

  2. Use the following code sample to create a self-hosted Claims-Aware service:

    var host = new ServiceHost(typeof(ClaimsAwareWebService), new Uri("myUri")); FederatedServiceCredentials.ConfigureServiceHost(host);

    host.Open();

  3. Set your WCF service to use the federatedServiceHostConfiguration Behavior Extension.

like image 33
Peder Rice Avatar answered Sep 19 '22 14:09

Peder Rice