Logging response and request to OAuth provider <p>Is there a way to capture the response from requests served by OAuth? Specifically, I need to log the request and response from <code>OAuthAuthorizationServerProvider.GrantResourceOwnerCredentials()</code>.</p> <p>I've tried extending <code>OwinMiddleware</code> and overriding <code>Invoke</code> as shown in <a href="http://stackoverflow.com/questions/17679644/owin-onsendingheaders-callback-reading-response-body?lq=1">this post</a>, but I'm unable to read the response body. I'd like to use a message handler as <a href="http://stackoverflow.com/questions/17656066/converting-httprequestmessage-to-owinrequest-and-owinresponse-to-httpresponsemes">this post</a> demonstrates, but I don't have <code>UseHttpMessageHandler</code> on my <code>AppBuilder</code> object.</p> <p>Any help would be greatly appreciated. Thank you!</p> <p><strong>Update</strong></p> <p>Modifying the example provided in Brock's excellent <a href="http://brockallen.com/2014/02/28/lidnug-intro-to-owin-and-katana" rel="nofollow">video</a>, here's what I need to do:</p> <pre class="lang-cs prettyprint-override"><code>public class Startup { public void Configuration(IAppBuilder app) { app.Use(typeof(MW1)); app.Map("/api", fooApp =&gt; { fooApp.Use&lt;MW2&gt;(); }); } } public class MW1 { Func&lt;IDictionary&lt;string, object&gt;, Task&gt; next; public MW1(Func&lt;IDictionary&lt;string, object&gt;, Task&gt; next) { this.next = next; } public async Task Invoke(IDictionary&lt;string, object&gt; env) { var ctx = new OwinContext(env); await next(env); // I need to be able to read: &lt;h1&gt;MW2 called&lt;/h1&gt; written by MW2 var body = ctx.Response.Body; // body.CanRead = False } } public class MW2 { Func&lt;IDictionary&lt;string, object&gt;, Task&gt; next; public MW2(Func&lt;IDictionary&lt;string, object&gt;, Task&gt; next) { this.next = next; } public async Task Invoke(IDictionary&lt;string, object&gt; env) { var ctx = new OwinContext(env); await ctx.Response.WriteAsync("&lt;h1&gt;MW2 called&lt;/h1&gt;"); await next(env); } } </code></pre> <p>I actually need to read the response sent from the OAuth provider, but I assume it would be the same process.</p>