This document was generated from CDN thread Created by: Vinay Kanakath on 24-07-2012 06:00:57 PM Hi,i am trying to use aAuth on a local webex quad server instance. i am using a java client for this. below is the code i am using. i am always getting a 500 server error with a message saying missing security token.i have tried a very similar code snippet in c# and it works, i get the consumer key and consumer secret. Can anyone tell me what is missing in the below code? <font size="2">URL url = </font> new URL("http://f180373441956.il.bankofamerica.com:8080/api/quad/rest/management/apiconsumers");<font size="2"> </font> //http://f180373441956.il.bankofamerica.com:8080/api/quad/rest/management/apiconsumers HttpURLConnection conn =(HttpURLConnection) url.openConnection();<font size="2">conn.setRequestMethod(</font> "POST");<font size="2">conn.setDoOutput(</font> true);<font size="2">conn.setDoInput(</font> true);<font size="2">conn.setUseCaches(</font> false);<font size="2">conn.setAllowUserInteraction(</font> false); <font size="2">conn.setRequestProperty(</font> "Content-Type",<font size="2"> </font> "application/xml");<font size="2">conn.setRequestProperty(</font> "Accept", "application/xml"); <font size="2">conn.setRequestProperty(</font> "Authorization","Basic userid:password");<font size="2"> </font> <font size="2">String xmlInput=</font> "<apiconsumer><callbackUrl>http://RNYXWTCRS11L1.corp.bankofamerica.com:8080</callbackUrl><description>Quad Mobile App</description><modifiedDate>1316741399291</modifiedDate><name>Quad Mobile App</name></apiconsumer>";OutputStream out = conn.getOutputStream();<font size="2">Writer writer = </font> new OutputStreamWriter(out, "UTF-8");out.write(xmlInput.getBytes());conn.connect(); <font size="2">System.</font> out.println("response code"+conn.getResponseCode());<font size="2">System.</font> out.println("response error "+conn.getResponseMessage());<font size="2">BufferedReader rd1 = </font> newBufferedReader(<font size="2"> </font> newInputStreamReader(conn.getErrorStream()));<font size="2">StringBuilder sb1 = </font> newStringBuilder();String line1;<font size="2"> </font> while ((line1 = rd1.readLine()) != null) {sb1.append(line1);}<font size="2">System.</font> out.println(sb1.toString());<font size="2">BufferedReader rd = </font> newBufferedReader(<font size="2"> </font> newInputStreamReader(conn.getInputStream()));<font size="2">StringBuilder sb = </font> newStringBuilder();String line;<font size="2"> </font> while ((line = rd.readLine()) != null) {sb.append(line);}rd.close(); conn.disconnect();writer.close();out.close();<font size="2">System.</font> out.println(sb.toString());Subject: RE: Not able to consume oAuth api's using a java client Replied by: Adrienne Moherek on 25-07-2012 05:40:50 PMHi Vinay,This is the authorization part of the code that is not working for you:conn.setRequestProperty("Authorization","Basic userid:password");The username and password need to be encoded for this to work. Thanks,AdrienneSubject: RE: Not able to consume oAuth api's using a java client Replied by: Vinay Kanakath on 25-07-2012 08:02:49 PMHi Adriennewill normal utf-8 encoding work or it needs to be base 64? reason i ask is when i set the the request header with a base 64 encoded value i get an Illegal character exceptionSubject: RE: Not able to consume oAuth api's using a java client Replied by: Adrienne Moherek on 27-07-2012 03:45:56 PMHi Vinay,It needs to be base 64 encoded. I have not had that problem with Basic Authentication. It should look like a string of numbers and letters. Example:1Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Here's some info about Basic Authentication: http://en.wikipedia.org/wiki/Basic_access_authenticationSubject: RE: Not able to consume oAuth api's using a java client Replied by: Vinay Kanakath on 02-08-2012 09:18:55 AMThanks Adrienne,forgot to add an update, this was resolved.Cause:- turns out HttpUrConnection class has a bug with basic authentication. i changed the class to DefaultHttpClient and it now works