2011-01-28 57 views
1

我正在使用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); 
} 

希望有另一種方法。

回答

2

我很欣賞你不想重新編譯庫的願望。但DotNetOpenAuth.ApplicationBlock庫只是DotNetOpenAuth的一個輔助庫,它隨附源碼,因爲它並不真正用於原樣使用。預計您會將源代碼複製並粘貼到您需要的Web應用程序中,然後轉儲剩餘的代碼。例如,在應用程序塊庫中不存在從版本到版本的向後兼容性承諾,例如核心dotnetopenauth.dll文件中存在向後兼容性承諾。

因此,通過一切手段,如果您發現appblock中存在缺陷,您有權自行修復它。

+0

啊,這解釋了爲什麼它不在nuget上。好吧,我猜想最後一件事是嘗試做的事情是讓臉書工作,但我找不到CTP你在說什麼。 http://stackoverflow.com/questions/4821747/facebook-twitter-with-dotnetopenauth – chobo2 2011-01-29 18:36:07