-
Notifications
You must be signed in to change notification settings - Fork 0
/
OAuthMessageHandler.cs
executable file
·51 lines (45 loc) · 1.93 KB
/
OAuthMessageHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
namespace TwitterSample.OAuth
{
/// <summary>
/// Basic DelegatingHandler that creates an OAuth authorization header based on the OAuthBase
/// class downloaded from http://oauth.net
/// </summary>
public class OAuthMessageHandler : DelegatingHandler
{
// Obtain these values by creating a Twitter app at http://dev.twitter.com/
private static string _consumerKey = "eguczzSgqwHRwGUkKv0pfChlt";
private static string _consumerSecret = "j2O6XsQbuF4uZE8TjcFhzEY85Q3gIhNYbe2witwG3oeuO6lr8W";
private static string _token = "1168204784-so8aAG7zNLqiPVhQZ4m33SszMAXz6kznSrjCoG0";
private static string _tokenSecret = "N0CByfvwTlo9aqisbCcKBS9XOcKzRMF9LjvZh19SLxJPG";
private OAuthBase _oAuthBase = new OAuthBase();
public OAuthMessageHandler(HttpMessageHandler innerHandler)
: base(innerHandler)
{
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
// Compute OAuth header
string normalizedUri;
string normalizedParameters;
string authHeader;
string signature = _oAuthBase.GenerateSignature(
request.RequestUri,
_consumerKey,
_consumerSecret,
_token,
_tokenSecret,
request.Method.Method,
_oAuthBase.GenerateTimeStamp(),
_oAuthBase.GenerateNonce(),
out normalizedUri,
out normalizedParameters,
out authHeader);
request.Headers.Authorization = new AuthenticationHeaderValue("OAuth", authHeader);
return base.SendAsync(request, cancellationToken);
}
}
}