Giter Site home page Giter Site logo

ben-biddington / coriander.oauth Goto Github PK

View Code? Open in Web Editor NEW
20.0 3.0 1.0 13.57 MB

Test-driven, "clean code" pure scala implementation of the OAuth standard. See: http://github.com/ben-biddington/Coriander.OAuth/downloads for latest jar.

License: Apache License 2.0

Ruby 1.97% Scala 98.03%

coriander.oauth's Introduction

Test-driven, "clean code" pure scala implementation of the OAuth standard.

#Examples#

##How to sign a URI with Consumer

Sugar class which signs a URI for a consumer. Adds query string parameters.

val uri         = new URI("http://xxx")
val consumer    = new Consumer(new Credential("key", "secret"))
val signedUri   = consumer.sign(uri)

##How to create a signed URI

Adds query string parameters to your URI. (Currently supports only HmacSha1Signature)

val uri         = new URI("http://xxx")
val consumer    = new Credential("key", "secret")
val token       = new Credential("token", "token_secret")  
val timestamp   = "1259067839"
val nonce       = "73f0f93345d76d6cd1bab30af14a99e3"

val signedUri = new SignedUri(
    uri,
    new CredentialSet(consumer, token),
    timestamp,
    nonce
)

##How to create an authorization header

A lower-level abstraction than SignedUri. This process requires you to first generate a SignatureBaseString, and then a Signature. Here we are using HmacSha1Signature, but RsaSha1Signature is also available.

val uri         = new URI("http://xxx")
val query       = new Query()
val credentials = new CredentialSet(
    new Credential("consumer_key", "consumer_secret"),
    new Credential("token_key", "token_secret")
)

val nonce       = "73f0f93345d76d6cd1bab30af14a99e3"
val timestamp 	= "1259067839"

val baseString = new SignatureBaseString(
    "GET"
    uri,
    query,
    credentials,
    nonce,
    timestamp,
    Options.DEFAULT
)

val signature = new HmacSha1Signature(urlEncoder, credentials).sign(baseString)

new AuthorizationHeader(
    "REALM",
    credentials,
    signature,
    timestamp,
    nonce,
    Options.DEFAULT,
    urlEncoder
)

##Example: generating signature base string The one from the oauth specification (http://oauth.net/core/1.0a#RFC2617, Appendix A.5.1. Generating Signature Base String) is represented as a unit test.

See: org.coriander.unit.tests.oauth.core.SignatureBaseStringTest. example_with_token_from_the_oauth_spec_document

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.