我正在尝试使用DotNetOpenAuth 4.1.0.12182为Facebook和Windows 创建用户登录名。
但是,下载中的示例使用了当前版本中不存在的DotNetOpenAuth.ApplicationBlock和DotNetOpenAuth.ApplicationBlock.Facebook。
相反,有一个DotNetOpenAuth.AspNet.Clients名称空间,它包括FacebookClient和WindowsLiveClient,但是我找不到如何使用这些名称空间的任何示例。
是否存在任何示例或文档?
发布于 2012-07-25 19:12:58
通过创建一个从DotNetOpenAuth.OAuth2.WebServerClient派生的FacebookAuthClient,我已经能够让DNOAVersion4.1.0.12182、.Net 3.5和Facebook相互协作。我发现的一个小问题是,如果您使用基于cookie的会话,那么您必须在使用OAuth功能之前访问该会话。据我所知,这是因为DNOA使用会话ID作为状态参数,如果会话从未被访问过,则可以在请求之间进行更改。当响应从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);
}
}
}这只是一个测试应用程序,所以没有错误处理,但它似乎是有效的。
编辑I为所有这些使用了DotNetOpenAuth(统一) NuGet包。
编辑在创建ClientCredentialApplicator时添加了缺少的.PostParameter调用。
发布于 2012-07-23 09:38:50
您需要使用ctp版本3.5的DNOA。4+版本是用来处理后来的OAuth 2的草稿,然后是Facebook使用的。
你可以在所有者GitHub:https://github.com/AArnott/dotnetopenid上找到它
https://stackoverflow.com/questions/11581776
复制相似问题