gpt4 book ai didi

Facebook 与 DotNetOpenAuth 4.1.0.12182

转载 作者:行者123 更新时间:2023-11-30 05:23:28 25 4
gpt4 key购买 nike

我正在尝试使用 DotNetOpenAuth 4.1.0.12182

创建 Facebook 和 Windows LiveId 的用户登录名

但是,下载中的示例使用了当前版本中不存在的 DotNetOpenAuth.ApplicationBlockDotNetOpenAuth.ApplicationBlock.Facebook

取而代之的是 DotNetOpenAuth.AspNet.Clients 命名空间,其中包括 FacebookClientWindowsLiveClient - 但是我找不到任何示例说明如何使用这些。

是否存在任何示例或文档?

最佳答案

通过创建从 DotNetOpenAuth.OAuth2.WebServerClient 派生的 FacebookAuthClient,我已经能够让 DNOA 版本 4.1.0.12182、.Net 3.5 和 Facebook 相互协作。我发现的一个小问题是,如果您使用基于 cookie 的 session ,那么您必须在使用 OAuth 功能之前访问该 session 。据我所知,这是因为 DNOA 使用 session ID 作为状态参数,如果 session 从未被访问过,它可以在请求之间更改。当响应从 Facebook 返回时,这将导致状态参数不匹配错误。

FacebookAuthClient:

public class FacebookAuthClient : DotNetOpenAuth.OAuth2.WebServerClient
{
private static readonly DotNetOpenAuth.OAuth2.AuthorizationServerDescription Description = new DotNetOpenAuth.OAuth2.AuthorizationServerDescription
{
TokenEndpoint = new Uri("https://graph.facebook.com/oauth/access_token"),
AuthorzationEndpoint = new Uri("https://graph.facebook.com/oauth/authorize")
};

public static readonly string [] ScopeNeeded = { "publish_stream" };

public FacebookAuthClient()
: base(Description)

{
}
}

Facebook.aspx.cs:

public partial class FacebookPage : System.Web.UI.Page
{
private FacebookAuthClient _client = new FacebookAuthClient
{
ClientIdentifier = ConfigurationManager.AppSettings["FBClientId"], //The FB app's Id
ClientCredentialApplicator = DotNetOpenAuth.OAuth2.ClientCredentialApplicator.PostParameter(ConfigurationManager.AppSettings["FBClientSecret"]) // The FB app's secret
}
protected void Page_Load(object sender, EventArgs e)
{
DotNetOpenAuth.OAuth2.IAuthorizationState auth = _client.ProcessUserAuthorization();
if (_auth == null)
{
// Kick off authorization request with the required scope info
client.RequestUserAuthorization(FacebookAuthClient.ScopeNeeded);
}
}
}

这只是一个测试应用,因此没有错误处理,但它似乎可以工作。

编辑我使用 DotNetOpenAuth(统一)NuGet 包来完成所有这些。

编辑添加了缺少的 .PostParameter 调用以创建 ClientCredentialApplicator。

关于Facebook 与 DotNetOpenAuth 4.1.0.12182,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11581776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com