com.google.api.client.auth.oauth.OAuthHmacSigner Java Examples

The following examples show how to use com.google.api.client.auth.oauth.OAuthHmacSigner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OAuthHmacThreeLeggedFlow.java    From google-oauth-java-client with Apache License 2.0 6 votes vote down vote up
public Credential complete(String authorizationCode) throws IOException {
  Preconditions.checkNotNull(transport, "Must call setHttpTransport before calling complete.");

  OAuthGetAccessToken accessToken = new OAuthGetAccessToken(authorizationServerUrl);
  accessToken.temporaryToken = tempToken;
  accessToken.transport = transport;

  OAuthHmacSigner signer = new OAuthHmacSigner();
  signer.clientSharedSecret = consumerSecret;
  signer.tokenSharedSecret = tempTokenSecret;

  accessToken.signer = signer;
  accessToken.consumerKey = consumerKey;
  accessToken.verifier = authorizationCode;
  OAuthCredentialsResponse credentials = accessToken.execute();
  signer.tokenSharedSecret = credentials.tokenSecret;

  OAuthHmacCredential accessCredential = new OAuthHmacCredential(
      userId, consumerKey, consumerSecret, credentials.tokenSecret, credentials.token);

  return accessCredential;
}
 
Example #2
Source File: AuthorizationFlow.java    From android-oauth-client with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new instance of a token request based on the given verifier
 * code. This step is defined in <a
 * href="http://oauth.net/core/1.0a/#auth_step3">Obtaining an Access
 * Token</a>.
 * 
 * @param temporaryCredentials
 * @param verifierCode
 * @return
 */
public OAuthGetAccessToken new10aTokenRequest(OAuthCredentialsResponse temporaryCredentials,
        String verifierCode) {
    OAuthGetAccessToken request = new OAuthGetAccessToken(getTokenServerEncodedUrl());
    request.temporaryToken = temporaryCredentials.token;
    request.transport = getTransport();

    OAuthHmacSigner signer = new OAuthHmacSigner();
    ClientParametersAuthentication clientAuthentication = (ClientParametersAuthentication) getClientAuthentication();
    signer.clientSharedSecret = clientAuthentication.getClientSecret();
    signer.tokenSharedSecret = temporaryCredentials.tokenSecret;

    request.signer = signer;
    request.consumerKey = clientAuthentication.getClientId();
    request.verifier = verifierCode;
    return request;
}
 
Example #3
Source File: OAuth1Config.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link OAuthSigner} for the access token request
 */
default OAuthSigner getAccessTokenSigner(String clientSecret, String tokenSecret) {
  OAuthHmacSigner signer = new OAuthHmacSigner();
  signer.clientSharedSecret = clientSecret;
  signer.tokenSharedSecret = tokenSecret;
  return signer;
}
 
Example #4
Source File: OAuthAuthenticator.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private OAuthHmacSigner getOAuthHmacSigner(
    @Nullable String clientSecret, @Nullable String oauthTemporaryToken)
    throws NoSuchAlgorithmException, InvalidKeySpecException {
  final OAuthHmacSigner signer = new OAuthHmacSigner();
  signer.clientSharedSecret = clientSecret;
  signer.tokenSharedSecret = sharedTokenSecrets.remove(oauthTemporaryToken);
  return signer;
}
 
Example #5
Source File: OAuthHmacThreeLeggedFlow.java    From google-oauth-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Create an OAuthThreeLeggedFlow instance from the required information.
 *
 * @param userId Key that can be used to associate this flow with an end user.
 * @param consumerKey Key that identifies the server to the service provider.
 * @param consumerSecret Secret that is shared between the server and the service provider.
 * @param authorizationServerUrl Url with which we communicate to authorize tis application.
 * @param temporaryTokenUrl Url which we will use to obtain a temporary token.
 * @param callbackUrl Url which the server should redirect the user to after obtaining
 *        authorization.
 *
 * @throws IOException Exception thrown when the flow is unable to communicate with the service
 *         provider.
 */
public OAuthHmacThreeLeggedFlow(String userId,
    String consumerKey,
    String consumerSecret,
    String authorizationServerUrl,
    String temporaryTokenUrl,
    String callbackUrl,
    HttpTransport transport) throws IOException {

  this.userId = userId;
  this.consumerSecret = consumerSecret;
  this.consumerKey = consumerKey;
  this.transport = transport;
  this.authorizationServerUrl = authorizationServerUrl;

  OAuthGetTemporaryToken temporaryToken = new OAuthGetTemporaryToken(callbackUrl);
  OAuthHmacSigner signer = new OAuthHmacSigner();
  signer.clientSharedSecret = consumerSecret;
  temporaryToken.signer = signer;
  temporaryToken.consumerKey = consumerKey;
  temporaryToken.callback = callbackUrl;
  temporaryToken.transport = this.transport;

  OAuthCredentialsResponse tempCredentials = temporaryToken.execute();

  tempToken = tempCredentials.token;
  tempTokenSecret = tempCredentials.tokenSecret;

  OAuthAuthorizeTemporaryTokenUrl authorizeUrl =
      new OAuthAuthorizeTemporaryTokenUrl(temporaryTokenUrl);
  authorizeUrl.temporaryToken = tempCredentials.token;
  this.authorizationUrl = authorizeUrl.build();
}
 
