Saturday, May 15, 2010

OAuth (Yahoo FireEagle) in J2ME

OAuth is an open authentication protocol. google, twiter, yahoo , facebook are using oauth for authentication of their API access.
If you want to implement any of the API that requires oauth authentication, first you have to implement oauth. Simon King wrote an OAuth library for J2ME http://github.com/simonpk/j2me-oauth/tree/master
Here i am going to explain you. User of this library for yahoo fire eagle API.
1. First of all you require
a. consumer token
b. consumer secret
c. App id.
2. Request token:
Required Parameters
oauth_consumer_key : application consumer key
oauth_callback : set this to a value of 'oob'
oauth_nonce: A random string
 oauth_timestamp:Current timestamp of the request. This value must be +-600 seconds of the current time.
 oauth_signature_method:The signature method that you use to sign the request. This can be plaintext or hmac-sha1.
 oauth_version:OAuth version (1.0)
 oauth_signature:Your shared secret.

 FireEagleConsumer fireEagleClient = FireEagleConsumer(OAUTH_CONSUMER_TOKEN, OAUTH_CONSUMER_SECRET);
 RequestToken requestToken = fireEagleClient.fetchNewRequestToken();   
2. Verification:

now user will open http://m.fireeagle.yahoo.net/oauth/mobile_auth/[YOU_APP_ID] this link on browser and enter request key manually.browser will display the verify string.
3. Access token.
requred parameters all same as request token except oauth_callback with two new parameters.
oauth_verifier : verification code keyed in by user in step 2.
oauth_token : the request_token that you obtained in step one.

 AccessToken accessToken==fireEagleClient.fetchNewAccessToken(verifier);
now user will enter the verifier string in application and application will get the access token and secret key.
This access token and secret key application will use for further api calls
you can download full midlet code of yahoo fire eagle from here.

if you want to explore more about oauth



1 comment: