OSDN Git Service

bit.ly API キーの検証を行わず、URL短縮の実行時に認証情報の有無のみ確認する
authorKimura Youichi <kim.upsilon@bucyou.net>
Fri, 28 Apr 2017 18:12:39 +0000 (03:12 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Fri, 28 Apr 2017 18:43:11 +0000 (03:43 +0900)
OpenTween/Api/BitlyApi.cs
OpenTween/AppendSettingDialog.Designer.cs
OpenTween/AppendSettingDialog.cs
OpenTween/Properties/Resources.Designer.cs
OpenTween/Properties/Resources.en.resx
OpenTween/Properties/Resources.resx
OpenTween/ShortUrl.cs
OpenTween/Tween.cs

index 4dcb73e..5f41afc 100644 (file)
@@ -86,38 +86,6 @@ namespace OpenTween.Api
             }
         }
 
-        public bool ValidateApiKey(string login, string apiKey)
-            => this.ValidateApiKeyAsync(login, apiKey).Result;
-
-        public async Task<bool> ValidateApiKeyAsync(string login, string apikey)
-        {
-            try
-            {
-                var requestUri = new Uri(ApiBase, "/v3/validate");
-                var param = new Dictionary<string, string>
-                {
-                    ["login"] = ApplicationSettings.BitlyLoginId,
-                    ["apiKey"] = ApplicationSettings.BitlyApiKey,
-                    ["x_login"] = login,
-                    ["x_apiKey"] = apikey,
-                    ["format"] = "txt",
-                };
-
-                using (var postContent = new FormUrlEncodedContent(param))
-                using (var response = await this.http.PostAsync(requestUri, postContent).ConfigureAwait(false))
-                {
-                    var responseText = await response.Content.ReadAsStringAsync()
-                        .ConfigureAwait(false);
-
-                    return responseText.TrimEnd() == "1";
-                }
-            }
-            catch (OperationCanceledException) { }
-            catch (HttpRequestException) { }
-
-            return false;
-        }
-
         private IEnumerable<KeyValuePair<string, string>> CreateAccessTokenParams()
         {
             if (string.IsNullOrEmpty(this.EndUserAccessToken))
index 2444320..06a67eb 100644 (file)
             this.Save.Name = "Save";
             this.ToolTip1.SetToolTip(this.Save, resources.GetString("Save.ToolTip"));
             this.Save.UseVisualStyleBackColor = true;
-            this.Save.Click += new System.EventHandler(this.Save_Click);
             // 
             // Cancel
             // 
             this.Cancel.Name = "Cancel";
             this.ToolTip1.SetToolTip(this.Cancel, resources.GetString("Cancel.ToolTip"));
             this.Cancel.UseVisualStyleBackColor = true;
-            this.Cancel.Click += new System.EventHandler(this.Cancel_Click);
             // 
             // ColorDialog1
             // 
index 3b26776..4ed41fd 100644 (file)
@@ -51,8 +51,6 @@ namespace OpenTween
         internal Twitter tw;
         internal TwitterApi twitterApi;
 
-        private bool _ValidationError = false;
-
         public AppendSettingDialog()
         {
             this.InitializeComponent();
@@ -151,45 +149,6 @@ namespace OpenTween
             }
         }
 
-        private void Save_Click(object sender, EventArgs e)
-        {
-            if (MyCommon.IsNetworkAvailable() &&
-                (this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Bitly || this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Jmp))
-            {
-                // bit.ly 短縮機能実装のプライバシー問題の暫定対応
-                // bit.ly 使用時はログインIDとAPIキーの指定を必須とする
-                // 参照: http://sourceforge.jp/projects/opentween/lists/archive/dev/2012-January/000020.html
-                if (string.IsNullOrEmpty(this.ShortUrlPanel.TextBitlyId.Text) || string.IsNullOrEmpty(this.ShortUrlPanel.TextBitlyPw.Text))
-                {
-                    MessageBox.Show("bit.ly のログイン名とAPIキーの指定は必須項目です。", Application.ProductName);
-                    _ValidationError = true;
-                    TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
-                    TreeViewSetting.Select();
-                    this.ShortUrlPanel.TextBitlyId.Focus();
-                    return;
-                }
-
-                var bitly = new BitlyApi();
-                if (!bitly.ValidateApiKey(this.ShortUrlPanel.TextBitlyId.Text, this.ShortUrlPanel.TextBitlyPw.Text))
-                {
-                    MessageBox.Show(Properties.Resources.SettingSave_ClickText1);
-                    _ValidationError = true;
-                    TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
-                    TreeViewSetting.Select();
-                    this.ShortUrlPanel.TextBitlyId.Focus();
-                    return;
-                }
-                else
-                {
-                    _ValidationError = false;
-                }
-            }
-            else
-            {
-                _ValidationError = false;
-            }
-        }
-
         private void Setting_FormClosing(object sender, FormClosingEventArgs e)
         {
             if (MyCommon._endingFlag) return;
@@ -201,10 +160,6 @@ namespace OpenTween
                     e.Cancel = true;
                 }
             }
-            if (_ValidationError)
-            {
-                e.Cancel = true;
-            }
             if (e.Cancel == false && TreeViewSetting.SelectedNode != null)
             {
                 var curPanel = (SettingPanelBase)TreeViewSetting.SelectedNode.Tag;
@@ -359,11 +314,6 @@ namespace OpenTween
             this.GetPeriodPanel.LabelUserStreamActive.Visible = tw.UserStreamActive;
         }
 
