OAuthServiceProvider provider;
OAuthConsumer consumer;
OAuthAccessor accessor;
OAuthClient client = new OAuthClient(new URLConnectionClient());
oAuthParams.setErrorMessage(null);
String temporaryCredentialsEndpointUrl = oAuthParams.getTemporaryCredentialsEndpoint();
if (temporaryCredentialsEndpointUrl == null || "".equals(temporaryCredentialsEndpointUrl)) {
oAuthParams.setErrorMessage("Missing temporary credentials endpoint url");
}
String clientId = oAuthParams.getClientID();
if (clientId == null || "".equals(clientId)) {
oAuthParams.setErrorMessage("Missing client identifier");
}
String secret = oAuthParams.getClientSecret();
if (secret == null || "".equals(secret)) {
oAuthParams.setErrorMessage("Missing client shared-secret");
}
if (oAuthParams.getErrorMessage() == null) {
provider = new OAuthServiceProvider(temporaryCredentialsEndpointUrl,
oAuthParams.getResourceOwnerAuthorizationEndpoint(), oAuthParams.getTokenRequestEndpoint());
consumer = new OAuthConsumer(null, clientId,
secret,
provider);
accessor = new OAuthAccessor(consumer);
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, oAuthParams.getSignatureMethod());
parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString());
parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000));
parameters.put(OAuth.OAUTH_CALLBACK, oAuthParams.getCallbackURL());
parameters.put("realm", "private");
parameters.put("x_oauth_scope", "read_info,modify_info");
parameters.put("x_oauth_uri", "/resources/person/*");
try {
accessor.consumer
.setProperty(OAuthClient.PARAMETER_STYLE, ParameterStyle.AUTHORIZATION_HEADER);
client.getRequestToken(accessor, OAuthMessage.POST, parameters.entrySet());
} catch (Exception e) {
oAuthParams.setErrorMessage(e.toString());
}
oAuthParams.setOauthToken(accessor.requestToken);