Re: Howe to send a successful "reqtoken" request in Java?

149 views
Skip to first unread message

Nico Witteman

unread,
Apr 29, 2013, 3:58:23 AM4/29/13
to car2go-...@googlegroups.com

Dirk,
Please refer to the oauth documentation for understanding how to proceed.
Nico

Op 29 apr. 2013 08:38 schreef "Dirk V. Schesmer" <dirk.s...@gmail.com> het volgende:
Hi there,

I am trying to get the car2go "reqtoken" POST request up and running using Java 7 and the Apache HttpClient 4 libraries.

Unfortunately, the car2go system's response is always:

<HTTP/1.1 401 Unauthorized [Date: Sun, 28 Apr 2013 14:37:49 GMT, Server: IBM_HTTP_Server, WWW-Authenticate: OAuth realm="car2go_api", oauth_problem="signature_invalid", Vary: Accept-Encoding,User-Agent, Content-Length: 0, Keep-Alive: timeout=10, max=100, Connection: Keep-Alive, Content-Type: text/plain, Content-Language: en-US]

I added my Java code below, any hint to get it up and running is very welcome !

Thanks for your help!

Dirk
Stuttgart/Germany

---------
private void executeCar2Go() {

String requestUrl = "https://www.car2go.com/api/reqtoken";

       HttpClient client = new DefaultHttpClient();
       HttpPost post = new HttpPost(requestUrl);

       try {
           List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
           nameValuePairs.add(new BasicNameValuePair("oauth_callback", "oob"));
           nameValuePairs.add(new BasicNameValuePair("oauth_consumer_key", "<my consumer key>"));

           nameValuePairs.add(new BasicNameValuePair("oauth_nonce", "6201190"));
           nameValuePairs.add(new BasicNameValuePair("oauth_signature_method", "HMAC-SHA1"));

           String ts = "" + (System.currentTimeMillis() / 1000);

           nameValuePairs.add(new BasicNameValuePair("oauth_timestamp", ts));
           nameValuePairs.add(new BasicNameValuePair("oauth_version", "1.0"));
           nameValuePairs.add(new BasicNameValuePair("oauth_signature", "<my shared secret>")); // same as "my encoded signature" ??

           post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
           HttpResponse response = client.execute(post);
           System.out.println("response: " + response);

           BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

           String line = "";
           while ((line = rd.readLine()) != null) {
               System.out.println(line);
           }
       } catch (IOException e) {
           e.printStackTrace();
       }
   }

--
You received this message because you are subscribed to the Google Groups "car2go OpenAPI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to car2go-openap...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dirk V. Schesmer

unread,
Apr 30, 2013, 6:28:46 AM4/30/13
to car2go-...@googlegroups.com
Well,
Sorry, but just to have a look at the oauth/net specification chapter 2.1 does not help me, I still do not see what I am doing incorrectly!

Thanks for a more detailled hint what my Java code does not do correctly!

Dirk Schesmer

Nico Witteman

unread,
May 1, 2013, 2:37:46 AM5/1/13
to car2go-...@googlegroups.com
Dirk,
My advice: find yourself a good oauth library for Java, and let it handle
the signing etc. for you. It is far too complicated to do this yourself.
Examples here: http://oauth.net/code/

I can't help you further, since my code is in c#.

Kind regards,
Nico Witteman





-----Oorspronkelijk bericht-----
Van: car2go-...@googlegroups.com
[mailto:car2go-...@googlegroups.com] Namens Dirk V. Schesmer
Verzonden: dinsdag 30 april 2013 12:29
Aan: car2go-...@googlegroups.com
Onderwerp: Re: Howe to send a successful "reqtoken" request in Java?

Dirk V. Schesmer

unread,
May 1, 2013, 10:07:25 AM5/1/13
to car2go-...@googlegroups.com
Nico,

I finally got it up and running in Java using the Scribe library! The only still outstanding point is to get rid of the login dialog popping up offering me the verifier code needed for further processing after a successful login. I think about getting rid of the login dialog and somehow to pass credentials, securely...

Thx for help,

Dirk

Nico Witteman

unread,
May 1, 2013, 10:20:18 AM5/1/13
to car2go-...@googlegroups.com

Dirk,
You cannot get rid of te first login to the car2go site, because that is where the user must grant the permission. The verifier code does not have to be shown to and copied by the user, you can ask car2go (send them an e-mail) to redirect to a server page of your own where you can handle the transfer of the verifier yourself. You could temporarily store it next to the requesttoken for instance, and then have your application retrieve it and use it for the next step. You must store the access token and accesstokensecret safely in your application environment.
Good luck,
Nico

Op 1 mei 2013 16:07 schreef "Dirk V. Schesmer" <dirk.s...@gmail.com> het volgende:

Dirk V. Schesmer

unread,
May 2, 2013, 9:26:30 AM5/2/13
to car2go-...@googlegroups.com
Nico,
thanks for your hint, I was indeed already tying for a while to get my callback URL to be invoked after a successful login, but without any success an now I understand the sentence in the car2go OpenApi doc:
"We ignore callback URLs passed to request token endpoint. You may provide a callback URL during registration as a consumer." So I sent an email to the car2go-Team asking to extend my consumer profile.

CU, Dirk
Reply all
Reply to author
Forward
0 new messages