1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 // (c) 2008-2011 Moz (@syo68k)
4 // (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 // (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 // (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 // (c) 2011 spinor (@tplantd) <http://d.hatena.ne.jp/spinor/>
8 // All rights reserved.
10 // This file is part of OpenTween.
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
27 using HttpConnectionOAuth = OpenTween.HttpConnectionOAuth;
28 using Uri = System.Uri;
29 using HttpWebRequest = System.Net.HttpWebRequest;
30 using System.Collections.Generic; // for Dictionary<TKey, TValue>, KeyValuePair<TKey, TValue>
31 using HttpConnection = OpenTween.HttpConnection;
32 using StringBuilder = System.Text.StringBuilder;
36 public class HttpConnectionOAuthEcho : HttpConnectionOAuth
40 private Uri _serviceProvider;
42 private string _token;
44 private string _tokenSecret;
48 set { this._realm = value; }
51 public Uri ServiceProvider
53 set { this._serviceProvider = value; }
56 protected override void AppendOAuthInfo( HttpWebRequest webRequest, Dictionary< string, string > query, string token, string tokenSecret )
59 Dictionary< string, string > parameter = this.GetOAuthParameter( token );
60 // OAuth共通情報にquery情報を追加
62 foreach ( KeyValuePair< string, string > item in query )
63 parameter.Add( item.Key, item.Value );
64 // 署名の作成・追加(GETメソッド固定。ServiceProvider呼び出し用の署名作成)
65 parameter.Add( "oauth_signature", this.CreateSignature( tokenSecret, HttpConnection.GetMethod, this._serviceProvider, parameter ) );
67 StringBuilder sb = new StringBuilder( "OAuth " );
68 sb.AppendFormat( "realm=\"{0}://{1}{2}\",", this._realm.Scheme, this._realm.Host, this._realm.AbsolutePath);
69 foreach ( KeyValuePair< string, string > item in parameter )
70 if ( item.Key.StartsWith( "oauth_" ) )
71 sb.AppendFormat( "{0}=\"{1}\",", item.Key, this.UrlEncode( item.Value ) );
72 webRequest.Headers.Add( "X-Verify-Credentials-Authorization", sb.ToString() );
73 webRequest.Headers.Add( "X-Auth-Service-Provider", string.Format("{0}://{1}{2}", this._serviceProvider.Scheme, this._serviceProvider.Host, this._serviceProvider.AbsolutePath));
76 public HttpConnectionOAuthEcho( Uri realm, Uri serviceProvider )
79 this._serviceProvider = serviceProvider;