Research Log of Web Science Students

Computer Science is not simply programming

A Software Engineering Problem: using client libraries for OAuth

with one comment

I just realized using client libraries doesn’t lend itself for a good system design as compared to doing manual requests.

I am making an interface so my controller handles oauth will be loosely coupled from the processing of oauth requests/response and now I am stuck with this design dilemna:

How to program extracting the AccessToken on callback to an interface. We’re accessing GoogleDocs and Twitter accounts via Oauth using Client libraries GData and Twitter4j respectively.

The GData client library does it this way:

                           (request.getQueryString(), oauthParameters);

in Twitter4j:

AccessToken accessToken 
       = twitter.getOAuthAccessToken(token, tokenSecret);

My problem is to try to encapsulate these two lines of code to
an interface. I just want the interface method to return the AccessToken with token and tokenSecret bundled in (I already have
a class that does this see below) so that in my controller I just need to call a method like this:

public interface Provider {
        ....//other interface methods
	public UserOAuthAccessToken getAccessToken();

and the controller gets the UserOAuthAccessToken with the token
and tokenSecret bundled in without having to know which concrete
implemenation he’s dealing with.


public ModelAndView callback(HttpServletRequest request, 
			HttpServletResponse response){
String providerRequested = request.getParameter("provider");

// returns provider specific implemenation, see method implemenation 
// below, 
Provider provider = getProvider(providerRequested);

OAuthAccessToken accessToken = provider.getAccessToken()			
private Provider getProvider(String providerRequested){
     Provider provider = null;
     if ("googledocs".equals(providerRequested)){
		provider = new GoogleDocs();
     if ("twitter".equals(providerRequested)){
               provider = new TwitterClient();
     return provider;

See how the controller doesn’t know any provider specific implementation? Whether we’re getting the access token from Twitter or from GoogleDocs it shouldn’t matter.

The problem is that the GData client library and Twitter client library requires different parameters:

For GData client library

1. java.lang.String. queryString

2.; oauthParameter

For Twitter client library

1. java.lang.String token

2. java.lang.String tokenSecret


Written by Jose Asuncion

October 3, 2009 at 11:24 am

One Response

Subscribe to comments with RSS.

  1. […] For my Software Engineering problem Like I did with my Twitter4J solution. I stored the token and tokenSecret to session and used it at the callback to get an access Token. […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: