Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook OAuth2 with DotNetOpenAuth under MVC3

I'm trying to authenticate on FB (and Twitter, also) using OAuth. Looking at the 3.5 CTP for DNOA, I was able to get the ASP.NET sample working.

But I'm lost about how to convert it to work in MVC3.

I tried the naïve approach and moved the sample code from FacebookClient.cs into a small assembly that I call from a controller action, but it dies here:

client.RequestUserAuthorization();

due to the fact that the HTTP headers have already been returned and cannot be re-written.

So I tried modifying this call to return an action result:

return client.PrepareRequestUserAuthorization().AsActionResult();

But this fails as it forces the browser to try and download something from facebook.

Does anybody have any advice on how I can get my MVC3 app to authenticate against facebook? I really wish DotNetOpenAuth's CTP included an MVC sample of OAuth2 authentication; I see a LOT of people banging their head against this. Andrew, save us!

like image 621
TimH Avatar asked Dec 20 '25 07:12

TimH


1 Answers

Hmmm... things seemt to be working better now, using this:

fbClient.PrepareRequestUserAuthorization().Send();

It seems like FB may have been tweaking things on their end, but I am not sure.

like image 124
TimH Avatar answered Dec 22 '25 20:12

TimH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!