org.apache.shindig.social.sample.oauth
Class SampleOAuthDataStore

java.lang.Object
  extended by org.apache.shindig.social.sample.oauth.SampleOAuthDataStore
All Implemented Interfaces:
OAuthDataStore

public class SampleOAuthDataStore
extends Object
implements OAuthDataStore

Sample implementation for OAuth data store


Constructor Summary
SampleOAuthDataStore(JsonDbOpensocialService dbService, String baseUrl)
           
 
Method Summary
 void authorizeToken(OAuthEntry entry, String userId)
          Authorize the request token for the given user id.
 OAuthEntry convertToAccessToken(OAuthEntry entry)
          Called when converting a request token to an access token.
 void disableToken(OAuthEntry entry)
          Mark a token DISABLED and store it.
 OAuthEntry generateRequestToken(String consumerKey, String oauthVersion, String signedCallbackUrl, String virtualOrganization)
          Generate a valid requestToken for the given consumerKey.
 net.oauth.OAuthConsumer getConsumer(String consumerKey)
          Lookup consumers.
 OAuthEntry getEntry(String oauthToken)
          Get the OAuthEntry that corresponds to the oauthToken.
 SecurityToken getSecurityTokenForConsumerRequest(String consumerKey, String userId, net.oauth.OAuthConsumer authConsumer)
          Return the proper security token for a 2 legged oauth request that has been validated for the given consumerKey.
 void removeToken(OAuthEntry entry)
          Remove a token
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SampleOAuthDataStore

@Inject
public SampleOAuthDataStore(JsonDbOpensocialService dbService,
                                   String baseUrl)
Method Detail

getEntry

public OAuthEntry getEntry(String oauthToken)
Description copied from interface: OAuthDataStore
Get the OAuthEntry that corresponds to the oauthToken.

Specified by:
getEntry in interface OAuthDataStore
Parameters:
oauthToken - a non-null oauthToken
Returns:
a valid OAuthEntry or null if no match

getConsumer

public net.oauth.OAuthConsumer getConsumer(String consumerKey)
Description copied from interface: OAuthDataStore
Lookup consumers. Generally this corresponds to an opensocial Application but could be abstracted in other ways. If you have multiple containers you may want to include the container as part of the identifier. Your consumer object should have the key and secret, a link to your provider plus you should consider setting properties that correspond to the metadata in the opensocial app like icon, description, etc. Returning null will inform the client that the consumer key does not exist. If you want to control the error response throw an OAuthProblemException

Specified by:
getConsumer in interface OAuthDataStore
Parameters:
consumerKey - A valid, non-null ConsumerKey
Returns:
the consumer object corresponding to the specified key.

generateRequestToken

public OAuthEntry generateRequestToken(String consumerKey,
                                       String oauthVersion,
                                       String signedCallbackUrl,
                                       String virtualOrganization)
Description copied from interface: OAuthDataStore
Generate a valid requestToken for the given consumerKey.

Specified by:
generateRequestToken in interface OAuthDataStore
Parameters:
consumerKey - A valid consumer key
oauthVersion - The version (1 or 1a)
signedCallbackUrl - Callback URL sent from consumer, may be null. If callbackUrl is not null then the returned entry should have signedCallbackUrl set to true.
virtualOrganization - the virtualOrganization context (if any)
Returns:
An OAuthEntry containing a valid request token.

convertToAccessToken

public OAuthEntry convertToAccessToken(OAuthEntry entry)
Description copied from interface: OAuthDataStore
Called when converting a request token to an access token. This is called in the final phase of 3-legged OAuth after the user authorizes the app.

Specified by:
convertToAccessToken in interface OAuthDataStore
Parameters:
entry - The Entry to convert
Returns:
a new entry with type Type.ACCESS

authorizeToken

public void authorizeToken(OAuthEntry entry,
                           String userId)
Description copied from interface: OAuthDataStore
Authorize the request token for the given user id.

Specified by:
authorizeToken in interface OAuthDataStore
Parameters:
entry - A valid OAuthEntry
userId - A user id

disableToken

public void disableToken(OAuthEntry entry)
Description copied from interface: OAuthDataStore
Mark a token DISABLED and store it.

Specified by:
disableToken in interface OAuthDataStore
Parameters:
entry - A valid OAuthEntry

removeToken

public void removeToken(OAuthEntry entry)
Description copied from interface: OAuthDataStore
Remove a token

Specified by:
removeToken in interface OAuthDataStore
Parameters:
entry - A valid OAuthEntry

getSecurityTokenForConsumerRequest

public SecurityToken getSecurityTokenForConsumerRequest(String consumerKey,
                                                        String userId,
                                                        net.oauth.OAuthConsumer authConsumer)
Description copied from interface: OAuthDataStore
Return the proper security token for a 2 legged oauth request that has been validated for the given consumerKey. App specific checks like making sure the requested user has the app installed should take place in this method. Returning null may allow for other authentication schemes to be used. Throwing an OAuthProblemException will allows errors to be returned to the caller.

Specified by:
getSecurityTokenForConsumerRequest in interface OAuthDataStore
Parameters:
consumerKey - A consumer key
userId - The userId to validate.
authConsumer - The OAuthConsumer
Returns:
A valid Security Token


Copyright © 2007-2012. All Rights Reserved.