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());
}
}
Aggregations