Thursday Apr 15, 2010

JavaFX + OAuth


As usual will start off with Wikipedia - OAuth (Open Authorization) - is an open standard that allows users to share their private resources (e.g. photos, videos, contact lists) stored on one site with another site without having to hand out their username and password. With more and more services moving to OAuth model, I think we need to try to have a generic implementation. Here is an attempt...

I prefer not to duplicate all those details available in various resources, so suggest to read few articles if you are not familiar with concepts of OAuth. Yahoo has a very detailed article outlining the flow of OAuth authorization or Beginner's Guide to OAuth from Hueniverse. Please refer to same for more info..

You can try out yourself with demo below. You need to get consumer-key and consumer-secret from respective service providers - Twitter, LinkedIn or Yahoo

<script src="http://dl.javafx.com/1.2/dtfx.js"></script><script src="http://javafxdemos.googlecode.com/hg/resource/JavaFXOAuth/JavaFXOAuth.js"></script>


To launch click on above image or

First enter oauth_consumer_key and oauth_secret_key, click "Request Token" button. If key is proper, you will receive a message in log with a URL. Copy and paste that URL in browser and follow the instructions. Once you grant access to your application, it will return a number. Copy the number and paste it as oauth_verifier. Now click on "Access Token" button. It will return you oauth_token and oauth_token_secret which can be used for all subsequent communication.

Yes its a bit difficult to understand the overall flow and implementation. I have tried my best to simplify it. The API may be simplified a bit more. I have signed up for contributing to JFXtras long time back, but haven't done anything yet. My objective was to pull in the various parsers that are used in different samples and create a library. I think all these can be incorporated into that...

Usage:

def oauthAPI = OAuthAPI.getInstance(
    <Service-Provider>, 
    <oauth_consumer_key>,
    <oauth_consumer_secret>
);

// Request Token Callback
oauthAPI.onRequestToken = function(response:String: Void {

}

// Access Token Callback
oauthAPI.onAccessToken = function(response:String: Void {

}

// Request Token
oauthAPI.requestToken();

// Access Token
oauthAPI.accessToken(<oauth_verifier>);
 

Refer to LinkedInAPI.fx to get an idea on how we can extend the implementation to have fulll fledged support.

Please try it out and let me know your suggestions and feedback..


<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="http://javafxdemos.googlecode.com/hg/resource/JavaFXOAuth/zoneit.js"></script>

About


The views expressed on this blog are my own and do not necessarily reflect that of my organization

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today