LightRest now supports OAuth!

How to authorize a user with OAuth

var consumer = new Consumer
{
    Key = "k",
    Secret = "s",
    RequestTokenUri = "http://host/oauth/request_token",
    AuthorizeUri = "http://host/oauth/authorize",
    AccessTokenUri = "http://host/oauth/access_token"
};

var requestToken = consumer.GetRequestToken();
var authorizeUri = requestToken.GetNormalizedAuthorizeUri();
//Redirect to the authorize URI to allow user authorize or deny the service.

//Then use the oauth_verifier to retrieve the access token.
var accessToken = requestToken.ToAccessToken("oauth_verifier_value");

//save the access token for later uses :)

How to access the protected resources with LightOAuth

var client = new RestClient();

var request = new OAuthHttpRequestMessage("GET", "http://host/protected/resource").Sign(accessToken);

var responseContent = client.Send(request).ReadContentAsString();

Last edited Aug 5, 2010 at 6:01 AM by shinyzhu, version 7

Comments

No comments yet.