Example #6
Source File: OAuthHmacCredential.java    From google-oauth-java-client with Apache License 2.0 5 votes vote down vote up
private void postConstruct() {
  OAuthHmacSigner signer = new OAuthHmacSigner();
  signer.clientSharedSecret = sharedSecret;
  signer.tokenSharedSecret = tokenSharedSecret;

  authorizer = new OAuthParameters();
  authorizer.consumerKey = consumerKey;
  authorizer.signer = signer;
  authorizer.token = token;
}
 
Example #7
Source File: OAuthHmacCredential.java    From android-oauth-client with Apache License 2.0 5 votes vote down vote up
private void postConstruct() {
    OAuthHmacSigner signer = new OAuthHmacSigner();
    signer.clientSharedSecret = sharedSecret;
    signer.tokenSharedSecret = tokenSharedSecret;

    authorizer = new OAuthParameters();
    authorizer.consumerKey = consumerKey;
    authorizer.signer = signer;
    authorizer.token = getAccessToken();
}
 
Example #8
Source File: AuthorizationFlow.java    From android-oauth-client with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the response of a Request Token request as defined in <a
 * href="http://oauth.net/core/1.0a/#auth_step1">Obtaining an Unauthorized
 * Request Token</a>.
 * 
 * @param redirectUri the {@code oauth_callback} as defined in <a
 *            href="http://oauth.net/core/1.0a/#rfc.section.6.1.1">Consumer
 *            Obtains a Request Token</a>
 * @return
 * @throws IOException
 */
public OAuthCredentialsResponse new10aTemporaryTokenRequest(String redirectUri)
        throws IOException {
    OAuthGetTemporaryToken temporaryToken =
            new OAuthGetTemporaryToken(getTemporaryTokenRequestUrl());
    OAuthHmacSigner signer = new OAuthHmacSigner();
    ClientParametersAuthentication clientAuthentication = (ClientParametersAuthentication) getClientAuthentication();
    signer.clientSharedSecret = clientAuthentication.getClientSecret();
    temporaryToken.signer = signer;
    temporaryToken.consumerKey = clientAuthentication.getClientId();
    temporaryToken.callback = redirectUri;
    temporaryToken.transport = getTransport();
    return temporaryToken.execute();
}
 
Example #9
Source File: OAuth1Config.java    From data-transfer-project with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the {@link OAuthSigner} for the initial token request
 */
default OAuthSigner getRequestTokenSigner(String clientSecret) {
  OAuthHmacSigner signer = new OAuthHmacSigner();
  signer.clientSharedSecret = clientSecret;
  return signer;
}
 
Example #10
Source File: OAuthSigner.java    From Woocommerce-Android-Client with MIT License 4 votes vote down vote up
public LinkedHashMap<String, String> getSignature(Map<String, String> options, RequestMethod requestMethod, String endpoint) {
    LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();

    OAuthParameters parameters = new OAuthParameters();
    parameters.computeTimestamp();
    parameters.computeNonce();
    parameters.version = "1.0";
    parameters.consumerKey = wooCommerce.getWc_key();
    GenericUrl genericUrl = new GenericUrl();
    genericUrl.setScheme(wooCommerce.isHttps() ? "https" : "http");
    genericUrl.setHost(wooCommerce.getBaseUrl());
    genericUrl.appendRawPath("/wc-api");
    genericUrl.appendRawPath("/v3");
    /*
     *    The endpoint to be called is specified next
     *    */

    genericUrl.appendRawPath(endpoint);

    for (Map.Entry<String, String> entry : options.entrySet())
    {
        System.out.println(entry.getKey() + "/" + entry.getValue());
        genericUrl.appendRawPath("/"+entry.getValue());
    }

    OAuthHmacSigner oAuthHmacSigner = new OAuthHmacSigner();
    oAuthHmacSigner.clientSharedSecret = wooCommerce.getWc_secret();


    parameters.signer = oAuthHmacSigner;
    parameters.signatureMethod = wooCommerce.getSigning_method().getVal();
    try {
        parameters.computeSignature(requestMethod.getVal(), genericUrl);
    } catch (GeneralSecurityException e) {
        e.printStackTrace();
    }

    map.put("oauth_consumer_key", parameters.consumerKey);
    map.put("oauth_signature_method", parameters.signatureMethod);
    map.put("oauth_timestamp", parameters.timestamp);
    map.put("oauth_nonce", parameters.nonce);
    map.put("oauth_version", parameters.version);
    map.put("oauth_signature", parameters.signature);

    genericUrl.put("oauth_consumer_key", parameters.consumerKey);
    genericUrl.put("oauth_signature_method", parameters.signatureMethod);
    genericUrl.put("oauth_timestamp", parameters.timestamp);
    genericUrl.put("oauth_nonce", parameters.nonce);
    genericUrl.put("oauth_version", parameters.version);
    genericUrl.put("oauth_signature", parameters.signature);

    Log.i(TAG,genericUrl.build());


    return map;
}