An IOC/DI friendly OpenAuth client library for creating consumer applications written in dotnet core.
Currently only OpenAuth 1.0a is supported but OAuth 2.0 will be along shortly.
On the To Do list in no particular order:
- Improve exception handling.
- Increase Test coverage
- Add more DI container support.
- better documentation.
- more examples of usage in the WebTest project.
- more complete examples of usage in the WebTest project.
- more resource providers.
- default IStateStorageManager implementation needed.
It is not intended for this library to include support for creating a server (service provider/resource) implementation of OAuth. There are plenty of those. This project strives to be a simple to use lightweight wrapper aroung HttpClient providing access to OpenAuth protected resources.
The main library. This can be used directly but it is recommended that one of the IOC container integration libraries is used as they ensure everything is wired correctly.
A library to use when an IOC container is not available or needed. This is a hard wired library with an implementation of OpenAuthClientFactory that creates its own dependencies.
The base library that all other DI implementations derive from.
A library making use of the ServiceCollection default IOC/DI implementation in asp.net core.
A library making use of the SimpleInjector IOC/DI container implementation in asp.net core.
A sample command line application using Blacktau.OpenAuth.Containers.Basic
in order to make simple calls to the following APIs:
You will need to supply your own Consumer Keys, Consumer Secrets, Access Tokens and Access Token Secrets. The first two you will need to obtain from the respective resources by registering your application and the second two by obtaining Authorization from those APIs. In the case of OAuth2 (Facebook/Google) you will need only an AccessToken as there is no access token secret in OAuth 2.
Use the Blacktau.OpenAuth.Basic package.
- Reference and add usings for Blacktau.OpenAuth.Basic and Blacktau.OpenAuth
- New up an instance of ApplicationCredentials and set the ApplicationKey and ApplicationSecret
- New up an instance of AuthorizationInformation and set its AccessToken and AccessTokenSecret properties.
- Using the results of steps 1 and 2 new up an OpenAuthClientFactory.
- Using the OpenAuthClientFactory instance create an OpenAuthClient.
- Add Body (for POST requests) or Query (for GET requests) parameters
- Invoke the async Execute method and do something with the result.
var applicationCredentials = new ApplicationCredentials();
applicationCredentials.ApplicationKey = "YourApplicationKey";
applicationCredentials.ApplicationSecret = "YourApplicationSecret";
var authorizationInformation = new AuthorizationInformation("YourAccessToken");
authorizationInformation.AccessTokenSecret = "YourAccessTokenSecret";
var openAuthClientFactory = new OpenAuthClientFactory(applicationCredentials, authorizationInformation);
var openAuthClient = openAuthClientFactory.CreateOpenAuthClient("https://api.twitter.com/1.1/statuses/user_timeline.json", HttpMethod.Get, OpenAuthVersion.OneA);
openAuthClient.AddQueryParameter("screen_name", "blacktau");
openAuthClient.AddQueryParameter("count", "2");
var result = await openAuthClient.Execute();
Console.WriteLine(result);