oauth-signature is a lightweight Scala library to generate OAuth1.0 signature using HMAC-SHA algorithm. Works well for Twitter and Flickr APIs that need OAuth1.0 authentication.
Use the following import to get started:
libraryDependencies += "com.github.bellam" %% "oauth-signature" % "0.1.1"
- Consumer Key
- Consumer Secret
- Access Token
- Access Token Secret
val config = OAuthConfig(
oauth_consumer_key = env("TWITTER_CONSUMER_KEY"),
oauth_consumer_secret = env("TWITTER_CONSUMER_SECRET"),
oauth_token = env("TWITTER_ACCESS_TOKEN"),
oauth_token_secret = env("TWITTER_ACCESS_TOKEN_SECRET")
)
- HTTP method (GET, POST, etc.)
- HTTP URL
- Query parameters to the request (pass an empty Map incase of no parameters)
val request = OAuthRequest(
http_method = "GET",
http_url = "https://api.twitter.com/1.1/search/tweets.json",
query_parameters = Map("q" -> "#BlackLivesMatter")
)
val signature = OAuthSignature(config, request)
scala> signature.getSignature
res14: String = "bbr4AkCDTrvw6FG0h605oHtX8tM="
scala> signature.getSignedAuthorizationHeader
res15: String = "OAuth oauth_consumer_key=\"1234\", oauth_nonce=\"1234\", oauth_signature=\"bbr4AkCDTrvw6FG0h605oHtX8tM%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1234\", oauth_token=\"1234\", oauth_version=\"1.0\""
This library has been very useful for me with some ammonite scripts I wrote to analyse twitter hashtags via Twitter's Standard API.
Thank you.