Closed brianly closed 13 years ago
Thanks for creating this ticket. This is definitely on the radar (there's been some work on it already) but it will be after 1.0. Don't worry, the version number is mostly meaningless, I hope 2.0 comes quickly after 1.0 is out.
+1 on oAuth Support :)
i got the oauth2 authentication done. there are many ways we can do oauth2 authentication. the one im gonna show here will be using the URI Query Parameter more details here http://tools.ietf.org/html/draft-ietf-oauth-v2-10#section-5.1.2
since oauth2 has lots of authentciation methods. i actually created an abstract class for it.
public abstract class OAuth2Authenticator : IAuthenticator {
public abstract void Authenticate(RestRequest request);
#endregion
}
then i create specific oauth2 authenticators that is uri paramater.
///
public OAuth2UriQueryParamaterAuthenticator(string accessToken)
{
_accessToken = accessToken;
}
#region Overrides of OAuth2Authenticator
public override void Authenticate(RestRequest request)
{
request.AddParameter("oauth_token", _accessToken, ParameterType.GetOrPost);
}
#endregion
}
so i want to access.. lets say facebook graph api which uses oauth2 for authentication.
var client = new RestClient("https://graph.facebook.com/me"); client.Authenticator = new OAuth2UriQueryParamaterAuthenticator( "acces_token"); var request = new RestRequest(); var respone = client.Execute(request);
Console.WriteLine(respone.Content);
thats all.
actually facebook requires "access_token" parameter. but since it wants to maintain standards it also supports the "oauth_token" parameter instead of "access_token". <:-) that makes our life easier..
oauth1 and 2 now supported in sync methods thanks to contributions from prabir and danielcrenna. async will follow post release 1
I had a quick look and didn't see any references to support for this. OAuth is multi-legged in terms of setup, but once you have the right credentials at the client side you can send over as headers in a similar way to basic authentication. There are OAuth samples for .NET at http://oauth.net/code/ but I think they make the protocol feel overly complicated.
I would use for a Yammer API client I am building, maybe I will get some time to hack this up for inclusion in RestSharp.