use of com.google.gdata.client.authn.oauth.GoogleOAuthParameters in project Synapse-Repository-Services by Sage-Bionetworks.
the class SpreadsheetHelper method createSpreadsheetService.
public static SpreadsheetService createSpreadsheetService() throws ServiceException, IOException, OAuthException {
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
String consumerKey = StackConfiguration.getGoogleAppsOAuthConsumerKey();
String consumerSecret = StackConfiguration.getGoogleAppsOAuthConsumerSecret();
String accessToken = StackConfiguration.getGoogleAppsOAuthAccessToken();
String accessTokenSecret = StackConfiguration.getGoogleAppsOAuthAccessTokenSecret();
oauthParameters.setOAuthConsumerKey(consumerKey);
oauthParameters.setOAuthConsumerSecret(consumerSecret);
oauthParameters.setScope(SPREADSHEET_SCOPE);
oauthParameters.setOAuthToken(accessToken);
oauthParameters.setOAuthTokenSecret(accessTokenSecret);
SpreadsheetService googleService = new SpreadsheetService(APPLICATION_NAME);
OAuthSigner signer = new OAuthHmacSha1Signer();
googleService.setOAuthCredentials(oauthParameters, signer);
return googleService;
}
use of com.google.gdata.client.authn.oauth.GoogleOAuthParameters in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthService method validateOauthSignature.
/**
* @param oauthParams
* @param secretKey
* @return
* @throws Exception
*/
private boolean validateOauthSignature(OAuthConsumerDTO oauthParams, String secretKey) throws AuthenticationException {
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(oauthParams.getOauthConsumerKey());
oauthParameters.setOAuthConsumerSecret(secretKey);
oauthParameters.setOAuthNonce(oauthParams.getOauthNonce());
oauthParameters.setOAuthTimestamp(oauthParams.getOauthTimeStamp());
oauthParameters.setOAuthSignatureMethod(oauthParams.getOauthSignatureMethod());
validateTimestampAndNonce(oauthParams.getOauthTimeStamp(), oauthParams.getOauthNonce());
OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer();
String signature;
try {
String baseString = OAuthUtil.getSignatureBaseString(oauthParams.getBaseString(), oauthParams.getHttpMethod(), oauthParameters.getBaseParameters());
signature = signer.getSignature(baseString, oauthParameters);
} catch (OAuthException e) {
throw new AuthenticationException(e.getMessage(), e);
}
if (signature != null && URLEncoder.encode(signature).equals(oauthParams.getOauthSignature())) {
return true;
} else if (signature != null && signature.equals(oauthParams.getOauthSignature())) {
return true;
}
return false;
}
use of com.google.gdata.client.authn.oauth.GoogleOAuthParameters in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthServiceTest method getConsumerSignature.
private String getConsumerSignature(OAuthConsumerDTO oAuthConsumer, String consumerSecret) throws OAuthException {
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(oAuthConsumer.getOauthConsumerKey());
oauthParameters.setOAuthConsumerSecret(consumerSecret);
oauthParameters.setOAuthNonce(oAuthConsumer.getOauthNonce());
oauthParameters.setOAuthTimestamp(oAuthConsumer.getOauthTimeStamp());
oauthParameters.setOAuthSignatureMethod(oAuthConsumer.getOauthSignatureMethod());
OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer();
String baseString = OAuthUtil.getSignatureBaseString(oAuthConsumer.getBaseString(), oAuthConsumer.getHttpMethod(), oauthParameters.getBaseParameters());
return signer.getSignature(baseString, oauthParameters);
}
use of com.google.gdata.client.authn.oauth.GoogleOAuthParameters in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthService method validateOauthSignature.
/**
* @param oauthParams
* @param secretKey
* @return
* @throws Exception
*/
private boolean validateOauthSignature(Parameters oauthParams, String secretKey, String tokenSecret) throws AuthenticationException {
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(oauthParams.getOauthConsumerKey());
oauthParameters.setOAuthConsumerSecret(secretKey);
oauthParameters.setOAuthNonce(oauthParams.getOauthNonce());
oauthParameters.setOAuthTimestamp(oauthParams.getOauthTimeStamp());
oauthParameters.setOAuthSignatureMethod(oauthParams.getOauthSignatureMethod());
if (oauthParams.getOauthToken() != null) {
oauthParameters.setOAuthToken(oauthParams.getOauthToken());
}
if (oauthParams.getOauthTokenVerifier() != null) {
oauthParameters.setOAuthVerifier((oauthParams.getOauthTokenVerifier()));
}
if (tokenSecret != null) {
oauthParameters.setOAuthTokenSecret(tokenSecret);
}
OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer();
String signature;
try {
String baseString = OAuthUtil.getSignatureBaseString(oauthParams.getBaseString(), oauthParams.getHttpMethod(), oauthParameters.getBaseParameters());
signature = signer.getSignature(baseString, oauthParameters);
} catch (OAuthException e) {
throw new AuthenticationException("Error while validating signature");
}
if (signature != null && URLEncoder.encode(signature).equals(oauthParams.getOauthSignature())) {
return true;
} else if (signature != null && signature.equals(oauthParams.getOauthSignature())) {
return true;
}
return false;
}
use of com.google.gdata.client.authn.oauth.GoogleOAuthParameters in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthServiceTest method getConsumerSignature.
private String getConsumerSignature(Parameters parameters, String consumerSecret, String tokenSecret) throws OAuthException {
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(parameters.getOauthConsumerKey());
oauthParameters.setOAuthConsumerSecret(consumerSecret);
oauthParameters.setOAuthNonce(parameters.getOauthNonce());
oauthParameters.setOAuthTimestamp(parameters.getOauthTimeStamp());
oauthParameters.setOAuthSignatureMethod(parameters.getOauthSignatureMethod());
if (parameters.getOauthToken() != null) {
oauthParameters.setOAuthToken(parameters.getOauthToken());
}
if (parameters.getOauthTokenVerifier() != null) {
oauthParameters.setOAuthVerifier((parameters.getOauthTokenVerifier()));
}
if (StringUtils.isNotEmpty(tokenSecret)) {
oauthParameters.setOAuthTokenSecret(tokenSecret);
}
OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer();
String baseString = OAuthUtil.getSignatureBaseString(parameters.getBaseString(), parameters.getHttpMethod(), oauthParameters.getBaseParameters());
return signer.getSignature(baseString, oauthParameters);
}
Aggregations