Spring Social

org.springframework.social.connect.support
Class OAuth2ConnectionFactory<S>

java.lang.Object
  extended by org.springframework.social.connect.ConnectionFactory<S>
      extended by org.springframework.social.connect.support.OAuth2ConnectionFactory<S>
Type Parameters:
S - the service API type.

public class OAuth2ConnectionFactory<S>
extends ConnectionFactory<S>

Factory for creating OAuth2-based Connections. May be subclassed to further simplify construction e.g. FacebookConnectionFactory.

Author:
Keith Donald

Constructor Summary
OAuth2ConnectionFactory(java.lang.String providerId, OAuth2ServiceProvider<S> serviceProvider, ApiAdapter<S> apiAdapter)
          Create a OAuth2ConnectionFactory.
 
Method Summary
 Connection<S> createConnection(AccessGrant accessGrant)
          Create a OAuth2-based Connection from the AccessGrant returned after completing the OAuth2 flow.
 Connection<S> createConnection(ConnectionData data)
          Create a OAuth2-based Connection from the connection data.
protected  java.lang.String extractProviderUserId(AccessGrant accessGrant)
          Hook for extracting the providerUserId from the returned AccessGrant, if it is available.
 java.lang.String generateState()
          Generates a value for the state parameter.
 OAuth2Operations getOAuthOperations()
          Get the ServiceProvider's OAuth2Operations that allows the client application to conduct the OAuth2 flow with the provider.
 java.lang.String getScope()
           
 void setScope(java.lang.String scope)
          Sets the default value to send in the scope parameter during authorization.
 boolean supportsStateParameter()
          Indicates that this provider supports the state parameter in callbacks to prevent against CSRF.
 
Methods inherited from class org.springframework.social.connect.ConnectionFactory
getApiAdapter, getProviderId, getServiceProvider
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OAuth2ConnectionFactory

public OAuth2ConnectionFactory(java.lang.String providerId,
                               OAuth2ServiceProvider<S> serviceProvider,
                               ApiAdapter<S> apiAdapter)
Create a OAuth2ConnectionFactory.

Parameters:
providerId - the provider id e.g. "facebook"
serviceProvider - the ServiceProvider model for conducting the authorization flow and obtaining a native service API instance.
apiAdapter - the ApiAdapter for mapping the provider-specific service API model to the uniform Connection interface.
Method Detail

setScope

public void setScope(java.lang.String scope)
Sets the default value to send in the scope parameter during authorization. Null by default, meaning that no scope parameter will be sent and the default scope will be determined by the provider.

Parameters:
scope - The default value to send as scope during authorization.

getScope

public java.lang.String getScope()

generateState

public java.lang.String generateState()
Generates a value for the state parameter.

Returns:
a random UUID by default.

supportsStateParameter

public boolean supportsStateParameter()
Indicates that this provider supports the state parameter in callbacks to prevent against CSRF. Default implementation returns true.


getOAuthOperations

public OAuth2Operations getOAuthOperations()
Get the ServiceProvider's OAuth2Operations that allows the client application to conduct the OAuth2 flow with the provider.


createConnection

public Connection<S> createConnection(AccessGrant accessGrant)
Create a OAuth2-based Connection from the AccessGrant returned after completing the OAuth2 flow.

Parameters:
accessGrant - the access grant
Returns:
the new service provider connection
See Also:
OAuth2Operations.exchangeForAccess(String, String, org.springframework.util.MultiValueMap)

createConnection

public Connection<S> createConnection(ConnectionData data)
Create a OAuth2-based Connection from the connection data.

Specified by:
createConnection in class ConnectionFactory<S>

extractProviderUserId

protected java.lang.String extractProviderUserId(AccessGrant accessGrant)
Hook for extracting the providerUserId from the returned AccessGrant, if it is available. Default implementation returns null, indicating it is not exposed and another remote API call will be required to obtain it. Subclasses may override.


Spring Social