Skip to content

jinahya/rfc5849

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rfc5849

implementation of The OAuth 1.0 Protocol.

Dependency Status Build Status Maven Central Javadocs

Components

OAuthBaseString

For building a Signature Base String.

final OAuthBaseString baseString = new OAuthBaseString();

You can use following methods to set values.

baseString.httpMethod(httpMethod);
baseString.baseUri(baseUri);
baseString.queryParameter(key, value);
baseString.protocolParameter(key, value); // key must start with 'oauth_'
baseString.entityParameter(key, value);

OAuthSignature

For generating a Signature.

class method platform
OAuthSignatureHmacSha1Bc HMAC-SHA1 BC
OAuthSignatureHmacSha1Jca HMAC-SHA1 JCA
OAuthSignatureRsaSha1Bc RSA-SHA1 BC
OAuthSignatureRsaSha1Jca RSA-SHA1 JCA
OAuthSignaturePlaintext PLAINTEXT

HMAC-SHA1

There are two implementations. One is for Java Cryptograph Architexture and the other is for Legion of the Bouncy Castle.

final OAuthSignatureHmacSha1 signature = new OAuthSignatureHmacSha1Bc(); // BC
final OAuthSignatureHmacSha1 signature = new OAuthSignatureHmacSha1Jca(); // JCA

You can use following methods to set values.

signature.consumerSecret(consumerSecret);
signature.tokenSecret(tokenSecret);
signature.baseString(baseString); // OAuthBaseString

RSA-SHA1

There are, again, two implementations. One is for Java Cryptograph Architexture and the other is for Legion of the Bouncy Castle.

final OAuthSignatureRsaSha1 signature = new OAuthSignatureRsaSha1Bc(); // BC
final OAuthSignatureRsaSha1 signature = new OAuthSignatureRsaSha1Jca(); // JCA

You can use following methods to set values.

signature.initParam(PrivateKey privateKey); // JCA
signature.initParam(CipherParameters cipherParameters); // BC

PLAINTEXT

new OAuthSignaturePlaintext();

OAuthProtocolParameters

final OAuthProtocolParameters protocolParameters = new OAuthProtocolParameters();
protocolParameters.realm(realm);
protocolParameters.signature(signature); // OAuthSignature

Three kinds of output defined in 3.5. Parameter Transmission are supported.

final String header = protocolParameters.authorizationHeader(); // Authorization Header
final String body = protocolParameters.formEncodedBody(); // Form-Encoded Body
final String query = protocolParameters.requestUriQuery(); // Request URI Query

Examples

final OAuthRequest protocolParameters = new OAuthRequest()
    .realm("Example")
    .signature(
        new OAuthSignatureHmacSha1Bc()
            .consumerSecret("j49sk3j29djd")
            .tokenSecret("dh893hdasih9")
            .baseString(
                new OAuthBaseString()
                    .httpMethod("POST")
                    .baseUri("http://example.com/request")
                    .queryParameter("b5", "=%3D")
                    .queryParameter("a3", "a")
                    .queryParameter("c@", "")
                    .queryParameter("a2", "r b")
                    .oauthConsumerKey("9djdj82h48djs9d2")
                    .oauthNonce("7d8f3e4a")
                    .oauthTimestamp("137131201")
                    .oauthToken("kkk9d7dh3k39sjv7")
                    .entityParameter("c2", "")
                    .entityParameter("a3", "2 q")
        )
    );

final String authorizationHeader = protocolParameters.authorizationHeader();

About

implementation of The OAuth 1.0 Protocol

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages