Search code examples
c#.netoauthdotnetopenauthwcf-web-api

Integrating DotNetOpenAuth and WCF WebAPI


I am trying to create a RESTful web service based on WCF Web API. I also need to control access using OAuth and for this I am using the DotNetOpenAuth open source library.

Has anyone ever been successful integrating the two? I am struggling converting from the HTTP entities representations of the WCF Web API into something that's understandable by DNOA (e.g. HTTP requests, HTTP headers, etc...).

Any tip would be greatly appreciated.


Solution

  • Could you be a little more specific?

    In WebAPI a request is represented by the HttpRequestMessage class. A response is represented by the HttpResponseMessage class.

    I've no previous knowledge of DNOA, but from what I saw, you can easily create a HttpRequestInfo from an HttpRequestMessage using the public HttpRequestInfo(string httpMethod, Uri requestUrl, string rawUrl, WebHeaderCollection headers, Stream inputStream).

    The HTTP method and request uri are directly HttpRequestMessage properties. The input stream is obtained via the Content property. I don't see a direct way of creating a WebHeaderCollection from the WebAPI's HttpRequestHeaders. However, you can iterate the HttpRequestHeaders entries and insert then on the WebHeaderCollection one by one.