Spring Social

org.springframework.social.oauth1
Class OAuth1Template

java.lang.Object
  extended by org.springframework.social.oauth1.OAuth1Template
All Implemented Interfaces:
OAuth1Operations

public class OAuth1Template
extends java.lang.Object
implements OAuth1Operations

OAuth10Operations implementation that uses REST-template to make the OAuth calls.

Author:
Keith Donald

Constructor Summary
OAuth1Template(java.lang.String consumerKey, java.lang.String consumerSecret, java.lang.String requestTokenUrl, java.lang.String authorizeUrl, java.lang.String accessTokenUrl)
           
OAuth1Template(java.lang.String consumerKey, java.lang.String consumerSecret, java.lang.String requestTokenUrl, java.lang.String authorizeUrl, java.lang.String accessTokenUrl, OAuth1Version version)
           
OAuth1Template(java.lang.String consumerKey, java.lang.String consumerSecret, java.lang.String requestTokenUrl, java.lang.String authorizeUrl, java.lang.String authenticateUrl, java.lang.String accessTokenUrl)
           
OAuth1Template(java.lang.String consumerKey, java.lang.String consumerSecret, java.lang.String requestTokenUrl, java.lang.String authorizeUrl, java.lang.String authenticateUrl, java.lang.String accessTokenUrl, OAuth1Version version)
           
 
Method Summary
protected  void addCustomAuthorizationParameters(org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> parameters)
          Subclassing hook to add custom authorization parameters to the authorization URL.
 java.lang.String buildAuthenticateUrl(java.lang.String requestToken, OAuth1Parameters parameters)
          Construct the URL to redirect the user to for authentication.
 java.lang.String buildAuthorizeUrl(java.lang.String requestToken, OAuth1Parameters parameters)
          Construct the URL to redirect the user to for authorization.
protected  OAuthToken createOAuthToken(java.lang.String tokenValue, java.lang.String tokenSecret, org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> response)
          Creates an OAuthToken given the response from the request token or access token exchange with the provider.
 OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> additionalParameters)
          Exchange the authorized request token for an access token.
 OAuthToken fetchRequestToken(java.lang.String callbackUrl, org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> additionalParameters)
          Begin a new authorization flow by fetching a new request token from this service provider.
protected  java.lang.String getConsumerKey()
          Exposes the consumer key to be read by subclasses.
 OAuth1Version getVersion()
          The version of OAuth1 implemented by this operations instance.
 void setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
          Set the request factory on the underlying RestTemplate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OAuth1Template

public OAuth1Template(java.lang.String consumerKey,
                      java.lang.String consumerSecret,
                      java.lang.String requestTokenUrl,
                      java.lang.String authorizeUrl,
                      java.lang.String accessTokenUrl)

OAuth1Template

public OAuth1Template(java.lang.String consumerKey,
                      java.lang.String consumerSecret,
                      java.lang.String requestTokenUrl,
                      java.lang.String authorizeUrl,
                      java.lang.String accessTokenUrl,
                      OAuth1Version version)

OAuth1Template

public OAuth1Template(java.lang.String consumerKey,
                      java.lang.String consumerSecret,
                      java.lang.String requestTokenUrl,
                      java.lang.String authorizeUrl,
                      java.lang.String authenticateUrl,
                      java.lang.String accessTokenUrl)

OAuth1Template

public OAuth1Template(java.lang.String consumerKey,
                      java.lang.String consumerSecret,
                      java.lang.String requestTokenUrl,
                      java.lang.String authorizeUrl,
                      java.lang.String authenticateUrl,
                      java.lang.String accessTokenUrl,
                      OAuth1Version version)
Method Detail

setRequestFactory

public void setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
Set the request factory on the underlying RestTemplate. This can be used to plug in a different HttpClient to do things like configure custom SSL settings.


getVersion

public OAuth1Version getVersion()
Description copied from interface: OAuth1Operations
The version of OAuth1 implemented by this operations instance.

Specified by:
getVersion in interface OAuth1Operations
See Also:
OAuth1Version.CORE_10, OAuth1Version.CORE_10_REVISION_A

fetchRequestToken

public OAuthToken fetchRequestToken(java.lang.String callbackUrl,
                                    org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> additionalParameters)
Description copied from interface: OAuth1Operations
Begin a new authorization flow by fetching a new request token from this service provider. The request token should be stored in the user's session up until the authorization callback is made and it's time to exchange it for an access token.

Specified by:
fetchRequestToken in interface OAuth1Operations
Parameters:
callbackUrl - the URL the provider should redirect to after the member authorizes the connection. Ignored for OAuth 1.0 providers.
additionalParameters - any additional query parameters to be sent when fetching the request token. Should not be encoded.
Returns:
a temporary request token use for authorization and exchanged for an access token

buildAuthorizeUrl

public java.lang.String buildAuthorizeUrl(java.lang.String requestToken,
                                          OAuth1Parameters parameters)
Description copied from interface: OAuth1Operations
Construct the URL to redirect the user to for authorization.

Specified by:
buildAuthorizeUrl in interface OAuth1Operations
Parameters:
requestToken - the request token value, to be encoded in the authorize URL.
parameters - parameters to pass to the provider in the authorize URL. Should never be null; if there are no parameters to pass, set this argument value to OAuth1Parameters.NONE.
Returns:
the absolute authorize URL to redirect the user to for authorization

buildAuthenticateUrl

public java.lang.String buildAuthenticateUrl(java.lang.String requestToken,
                                             OAuth1Parameters parameters)
Description copied from interface: OAuth1Operations
Construct the URL to redirect the user to for authentication. For some provider, the authenticate URL differs from the authorizationUrl slightly in that it does not require the user to authorize the app multiple times. This provides a better user experience for "Sign in with Provider" scenarios.

Specified by:
buildAuthenticateUrl in interface OAuth1Operations
Parameters:
requestToken - the request token value, to be encoded in the authorize URL.
parameters - parameters to pass to the provider in the authenticate URL. Should never be null; if there are no parameters to pass, set this argument value to OAuth1Parameters.NONE.
Returns:
the absolute authenticate URL to redirect the user to for authentication

exchangeForAccessToken

public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken,
                                         org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> additionalParameters)
Description copied from interface: OAuth1Operations
Exchange the authorized request token for an access token.

Specified by:
exchangeForAccessToken in interface OAuth1Operations
Parameters:
requestToken - an authorized request token and verifier. The verifier will be ignored for OAuth 1.0 providers.
additionalParameters - any additional query parameters to be sent when fetching the access token. Should not be encoded.
Returns:
an access token granted by the provider

getConsumerKey

protected java.lang.String getConsumerKey()
Exposes the consumer key to be read by subclasses. This may be useful when overriding addCustomAuthorizationParameters(MultiValueMap) and the consumer key is required in the authorization request.


createOAuthToken

protected OAuthToken createOAuthToken(java.lang.String tokenValue,
                                      java.lang.String tokenSecret,
                                      org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> response)
Creates an OAuthToken given the response from the request token or access token exchange with the provider. May be overridden to create a custom OAuthToken.

Parameters:
tokenValue - the token value received from the provider.
tokenSecret - the token secret received from the provider.
response - all parameters from the response received in the request/access token exchange.
Returns:
an OAuthToken

addCustomAuthorizationParameters

protected void addCustomAuthorizationParameters(org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> parameters)
Subclassing hook to add custom authorization parameters to the authorization URL. Default implementation adds no parameters.


Spring Social