Search in sources :

Example 1 with OAuthAuthorizeTemporaryTokenUrl

use of com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl in project che by eclipse.

the class OAuthAuthenticator method getAuthenticateUrl.

/**
     * Create authentication URL.
     *
     * @param requestUrl
     *         URL of current HTTP request. This parameter required to be able determine URL for redirection after
     *         authentication. If URL contains query parameters they will be copied to 'state' parameter and returned to
     *         callback method.
     * @param requestMethod
     *         HTTP request method that will be used to request temporary token
     * @param signatureMethod
     *         OAuth signature algorithm
     * @return URL for authentication.
     * @throws OAuthAuthenticationException
     *         if authentication failed.
     */
String getAuthenticateUrl(final URL requestUrl, @Nullable final String requestMethod, @Nullable final String signatureMethod) throws OAuthAuthenticationException {
    try {
        final GenericUrl callbackUrl = new GenericUrl(redirectUri);
        callbackUrl.put(STATE_PARAM_KEY, requestUrl.getQuery());
        OAuthGetTemporaryToken temporaryToken;
        if (requestMethod != null && "post".equals(requestMethod.toLowerCase())) {
            temporaryToken = new OAuthPostTemporaryToken(requestTokenUri);
        } else {
            temporaryToken = new OAuthGetTemporaryToken(requestTokenUri);
        }
        if (signatureMethod != null && "rsa".equals(signatureMethod.toLowerCase())) {
            temporaryToken.signer = getOAuthRsaSigner();
        } else {
            temporaryToken.signer = getOAuthHmacSigner(null, null);
        }
        temporaryToken.consumerKey = clientId;
        temporaryToken.callback = callbackUrl.build();
        temporaryToken.transport = httpTransport;
        final OAuthCredentialsResponse credentialsResponse = temporaryToken.execute();
        final OAuthAuthorizeTemporaryTokenUrl authorizeTemporaryTokenUrl = new OAuthAuthorizeTemporaryTokenUrl(authorizeTokenUri);
        authorizeTemporaryTokenUrl.temporaryToken = credentialsResponse.token;
        sharedTokenSecrets.put(credentialsResponse.token, credentialsResponse.tokenSecret);
        return authorizeTemporaryTokenUrl.build();
    } catch (Exception e) {
        throw new OAuthAuthenticationException(e.getMessage());
    }
}
Also used : OAuthGetTemporaryToken(com.google.api.client.auth.oauth.OAuthGetTemporaryToken) GenericUrl(com.google.api.client.http.GenericUrl) OAuthAuthorizeTemporaryTokenUrl(com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) GeneralSecurityException(java.security.GeneralSecurityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OAuthCredentialsResponse(com.google.api.client.auth.oauth.OAuthCredentialsResponse)

Aggregations

OAuthAuthorizeTemporaryTokenUrl (com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl)1 OAuthCredentialsResponse (com.google.api.client.auth.oauth.OAuthCredentialsResponse)1 OAuthGetTemporaryToken (com.google.api.client.auth.oauth.OAuthGetTemporaryToken)1 GenericUrl (com.google.api.client.http.GenericUrl)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1