MVC3 下的 Facebook OAuth2 和 DotNetOpenAuth
我正在尝试使用 OAuth 在 FB(以及 Twitter)上进行身份验证。查看 DNOA 的 3.5 CTP,我能够使 ASP.NET 示例正常工作。
但我不知道如何将其转换为在 MVC3 中工作。
我尝试了简单的方法,并将示例代码从 FacebookClient.cs 移动到我从控制器操作调用的一个小程序集中,但它在这里死掉了:
client.RequestUserAuthorization();
因为 HTTP 标头已经返回并且无法重写。
所以我尝试修改此调用以返回操作结果:
return client.PrepareRequestUserAuthorization().AsActionResult();
但这失败了,因为它强制浏览器尝试从 facebook 下载某些内容。
有人对如何让我的 MVC3 应用程序通过 Facebook 进行身份验证有任何建议吗?我真的希望 DotNetOpenAuth 的 CTP 包含 OAuth2 身份验证的 MVC 示例;我看到很多人对此表示反对。安德鲁,救救我们!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯……现在使用这个似乎工作得更好了:
看起来 FB 可能一直在调整他们的东西,但我不确定。
Hmmm... things seemt to be working better now, using this:
It seems like FB may have been tweaking things on their end, but I am not sure.