-        private void Cancel_Click(object sender, EventArgs e)
-        {
-            _ValidationError = false;
-        }
-
         private void OpenUrl(string url)
         {
             string myPath = url;
index 9b2f03b..a4bc25f 100644 (file)
@@ -2541,15 +2541,6 @@ namespace OpenTween.Properties {
         }
         
         /// <summary>
-        ///   IDとAPIキーの組み合わせが違います。IDと同時に設定するのはパスワードではなくAPIキーです。ご確認ください。 に類似しているローカライズされた文字列を検索します。
-        /// </summary>
-        internal static string SettingSave_ClickText1 {
-            get {
-                return ResourceManager.GetString("SettingSave_ClickText1", resourceCulture);
-            }
-        }
-        
-        /// <summary>
         ///   フォロー状況取得中・・・ に類似しているローカライズされた文字列を検索します。
         /// </summary>
         internal static string ShowFriendshipText1 {
@@ -3189,6 +3180,15 @@ namespace OpenTween.Properties {
         }
         
         /// <summary>
+        ///   Bitlyを使用するには設定画面で認証情報を入力する必要があります に類似しているローカライズされた文字列を検索します。
+        /// </summary>
+        internal static string UrlConvert_BitlyAuthRequired {
+            get {
+                return ResourceManager.GetString("UrlConvert_BitlyAuthRequired", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   適用 に類似しているローカライズされた文字列を検索します。
         /// </summary>
         internal static string UserInfoButtonEdit_ClickText1 {
index 0caaa46..4e46516 100644 (file)
@@ -1009,9 +1009,6 @@ Do you want to upload the {1} selected media file(s)?</value>
   <data name="SaveLogMenuItem_ClickText5" xml:space="preserve">
     <value>Save events?{0}  [Yes]    :Save events in this tab{0}  [No]  :Save all events{0}[Cancel]:Cancel{0}(Save as Tab separated text(TSV))</value>
   </data>
-  <data name="SettingSave_ClickText1" xml:space="preserve">
-    <value>Failed to authorization. Please confirm api key.</value>
-  </data>
   <data name="TranslateDefaultLanguage" xml:space="preserve">
     <value>en</value>
   </data>
@@ -1155,4 +1152,7 @@ Existing setting files are copied to {1}.
  * If you run as administrator, operations to post images with D&amp;D will be restricted.
  * After running, the setting files of {0} will be able to modify only from administrator.</value>
   </data>
+  <data name="UrlConvert_BitlyAuthRequired" xml:space="preserve">
+    <value>To use Bitly, you must perform the Bitly authentication in settings dialog.</value>
+  </data>
 </root>
\ No newline at end of file
index 612c2cf..cc55fbd 100644 (file)
   <data name="ChangeIconToolStripMenuItem_ClickText5" xml:space="preserve">
     <value>アイコンを変更しました。 次回発言より反映されます。</value>
   </data>
-  <data name="SettingSave_ClickText1" xml:space="preserve">
-    <value>IDとAPIキーの組み合わせが違います。IDと同時に設定するのはパスワードではなくAPIキーです。ご確認ください。</value>
-  </data>
   <data name="UserInfoButtonEdit_ClickText1" xml:space="preserve">
     <value>適用</value>
   </data>
  * 管理者権限で実行するとD&amp;Dで画像を投稿する操作が制限されます。
  * {0}の設定ファイルが一般ユーザー権限で編集できなくなります。</value>
   </data>
+  <data name="UrlConvert_BitlyAuthRequired" xml:space="preserve">
+    <value>Bitlyを使用するには設定画面で認証情報を入力する必要があります</value>
+  </data>
 </root>
\ No newline at end of file
index 4f12642..dd774fe 100644 (file)
@@ -445,10 +445,8 @@ namespace OpenTween
             if ("http://bit.ly/xxxx".Length > srcUri.OriginalString.Length)
                 return srcUri;
 
-            // bit.ly 短縮機能実装のプライバシー問題の暫定対応
-            // ログインIDとAPIキーが指定されていない場合は短縮せずにPOSTする
-            // 参照: http://sourceforge.jp/projects/opentween/lists/archive/dev/2012-January/000020.html
-            if (!string.IsNullOrEmpty(this.BitlyAccessToken) && (string.IsNullOrEmpty(this.BitlyId) || string.IsNullOrEmpty(this.BitlyKey)))
+            // OAuth2 アクセストークンまたは API キー (旧方式) のいずれも設定されていなければ短縮しない
+            if (string.IsNullOrEmpty(this.BitlyAccessToken) && (string.IsNullOrEmpty(this.BitlyId) || string.IsNullOrEmpty(this.BitlyKey)))
                 return srcUri;
 
             var bitly = new BitlyApi
index 998b739..864ed57 100644 (file)
@@ -9201,6 +9201,17 @@ namespace OpenTween
 
         private async Task<bool> UrlConvertAsync(MyCommon.UrlConverter Converter_Type)
         {
+            if (Converter_Type == MyCommon.UrlConverter.Bitly || Converter_Type == MyCommon.UrlConverter.Jmp)
+            {
+                // OAuth2 アクセストークンまたは API キー (旧方式) のいずれも設定されていなければ短縮しない
+                if (string.IsNullOrEmpty(SettingManager.Common.BitlyAccessToken) &&
+                    (string.IsNullOrEmpty(SettingManager.Common.BilyUser) || string.IsNullOrEmpty(SettingManager.Common.BitlyPwd)))
+                {
+                    MessageBox.Show(this, Properties.Resources.UrlConvert_BitlyAuthRequired, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+                    return false;
+                }
+            }
+
             //t.coで投稿時自動短縮する場合は、外部サービスでの短縮禁止
             //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco) return;