• Stars
    star
    100
  • Rank 330,015 (Top 7 %)
  • Language
    C#
  • Created about 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Portable Client Library and HttpClient based OAuth library, including all platform(for PCL).

AsyncOAuth

Portable Client Library and HttpClient based OAuth library, including all platform(for PCL as .NET 4.0, .NET 4.5, Silverlight4, Silverlight5, Windows Phone 7.5, Windows Phone 8.0, Windows Store Apps).

Install

using with NuGet, AsyncOAuth

PM> Install-Package AsyncOAuth

Usage

at first, you must initialize hash function(ApplicationStart etc...)

// Silverlight, Windows Phone, Console, Web, etc...
OAuthUtility.ComputeHash = (key, buffer) => { using (var hmac = new HMACSHA1(key)) { return hmac.ComputeHash(buffer); } };
 
// Windows Store Apps
AsyncOAuth.OAuthUtility.ComputeHash = (key, buffer) =>
{
    var crypt = Windows.Security.Cryptography.Core.MacAlgorithmProvider.OpenAlgorithm("HMAC_SHA1");
    var keyBuffer = Windows.Security.Cryptography.CryptographicBuffer.CreateFromByteArray(key);
    var cryptKey = crypt.CreateKey(keyBuffer);
 
    var dataBuffer = Windows.Security.Cryptography.CryptographicBuffer.CreateFromByteArray(buffer);
    var signBuffer = Windows.Security.Cryptography.Core.CryptographicEngine.Sign(cryptKey, dataBuffer);
 
    byte[] value;
    Windows.Security.Cryptography.CryptographicBuffer.CopyToByteArray(signBuffer, out value);
    return value;
};

Create HttpClient with OAuthMessageHandler

var client = new HttpClient(new OAuthMessageHandler("consumerKey", "consumerSecret", new AccessToken("accessToken", "accessTokenSecret")));
 
// shorthand(result is same above)
var client = OAuthUtility.CreateOAuthClient("consumerKey", "consumerSecret", new AccessToken("accessToken", "accessTokenSecret"));

operation same as HttpClient

// Get
var json = await client.GetStringAsync("http://api.twitter.com/1.1/statuses/home_timeline.json?count=" + count + "&page=" + page);
 
// Post
var content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("status", status) });
var response = await client.PostAsync("http://api.twitter.com/1.1/statuses/update.json", content);
var json = await response.Content.ReadAsStringAsync();
 
// Multi Post
var content = new MultipartFormDataContent();
content.Add(new StringContent(status), "\"status\"");
content.Add(new ByteArrayContent(media), "media[]", "\"" + fileName + "\"");
 
var response = await client.PostAsync("https://upload.twitter.com/1/statuses/update_with_media.json", content);
var json = await response.Content.ReadAsStringAsync();

Sample

more sample, please see AsyncOAuth.ConsoleApp(Twitter.cs, Hatena.cs), AsyncOAuth.WindowsStoreApp
sample contains authorize flow

// sample flow for Twitter authroize
public async static Task<AccessToken> AuthorizeSample(string consumerKey, string consumerSecret)
{
    // create authorizer
    var authorizer = new OAuthAuthorizer(consumerKey, consumerSecret);

    // get request token
    var tokenResponse = await authorizer.GetRequestToken("https://api.twitter.com/oauth/request_token");
    var requestToken = tokenResponse.Token;

    var pinRequestUrl = authorizer.BuildAuthorizeUrl("https://api.twitter.com/oauth/authorize", requestToken);

    // open browser and get PIN Code
    Process.Start(pinRequestUrl);

    // enter pin
    Console.WriteLine("ENTER PIN");
    var pinCode = Console.ReadLine();

    // get access token
    var accessTokenResponse = await authorizer.GetAccessToken("https://api.twitter.com/oauth/access_token", requestToken, pinCode);

    // save access token.
    var accessToken = accessTokenResponse.Token;
    Console.WriteLine("Key:" + accessToken.Key);
    Console.WriteLine("Secret:" + accessToken.Secret);

    return accessToken;
}

History

ver 0.8.4 - 2014-03-14

  • fixed, generate wrong signature when POST and data contains "%21", "%2A", "%27", "%28" and "%29". thanks @karno #11
  • update Microsoft.Bcl.Async to 1.0.165
  • update Microsoft.Net.Http to 2.2.18

ver 0.8.3 - 2013-10-17

  • fixed, generate wrong signature when data contains space(This enbug is from v.0.8.1)

ver 0.8.2 - 2013-09-30

  • fixed, allow OAuth TokenResponse returns duplicate key

