我正在使用dotnetopenauth库,我试图找出如何更改回调url。dotnetopenauth - 更改twitter的回叫网址?
我在看样品文件
public partial class SignInWithTwitter : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (TwitterConsumer.IsTwitterConsumerConfigured) {
this.MultiView1.ActiveViewIndex = 1;
if (!IsPostBack) {
string screenName;
int userId;
if (TwitterConsumer.TryFinishSignInWithTwitter(out screenName, out userId)) {
this.loggedInPanel.Visible = true;
this.loggedInName.Text = screenName;
// In a real app, the Twitter username would likely be used
// to log the user into the application.
////FormsAuthentication.RedirectFromLoginPage(screenName, false);
}
}
}
}
protected void signInButton_Click(object sender, ImageClickEventArgs e) {
TwitterConsumer.StartSignInWithTwitter(this.forceLoginCheckbox.Checked).Send();
}
因此,这是所有的,什么是需要欢送到Twitter上请求(web表单的MVC略有不同)。
我想改变,响应回来过的网址(我宁愿有一个单独作用的结果。
现在好像StartSignInWithTwitter()是它设置URL。
/// <summary>
/// Prepares a redirect that will send the user to Twitter to sign in.
/// </summary>
/// <param name="forceNewLogin">if set to <c>true</c> the user will be required to re-enter their Twitter credentials even if already logged in to Twitter.</param>
/// <returns>The redirect message.</returns>
/// <remarks>
/// Call <see cref="OutgoingWebResponse.Send"/> or
/// <c>return StartSignInWithTwitter().<see cref="MessagingUtilities.AsActionResult">AsActionResult()</see></c>
/// to actually perform the redirect.
/// </remarks>
public static OutgoingWebResponse StartSignInWithTwitter(bool forceNewLogin) {
var redirectParameters = new Dictionary<string, string>();
if (forceNewLogin) {
redirectParameters["force_login"] = "true";
}
Uri callback = MessagingUtilities.GetRequestUrlFromContext().StripQueryArgumentsWithPrefix("oauth_");
var request = TwitterSignIn.PrepareRequestUserAuthorization(callback, null, redirectParameters);
return TwitterSignIn.Channel.PrepareResponse(request);
}
这似乎是硬编码为得到上下文的当前请求。是否有可能以某种方式重写此没有我真正改变这行代码和重新编译的.dll?
编辑 现在我对.dll进行了更改 - 我真的不喜欢这种方式,因为现在我需要支持一个自定义版本。
public static OutgoingWebResponse StartSignInWithTwitter(bool forceNewLogin) {
Uri callback = MessagingUtilities.GetRequestUrlFromContext().StripQueryArgumentsWithPrefix("oauth_");
return StartProcess(forceNewLogin, callback);
}
private static OutgoingWebResponse StartProcess(bool forceNewLogin, Uri callback)
{
var redirectParameters = new Dictionary<string, string>();
if (forceNewLogin)
{
redirectParameters["force_login"] = "true";
}
var request = TwitterSignIn.PrepareRequestUserAuthorization(callback, null, redirectParameters);
return TwitterSignIn.Channel.PrepareResponse(request);
}
public static OutgoingWebResponse StartSignInWithTwitter(bool forceNewLogin, Uri callback)
{
return StartProcess(forceNewLogin, callback);
}
希望有另一种方法。
啊,这解释了为什么它不在nuget上。好吧,我猜想最后一件事是尝试做的事情是让脸书工作,但我找不到CTP你在说什么。 http://stackoverflow.com/questions/4821747/facebook-twitter-with-dotnetopenauth – chobo2 2011-01-29 18:36:07