This is a simple OAuth client library which I developed in Scala. It currently supports Plaintext and HMAC-SHA1 signatures and has successfully been used to authenticate to both Twitter and Yahoo and to interact with Twitter's REST API.
import jm.oauth.OAuth
import jm.oauth.Requester
//Getting the request token
val oauth = new OAuth(OAuth.POST, oauthConsumerSecret, oauthConsumerKey, OAuth.HMAC_SHA1)
val requestToken = oauth.generateRequestToken(oauth_api_url, OAuth.OOB)
//careful, different OAuth services return slightly different name/value pairs.
println("request_token is " + requestToken)
println(requestToken("oauth_token_secret"))
//Getting the access token now that you have a request token
/*oauth.generateAccessToken(accessTokenUrl, oauth_token_secret, oauth_token,
* oauth_verifier or pin) Since this example is using OOB rather than a
* callback URL and Twitter, the user must now to go the url
* https://api.twitter.com/oauth/authorize?oauth_token=tokenrequest("oauth_token")
* where they will sign in and be presented with a PIN to use in the next step.
* If using a callback url, an identifier will be included there.
*/
val accessTokenRequest = oauth.generateAccessToken(accessTokenUrl,
tokenRequest("oauth_token_secret"), tokenRequest("oauth_token"), PIN)
/* Now store the authorized token and authorized token secret somewhere
* With twitter these will be tokenRequest("oauth_token") for authorized token
* and tokenRequest("oauth_token_secret") for the authorized token secret
*/
//Make a request - posting an update to Twitter here
val requester = new Requester(OAuth.HMAC_SHA1, TWITTER_CONSUMER_SECRET,
TWITTER_CONSUMER_KEY, TWITTER_AUTHORIZED_TOKEN, TWITTER_AUTHORIZED_TOKEN_SECRET)
val postMessage = Map("status" -> "another test")
//response is a byte array
val response = requester.post("http://api.twitter.com/1/statuses/update.json", postMessage)
- Nothing to see here, move along.