Skip to content

pkaeding/Scala-OAuth

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Scala OAuth is a simple OAuth client library written in Scala.  The focus is on
simplicity for common tasks moreso than supporting everything you might ever
want to do with OAuth.

Use it, clone it and continue development, etc. as you like within the bounds
of the license.  New requests to pull patches may or may not ever get
completed.  I enjoy developing new things and learning from them for a hobby,
not supporting them afterwards, so I'll have moved on to new projects.
I wanted to put this code out here so that it is easily accessible for anyone
who might be able to use it, though.

Thanks for taking a look and I hope you find it useful.

Authors:
Justin Michalicek

Usage Example:

import jm.oauth.OAuth
import jm.oauth.Requester

val oauthApiUrl = TWITTER_REQUEST_TOKEN_URL
val oauthConsumerKey = TWITTER_CONSUMER_KEY
val oauthConsumerSecret = TWITTER_CONSUMER_SECRET

//Getting the request token
val oauth = new OAuth(OAuth.POST, oauthConsumerSecret, oauthConsumerKey, OAuth.HMAC_SHA1)
val requestToken = oauth.generateRequestToken(oauthApiUrl, 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)

Releases

No releases published

Packages

No packages published

Languages

  • Scala 100.0%