Search in sources :

Example 1 with GoogleOAuthParameters

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;
}
Also used : GoogleOAuthParameters(com.google.gdata.client.authn.oauth.GoogleOAuthParameters) SpreadsheetService(com.google.gdata.client.spreadsheet.SpreadsheetService) OAuthSigner(com.google.gdata.client.authn.oauth.OAuthSigner) OAuthHmacSha1Signer(com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer)

Example 2 with GoogleOAuthParameters

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;
}
Also used : GoogleOAuthParameters(com.google.gdata.client.authn.oauth.GoogleOAuthParameters) AuthenticationException(org.wso2.carbon.core.common.AuthenticationException) OAuthException(com.google.gdata.client.authn.oauth.OAuthException) OAuthHmacSha1Signer(com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer)

Example 3 with GoogleOAuthParameters

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);
}
Also used : GoogleOAuthParameters(com.google.gdata.client.authn.oauth.GoogleOAuthParameters) Matchers.anyString(org.mockito.Matchers.anyString) OAuthHmacSha1Signer(com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer)

Example 4 with GoogleOAuthParameters

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;
}
Also used : GoogleOAuthParameters(com.google.gdata.client.authn.oauth.GoogleOAuthParameters) AuthenticationException(org.wso2.carbon.core.common.AuthenticationException) OAuthException(com.google.gdata.client.authn.oauth.OAuthException) OAuthHmacSha1Signer(com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer)

Example 5 with GoogleOAuthParameters

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);
}
Also used : GoogleOAuthParameters(com.google.gdata.client.authn.oauth.GoogleOAuthParameters) Matchers.anyString(org.mockito.Matchers.anyString) OAuthHmacSha1Signer(com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer)

Aggregations

GoogleOAuthParameters (com.google.gdata.client.authn.oauth.GoogleOAuthParameters)6 OAuthHmacSha1Signer (com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer)6 OAuthException (com.google.gdata.client.authn.oauth.OAuthException)2 OAuthSigner (com.google.gdata.client.authn.oauth.OAuthSigner)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AuthenticationException (org.wso2.carbon.core.common.AuthenticationException)2 GoogleOAuthHelper (com.google.gdata.client.authn.oauth.GoogleOAuthHelper)1 SpreadsheetService (com.google.gdata.client.spreadsheet.SpreadsheetService)1