OSDN Git Service

OAuth署名生成などの処理をOAuthUtilityクラスに移動
[opentween/open-tween.git] / OpenTween / Connection / HttpConnectionOAuthEcho.cs
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.
9 // 
10 // This file is part of OpenTween.
11 // 
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)
15 // any later version.
16 // 
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
20 // for more details. 
21 // 
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.
26
27 using HttpConnectionOAuth = OpenTween.HttpConnectionOAuth;
28 using OAuthUtility = OpenTween.Connection.OAuthUtility;
29 using Uri = System.Uri;
30 using HttpWebRequest = System.Net.HttpWebRequest;
31 using System.Collections.Generic; // for Dictionary<TKey, TValue>, KeyValuePair<TKey, TValue>
32 using HttpConnection = OpenTween.HttpConnection;
33 using StringBuilder = System.Text.StringBuilder;
34
35 namespace OpenTween
36 {
37         public class HttpConnectionOAuthEcho : HttpConnectionOAuth
38         {
39                 private Uri _realm;
40
41                 private Uri _serviceProvider;
42
43                 public Uri Realm
44                 {
45                         set { this._realm = value; }
46                 }
47
48                 public Uri ServiceProvider
49                 {
50                         set { this._serviceProvider = value; }
51                 }
52
53                 protected override void AppendOAuthInfo( HttpWebRequest webRequest, Dictionary< string, string > query, string token, string tokenSecret )
54                 {
55                         var realm = this._realm.Scheme + "://" + this._realm.Host + this._realm.AbsolutePath;
56
57                         var credential = OAuthUtility.CreateAuthorization( HttpConnection.GetMethod, this._serviceProvider, query,
58                                 this.consumerKey, this.consumerSecret, token, tokenSecret, realm );
59
60                         webRequest.Headers.Add( "X-Verify-Credentials-Authorization", credential );
61                         webRequest.Headers.Add( "X-Auth-Service-Provider", string.Format("{0}://{1}{2}", this._serviceProvider.Scheme, this._serviceProvider.Host, this._serviceProvider.AbsolutePath));
62                 }
63
64                 public HttpConnectionOAuthEcho( Uri realm, Uri serviceProvider )
65                 {
66                         this._realm = realm;
67                         this._serviceProvider = serviceProvider;
68                 }
69         }
70 }