Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
979c6579ab | ||
|
|
97fa26fce7 | ||
|
|
2f55386995 | ||
|
|
23fa5946a9 |
No files matched your search
@@ -5,7 +5,7 @@ import org.scribe.services.*;
|
||||
|
||||
public class YammerApi extends DefaultApi10a
|
||||
{
|
||||
private static final String AUTHORIZATION_URL = "'https://www.yammer.com/oauth/authorize?oauth_token=%s'";
|
||||
private static final String AUTHORIZATION_URL = "https://www.yammer.com/oauth/authorize?oauth_token=%s";
|
||||
|
||||
@Override
|
||||
public String getRequestTokenEndpoint()
|
||||
|
||||
@@ -57,4 +57,22 @@ public class Token implements Serializable
|
||||
{
|
||||
return String.format("Token[%s , %s]", token, secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the token is empty (token = "", secret = "")
|
||||
*/
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return "".equals(this.token) && "".equals(this.secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method that returns an empty token (token = "", secret = "").
|
||||
*
|
||||
* Useful for two legged OAuth.
|
||||
*/
|
||||
public static Token empty()
|
||||
{
|
||||
return new Token("","");
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import org.scribe.utils.*;
|
||||
|
||||
/**
|
||||
* OAuth 1.0a implementation of {@link OAuthService}
|
||||
*
|
||||
*
|
||||
* @author Pablo Fernandez
|
||||
*/
|
||||
public class OAuth10aServiceImpl implements OAuthService
|
||||
@@ -20,7 +20,7 @@ public class OAuth10aServiceImpl implements OAuthService
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
*
|
||||
* @param api OAuth1.0a api information
|
||||
* @param config OAuth 1.0a configuration param object
|
||||
*/
|
||||
@@ -88,8 +88,12 @@ public class OAuth10aServiceImpl implements OAuthService
|
||||
public void signRequest(Token token, OAuthRequest request)
|
||||
{
|
||||
config.log("signing request: " + request.getCompleteUrl());
|
||||
request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken());
|
||||
|
||||
// Do not append the token if empty. This is for two legged OAuth calls.
|
||||
if (!token.isEmpty())
|
||||
{
|
||||
request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken());
|
||||
}
|
||||
config.log("setting token to: " + token);
|
||||
addOAuthParams(request, token);
|
||||
appendSignature(request);
|
||||
@@ -110,7 +114,7 @@ public class OAuth10aServiceImpl implements OAuthService
|
||||
{
|
||||
return api.getAuthorizationUrl(requestToken);
|
||||
}
|
||||
|
||||
|
||||
private String getSignature(OAuthRequest request, Token token)
|
||||
{
|
||||
config.log("generating signature...");
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.scribe.services;
|
||||
|
||||
import org.apache.commons.codec.binary.*;
|
||||
import org.scribe.exceptions.*;
|
||||
import java.security.*;
|
||||
|
||||
/**
|
||||
* A signature service that uses the RSA-SHA1 algorithm.
|
||||
*/
|
||||
public class RSASha1SignatureService implements SignatureService
|
||||
{
|
||||
private static final String METHOD = "RSA-SHA1";
|
||||
private static final String RSA_SHA1 = "SHA1withRSA";
|
||||
|
||||
private PrivateKey privateKey;
|
||||
|
||||
public RSASha1SignatureService(PrivateKey privateKey)
|
||||
{
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getSignature(String baseString, String apiSecret, String tokenSecret)
|
||||
{
|
||||
try
|
||||
{
|
||||
Signature signature = Signature.getInstance(RSA_SHA1);
|
||||
signature.initSign(privateKey);
|
||||
signature.update(baseString.getBytes());
|
||||
return new String(Base64.encodeBase64(signature.sign(), false));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new OAuthSignatureException(baseString, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getSignatureMethod()
|
||||
{
|
||||
return METHOD;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.scribe.services;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.apache.commons.codec.binary.*;
|
||||
import java.security.*;
|
||||
import java.security.spec.*;
|
||||
|
||||
public class RSASha1SignatureServiceTest
|
||||
{
|
||||
|
||||
RSASha1SignatureService service = new RSASha1SignatureService(getPrivateKey());
|
||||
|
||||
@Test
|
||||
public void shouldReturnSignatureMethodString()
|
||||
{
|
||||
String expected = "RSA-SHA1";
|
||||
assertEquals(expected, service.getSignatureMethod());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSignature()
|
||||
{
|
||||
String apiSecret = "api secret";
|
||||
String tokenSecret = "token secret";
|
||||
String baseString = "base string";
|
||||
String signature = "LUNRzQAlpdNyM9mLXm96Va6g/qVNnEAb7p7K1KM0g8IopOFQJPoOO7cvppgt7w3QyhijWJnCmvqXaaIAGrqvdyr3fIzBULh8D/iZQUNLMi08GCOA34P81XBvsc7A5uJjPDsGhJg2MzoVJ8nWJhU/lMMk4c92S1WGskeoDofRwpo=";
|
||||
assertEquals(signature, service.getSignature(baseString, apiSecret, tokenSecret));
|
||||
}
|
||||
|
||||
/**
|
||||
*Created primary key using openssl.
|
||||
*
|
||||
* openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj '/C=GB/ST=/L=Manchester/CN=www.example.com' -keyout myrsakey.pem -out /tmp/myrsacert.pem
|
||||
* openssl pkcs8 -in myrsakey.pem -topk8 -nocrypt -out myrsakey.pk8
|
||||
*/
|
||||
private static PrivateKey getPrivateKey()
|
||||
{
|
||||
String str = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMPQ5BCMxlUq2TYy\n"+
|
||||
"iRIoEUsz6HGTJhHuasS2nx1Se4Co3lxwxyubVdFj8AuhHNJSmJvjlpbTsGOjLZpr\n"+
|
||||
"HyDEDdJmf1Fensh1MhUnBZ4a7uLrZrKzFHHJdamX9pxapB89vLeHlCot9hVXdrZH\n"+
|
||||
"nNtg6FdmRKH/8gbs8iDyIayFvzYDAgMBAAECgYA+c9MpTBy9cQsR9BAvkEPjvkx2\n"+
|
||||
"XL4ZnfbDgpNA4Nuu7yzsQrPjPomiXMNkkiAFHH67yVxwAlgRjyuuQlgNNTpKvyQt\n"+
|
||||
"XcHxffnU0820VmE23M+L7jg2TlB3+rUnEDmDvCoyjlwGDR6lNb7t7Fgg2iR+iaov\n"+
|
||||
"0iVzz+l9w0slRlyGsQJBAPWXW2m3NmFgqfDxtw8fsKC2y8o17/cnPjozRGtWb8LQ\n"+
|
||||
"g3VCb8kbOFHOYNGazq3M7+wD1qILF2h/HecgK9eQrZ0CQQDMHXoJMfKKbrFrTKgE\n"+
|
||||
"zyggO1gtuT5OXYeFewMEb5AbDI2FfSc2YP7SHij8iQ2HdukBrbTmi6qxh3HmIR58\n"+
|
||||
"I/AfAkEA0Y9vr0tombsUB8cZv0v5OYoBZvCTbMANtzfb4AOHpiKqqbohDOevLQ7/\n"+
|
||||
"SpvgVCmVaDz2PptcRAyEBZ5MCssneQJAB2pmvaDH7Ambfod5bztLfOhLCtY5EkXJ\n"+
|
||||
"n6rZcDbRaHorRhdG7m3VtDKOUKZ2DF7glkQGV33phKukErVPUzlHBwJAScD9TqaG\n"+
|
||||
"wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ\n"+
|
||||
"UHgqXmuvk2X/Ww==";
|
||||
|
||||
try
|
||||
{
|
||||
KeyFactory fac = KeyFactory.getInstance("RSA");
|
||||
PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(str.getBytes()));
|
||||
return fac.generatePrivate(privKeySpec);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user