org.springframework.social.oauth2
Class OAuth2Template

java.lang.Object
  extended by org.springframework.social.oauth2.OAuth2Template
All Implemented Interfaces:
OAuth2Operations
Direct Known Subclasses:
FacebookOAuth2Template

public class OAuth2Template
extends java.lang.Object
implements OAuth2Operations

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


Constructor Summary
OAuth2Template(java.lang.String clientId, java.lang.String clientSecret, java.lang.String authorizeUrl, java.lang.String accessTokenUrl)
           
OAuth2Template(java.lang.String clientId, java.lang.String clientSecret, java.lang.String authorizeUrl, java.lang.String authenticateUrl, java.lang.String accessTokenUrl)
           
 
Method Summary
 java.lang.String buildAuthenticateUrl(GrantType grantType, OAuth2Parameters parameters)
          Construct the URL to redirect the user to for authentication.
 java.lang.String buildAuthorizeUrl(GrantType grantType, OAuth2Parameters parameters)
          Construct the URL to redirect the user to for authorization.
protected  AccessGrant createAccessGrant(java.lang.String accessToken, java.lang.String scope, java.lang.String refreshToken, java.lang.Integer expiresIn, java.util.Map<java.lang.String,java.lang.Object> result)
           
protected  RestTemplate createRestTemplate()
           
 AccessGrant exchangeForAccess(java.lang.String authorizationCode, java.lang.String redirectUri, MultiValueMap<java.lang.String,java.lang.String> additionalParameters)
          Exchange the authorization code for an access grant.
protected  RestTemplate getRestTemplate()
           
protected  AccessGrant postForAccessGrant(java.lang.String accessTokenUrl, MultiValueMap<java.lang.String,java.lang.String> parameters)
           
 AccessGrant refreshAccess(java.lang.String refreshToken, java.lang.String scope, MultiValueMap<java.lang.String,java.lang.String> additionalParameters)
          Refreshes a previous access grant.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OAuth2Template

public OAuth2Template(java.lang.String clientId,
                      java.lang.String clientSecret,
                      java.lang.String authorizeUrl,
                      java.lang.String accessTokenUrl)

OAuth2Template

public OAuth2Template(java.lang.String clientId,
                      java.lang.String clientSecret,
                      java.lang.String authorizeUrl,
                      java.lang.String authenticateUrl,
                      java.lang.String accessTokenUrl)
Method Detail

buildAuthorizeUrl

public java.lang.String buildAuthorizeUrl(GrantType grantType,
                                          OAuth2Parameters parameters)
Description copied from interface: OAuth2Operations
Construct the URL to redirect the user to for authorization.

Specified by:
buildAuthorizeUrl in interface OAuth2Operations
Parameters:
grantType - specifies whether to use client-side or server-side OAuth flow
parameters - authorization parameters needed to build the URL
Returns:
the absolute authorize URL to redirect the user to for authorization

buildAuthenticateUrl

public java.lang.String buildAuthenticateUrl(GrantType grantType,
                                             OAuth2Parameters parameters)
Description copied from interface: OAuth2Operations
Construct the URL to redirect the user to for authentication. 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 OAuth2Operations
Parameters:
grantType - specifies whether to use client-side or server-side OAuth flow
parameters - authorization parameters needed to build the URL
Returns:
the absolute authenticate URL to redirect the user to for authorization

exchangeForAccess

public AccessGrant exchangeForAccess(java.lang.String authorizationCode,
                                     java.lang.String redirectUri,
                                     MultiValueMap<java.lang.String,java.lang.String> additionalParameters)
Description copied from interface: OAuth2Operations
Exchange the authorization code for an access grant.

Specified by:
exchangeForAccess in interface OAuth2Operations
Parameters:
authorizationCode - the authorization code returned by the provider upon user authorization
redirectUri - the authorization callback url; this value must match the redirectUri registered with the provider

refreshAccess

public AccessGrant refreshAccess(java.lang.String refreshToken,
                                 java.lang.String scope,
                                 MultiValueMap<java.lang.String,java.lang.String> additionalParameters)
Description copied from interface: OAuth2Operations
Refreshes a previous access grant.

Specified by:
refreshAccess in interface OAuth2Operations
Parameters:
refreshToken - the refresh token from the previous access grant.
scope - optional scope to narrow to when refreshing access; if null, the existing scope is preserved.

createRestTemplate

protected RestTemplate createRestTemplate()

postForAccessGrant

protected AccessGrant postForAccessGrant(java.lang.String accessTokenUrl,
                                         MultiValueMap<java.lang.String,java.lang.String> parameters)

createAccessGrant

protected AccessGrant createAccessGrant(java.lang.String accessToken,
                                        java.lang.String scope,
                                        java.lang.String refreshToken,
                                        java.lang.Integer expiresIn,
                                        java.util.Map<java.lang.String,java.lang.Object> result)

getRestTemplate

protected RestTemplate getRestTemplate()