@Consumes("application/x-www-form-urlencoded")
@Produces("application/x-www-form-urlencoded")
public Response postReqTokenRequest() {
try {
OAuthServerRequest request = new OAuthServerRequest(hc.getRequest());
OAuthParameters params = new OAuthParameters();
params.readRequest(request);
String tok = params.getToken();
if ((tok != null) && (!tok.contentEquals(""))) {
throw new OAuthException(Response.Status.BAD_REQUEST, null);
}
String consKey = params.getConsumerKey();
if (consKey == null) {
throw new OAuthException(Response.Status.BAD_REQUEST, null);
}
OAuthConsumer consumer = provider.getConsumer(consKey);
if (consumer == null) {
throw new OAuthException(Response.Status.BAD_REQUEST, null);
}
OAuthSecrets secrets = new OAuthSecrets().consumerSecret(consumer.getSecret()).tokenSecret("");
boolean sigIsOk = false;
try {
sigIsOk = OAuthSignature.verify(request, params, secrets);
} catch (OAuthSignatureException ex) {
Logger.getLogger(RequestTokenRequest.class.getName()).log(Level.SEVERE, null, ex);
}
if (!sigIsOk) {
throw new OAuthException(Response.Status.BAD_REQUEST, null);
}
MultivaluedMap<String, String> parameters = new MultivaluedMapImpl();
for (String n : request.getParameterNames()) {
parameters.put(n, request.getParameterValues(n));
}
OAuthToken rt = provider.newRequestToken(consKey, params.getCallback(), parameters);
Form resp = new Form();
resp.putSingle(OAuthParameters.TOKEN, rt.getToken());
resp.putSingle(OAuthParameters.TOKEN_SECRET, rt.getSecret());
resp.putSingle(OAuthParameters.CALLBACK_CONFIRMED, "true");