Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / C#

Digest Authentication on a WCF REST Service

Rate me:
Please Sign up or sign in to vote.
4.95/5 (27 votes)
27 Feb 2011CPOL10 min read 158K   3.3K   65  
An article that explains Digest Authentication and a library to use Digest Authentication with WCF Rest and validate against any back-end.
//-----------------------------------------------------------------------
// <copyright file="DigestHeaderParser.cs" company="http://www.semanticarchitecture.net">
//     (C) Patrick Kalkman pkalkie@gmail.com
// </copyright>
//-----------------------------------------------------------------------
namespace DigestAuthenticationOnWCF
{
   /// <summary>
   /// This class is responsible for parsing and creating the digest header that is available
   /// in the incoming message.
   /// </summary>
   internal class DigestHeaderParser
   {
      private readonly HeaderKeyValueSplitter keyValueSplitter;

      public DigestHeaderParser(HeaderKeyValueSplitter keyValueSplitter)
      {
         this.keyValueSplitter = keyValueSplitter;
      }

      public virtual DigestHeader Parse(string digestHeaderString)
      {
         string headerString = RemoveDigestFromHeaderString(digestHeaderString);
         var header = new DigestHeader();
         string[] keyValueCombinations = headerString.Split(',');
         foreach (string keyValueCombination in keyValueCombinations)
         {
            HeaderKeyValue headerKeyValue = keyValueSplitter.Split(keyValueCombination);
            header.Set(headerKeyValue);
         }

         return header;
      }

      private static string RemoveDigestFromHeaderString(string headerString)
      {
         return headerString.Replace("Digest", string.Empty);
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Architect http://www.simpletechture.nl
Netherlands Netherlands
Patrick Kalkman is a senior Software Architect with more than 20 years professional development experience. He works for SimpleTechture where he helps teams develop state of the art web applications.

Patrick enjoys writing his blog. It discusses agile software development. Patrick can be reached at patrick@simpletechture.nl.

Published Windows 8 apps:


Published Windows Phone apps:


Awards:

Best Mobile article of March 2012
Best Mobile article of June 2012

Comments and Discussions