Back to oDesk.com » Love the way you work.

Welcome to the oDesk Community! Connect here with fellow clients, contractors, and oDesk staff. Please review our Usage Policy.

oAuth Java desktop application

Hi all.

I can't understand how to use oAuth authorization in desktop app (JavaFX / Win 7). I have to use authorization due of job find API algorithm https://www.odesk.com/community/node/27938. oAuth client is my application on my computer. So I don't see any reason to open browser to authorize myself, and receive token from browser... I look the way to make this without browser at all. Is it possible and reasonable in Java for desktop? It is fine to use web application, but may be a bit later...

Nevertheless,

I looked and tried http://developers.odesk.com/w/page/12364001/Examples and take java example. After adding libs, my NetBeans still marks red:

onCreate()
Intent
Uri
uid

As I understand it is for web ... Is any examples for desktop?

Thanks.

Vote Result

----------
Score: 0.0, Votes: 0
Pavel, a user, who uses an

Pavel,

a user, who uses an app (no matter that it is yours), must enter credentials and authorize the app - this is a requirement of OAuth protocol.
Because of security reasons, it is a requirement of RFC 5849 to enter credentials on the side of 'provider', in your case - oDesk.
Hence, you should provide an interface (e.g. open browser) to end user who will be able login at oDesk and authorize your app.

Try to check nonweb examples written in PHP as well.

Let's look example

Hi, Java example here:

http://developers.odesk.com/w/page/12364001/Examples

I take few first lines. It stops with exception...
Profiler shows that it in: String url = api.getAuthUrl();
But it is not JSONException ...
Why api not get auth url?


String secret = "xxx";
String api_key = "xxx";
oDeskAPI api = new oDeskAPI(secret, api_key);
try {
// get auth url to open in system's browser
String url = api.getAuthUrl();
} catch (JSONException e) {
e.printStackTrace();
}

By the way in example "String" missed... why?

Here error message

Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.javafx.main.Main.launchApp(Main.java:642)
at com.javafx.main.Main.main(Main.java:805)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NoClassDefFoundError: android/util/Log
at com.oDesk.api.oDeskAPI.normalizeParams(oDeskAPI.java:311)
at com.oDesk.api.oDeskAPI.normalizeParams(oDeskAPI.java:317)
at com.oDesk.api.oDeskAPI.calcApiSig(oDeskAPI.java:285)
at com.oDesk.api.oDeskAPI.calcApiSig(oDeskAPI.java:290)
at com.oDesk.api.oDeskAPI.getFrob(oDeskAPI.java:229)
at com.oDesk.api.oDeskAPI.getAuthUrl(oDeskAPI.java:83)
at oauthtest.OAuthTest.start(OAuthTest.java:147)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
... 1 more
Caused by: java.lang.ClassNotFoundException: android.util.Log
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 14 more

It is an example for Token

It is an example for Token Based authorization.

So what?

"Token Based authorization" - What manual describes this? I looked rfc5849, so OAuth 1.0 is token based... I understand that clear!

I asked you about getAuthUrl() - why it not works as described in http://developers.odesk.com/w/page/12363997/API%20Libraries ? What to use instead ? Or OdeskApi works only on Android? Here from man, there is nothing about "Token Based authorization":

getAuthUrl() - return authentication url. The URL can be opened in system's browser for authorizing access to application.

What method of oDeskAPI I have to use first? Or is there any other ability to make "Temporary Credential Request" (rfc5849 p.5)

Pavlo, oDesk provides two

Pavlo,

oDesk provides two ways of authentication, it is described in the documentation - developers.odesk.com/Authentication

Please check it and you will find that this example is for Token Based (APIKeys) type. At the same type you are trying to use it as OAuth library, which is wrong.

In case you need Java lib for OAuth, please check official source that recommends a good list.

Thank for you patience

Hello, Maksym.

I'm sorry for my mistake, with two different authentication methods. Really i
find out what you talking about. I find the way to solve my problem. Thank you, and oDesk team for API!

So from here I offer to you look at Examples page. When I read it I don't understand that it shows two different approaches. May be "Token based" looks similar to "OAuth" because of RFC 5849 often use "token" terms. May be you will find some point to make this info more readable, in sens that it different. I searched method to solve problem but find that many people have the same question. Also it will be good to make little table on first page with platforms that tested authorization.

I tried to use OAuth (as recomended) with libraries. It become a trouble, because OAuth 1.0 project seems to stop. Examples with Java libraries on official site not started (most of them 2008-2009) community very weak, so I do not find the way to start it. Other sites that use OAuth more friendly with Java libs (as it seems to me).

I also tried not recommended Token Based, and also have unsolved problem. The example given not started on Java SE. I saw that it tested for android... but i don't use it.

So I have to solve the problem with method that I don't find on your manuals Smile. In my early question https://www.odesk.com/community/node/27938 Dmitry pointed to log in in browser. I step this way and make JavaFX embedded in browser. It works! Now I test it.

With best regards, Pavlo.

Pavlo, thank you for your

Pavlo,

thank you for your comprehensive reply.
We will check what we can do to make our documentation more readable.

As for OAuth, it is a standard that was released a couple years ago and contains enough libraries in majority of langueges, therefore, there is not a big number of newly created libs.

As for Java, i personally tried Signpost and it worked well, but it is up to you to decide what to choose according to needs of your project.