Facebook C#SDK-服务器流身份验证 [英] Facebook C# SDK - Server flow authentication

查看:104
本文介绍了Facebook C#SDK-服务器流身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用通过NuGet安装的Facebook C#SDK,以允许用户使用Facebook登录到我的网站.在我发现的所有C#SDK文档中,访问令牌都是使用JavaScript SDK获得的.我想在不使用JavaScript SDK的情况下完成整个身份验证流程服务器端.

I am using the Facebook C# SDK installed using NuGet to allow user's to login to my site using Facebook. In all the C# SDK documentation that I've found, the access token was obtained using the JavaScript SDK. I want to do the entire authentication flow server side without using JavaScript SDK.

  1. 在哪里可以找到有关使用Facebook C#SDK进行完整服务器端身份验证所需遵循的步骤的良好文档或示例代码?

  1. Where can I find good documentation or sample code for the steps I need to follow for complete server side authentication using the Facebook C# SDK?

将C#SDK和JavaScript SDK结合起来是否有优势,还是仅坚持服务器端流程是否可以?

Is there any advantage of combining C# SDK and JavaScript SDK, or is it fine to stick to server side flow only?

推荐答案

服务器端身份验证与客户端相同,您使用 RedirectUri 之类的参数将用户重定向到OAuth对话框,然后您 AppId .然后,使用参数 code 将用户重定向到 RedirectUri ,现在您向服务器端发出将代码转换为访问令牌的请求.

Server side authentication is same as client side, you redirect user to OAuth Dialog with parameters like RedirectUri and you AppId. Then user is redirected to RedirectUri with parameter code and now you make server side request to convert code to access token, thats all.

http://developers.facebook.com上阅读用于服务器端身份验证的文档/docs/authentication/server-side/

如何与Facebook C#SDK交换用户访问令牌代码?

How to exchange the code for a User Access Token with Facebook C# SDK?

var fb = new FacebookClient();
dynamic response = fb.Get("oauth/access_token", 
        new
        { 
            client_id = APP_ID,
            redirect_uri = "http://www.example.com/",
            client_secret = SECRET_ID,
            code = CODE
        })
//response.access_token
//response.expires

这篇关于Facebook C#SDK-服务器流身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