ver 0.8.1 - 2013-09-30

  • fixed, generate wrong OAuth signature when parameter have same key and value needs UrlEncode
  • modified, escape character in URLs. thanks @gjulianm #6
  • update HttpClient version - to 2.2.15.

ver 0.7.0 - 2013-06-24

  • fixed, generate wrong OAuth signature when parameter-name mixed lower and upper.
  • fixed, generate wrong OAuth signature when get and querystring needs UrlEncode.

ver.0.6.4 - 2013-05-27

  • update external library version.
  • improved:Token is serializable.

License

under MIT License

More Repositories

1

UniRx

Reactive Extensions for Unity
C#
6,889
star
2

MessagePack-CSharp

Extremely Fast MessagePack Serializer for C#(.NET, .NET Core, Unity, Xamarin). / msgpack.org[C#]
C#
4,721
star
3

ZeroFormatter

Infinitely Fast Deserializer for .NET, .NET Core and Unity.
C#
2,378
star
4

Utf8Json

Definitely Fastest and Zero Allocation JSON Serializer for C#(NET, .NET Core, Unity, Xamarin).
C#
2,345
star
5

LINQ-to-GameObject-for-Unity

LINQ to GameObject - Traverse GameObject Hierarchy by LINQ
C#
790
star
6

MarkdownGenerator

Generate markdown from C# binary & xml document for GitHub Wiki.
C#
189
star
7

LightNode

Micro RPC/REST Framework built on OWIN
C#
177
star
8

MicroResolver

Extremely Fast Dependency Injection Library.
C#
174
star
9

linq.js

LINQ for JavaScript.
JavaScript
128
star
10

SerializableDictionary

SerializableCollections(SerializableDictionary, SerializableLookup, SerializableTuple) for Unity
C#
123
star
11

EtwStream

Logs are event streams. EtwStream provides In-Process and Out-of-Process ObservableEventListener. Everything can compose and output to anywhere by Reactive Extensions.
C#
123
star
12

PhotonWire

Typed Asynchronous RPC Layer for Photon Server + Unity
C#
119
star
13

HyperMapper

An alternative to AutoMapper, Hyper fast object-to-object mapper built on fastest serializer technology.
C#
93
star
14

LINQ-to-BigQuery

LINQ to BigQuery is C# LINQ Provider for Google BigQuery. It also enables Desktop GUI Client with LINQPad and plug-in driver.
C#
85
star
15

ChainingAssertion

Method Chaining base UnitTesting Extension Methods and Dynamic Private Accessor for MSTest, NUnit, xUnit.net.
C#
75
star
16

FastHashtable

Infrastructure for high performance code.
C#
64
star
17

MySqlSharp

Extremely Fast MySQL Driver for C#, work in progress.
C#
53
star
18

NotifyPropertyChangedGenerator

Roslyn Analyzer/Generator for avoid boring boilerplate INotifyPropertyChanged implementation.
C#
51
star
19

Open-on-GitHub

Visual Studio Extension for opening files on GitHub, GitLab, Gitea, Bitbucket and AzureDevOps (dev.azure.com, visualstudio.com, tfs)
C#
44
star
20

DatadogSharp

Yet another C# Datadog client that supports DogStatsD and APM.
C#
41
star
21

ReMotion

Hyper Fast Reactive Tween Engine for Unity
C#
40
star
22

DynamicJson

dynamic json structure for C# 4.0.
C#
36
star
23

OwinRequestScopeContext

Owin Middleware it is possible to RequestScopeContext like HttpContext.Current but no dependent System.Web.
C#
29
star
24

RespClient

RespClient is a minimal RESP(REdis Serialization Protocol) client for C# and PowerShell.
C#
29
star
25

Resume

My Resume
21
star
26

Blog2

C# Static Site Generator and Hosting for neue.cc
C#
15
star
27

ObserveEveryValueChanged

Voodoo Magic for WPF.
C#
13
star
28

MemcachedTranscoder

C# Memcached Transcoders
C#
8
star
29

AnonymousComparer

Lambda compare selector for Linq
C#
6
star
30

Owin.RedisSession

Redis Session Provider for Owin.
C#
5
star
31

MSBuildAssemblyLoadIssue

C#
4
star
32

neuecc

4
star
33

DbExecutor

Simple and Lightweight Database Executor
C#
4
star
34

EsaClient

esa.io client for .NET Standard.
C#
3
star
35

XStreamingReader

Xml Stream(XmlReader) to IEnumerable for Windows Phone(memory save) or parse large Xml.
C#
3
star
36

ImplicitQueryString

Magic for QueryString parsing.
C#
2
star
37

ReactiveOAuth

OAuth library for .NET Framework 4 Client Profile, Silverlight 4 and Windows Phone 7.
C#
2
star