|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.social.oauth2.OAuth2Template
public class OAuth2Template
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> response)
Creates an AccessGrant given the response from the access token exchange with the provider. |
protected RestTemplate |
createRestTemplate()
Creates the RestTemplate used to communicate with the provider's OAuth 2 API. |
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)
Posts the request for an access grant to the provider. |
AccessGrant |
refreshAccess(java.lang.String refreshToken,
java.lang.String scope,
MultiValueMap<java.lang.String,java.lang.String> additionalParameters)
Refreshes a previous access grant. |
void |
setRequestFactory(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 |
---|
public OAuth2Template(java.lang.String clientId, java.lang.String clientSecret, java.lang.String authorizeUrl, java.lang.String accessTokenUrl)
public OAuth2Template(java.lang.String clientId, java.lang.String clientSecret, java.lang.String authorizeUrl, java.lang.String authenticateUrl, java.lang.String accessTokenUrl)
Method Detail |
---|
public void setRequestFactory(ClientHttpRequestFactory requestFactory)
public java.lang.String buildAuthorizeUrl(GrantType grantType, OAuth2Parameters parameters)
OAuth2Operations
buildAuthorizeUrl
in interface OAuth2Operations
grantType
- specifies whether to use client-side or server-side OAuth flowparameters
- authorization parameters needed to build the URL
public java.lang.String buildAuthenticateUrl(GrantType grantType, OAuth2Parameters parameters)
OAuth2Operations
buildAuthenticateUrl
in interface OAuth2Operations
grantType
- specifies whether to use client-side or server-side OAuth flowparameters
- authorization parameters needed to build the URL
public AccessGrant exchangeForAccess(java.lang.String authorizationCode, java.lang.String redirectUri, MultiValueMap<java.lang.String,java.lang.String> additionalParameters)
OAuth2Operations
exchangeForAccess
in interface OAuth2Operations
authorizationCode
- the authorization code returned by the provider upon user authorizationredirectUri
- the authorization callback url; this value must match the redirectUri registered with the provideradditionalParameters
- any additional parameters to be sent when exchanging the authorization code for an access grant. Should not be encoded.
public AccessGrant refreshAccess(java.lang.String refreshToken, java.lang.String scope, MultiValueMap<java.lang.String,java.lang.String> additionalParameters)
OAuth2Operations
refreshAccess
in interface OAuth2Operations
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.additionalParameters
- any additional parameters to be sent when refreshing a previous access grant. Should not be encoded.
protected RestTemplate createRestTemplate()
RestTemplate
used to communicate with the provider's OAuth 2 API.
This implementation creates a RestTemplate with a minimal set of HTTP message converters (FormHttpMessageConverter
and MappingJacksonHttpMessageConverter
).
May be overridden to customize how the RestTemplate is created.
For example, if the provider returns data in some format other than JSON for form-encoded, you might override to register an appropriate message converter.
protected AccessGrant postForAccessGrant(java.lang.String accessTokenUrl, MultiValueMap<java.lang.String,java.lang.String> parameters)
AccessGrant
.
Since the OAuth 2 specification indicates that an access token response should be in JSON format, there's often no need to override this method.
If all you need to do is capture provider-specific data in the response, you should override createAccessGrant() instead.
However, in the event of a provider whose access token response is non-JSON, you may need to override this method to request that the response be bound to something other than a Map.
For example, if the access token response is given as form-encoded, this method should be overridden to call RestTemplate.postForObject() asking for the response to be bound to a MultiValueMap (whose contents can then be used to create an AccessGrant).
accessTokenUrl
- the URL of the provider's access token endpoint.parameters
- the parameters to post to the access token endpoint.
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> response)
AccessGrant
given the response from the access token exchange with the provider.
May be overridden to create a custom AccessGrant that captures provider-specific information from the access token response.
accessToken
- the access token value received from the providerscope
- the scope of the access tokenrefreshToken
- a refresh token value received from the providerexpiresIn
- the time (in seconds) remaining before the access token expires.response
- all parameters from the response received in the access token exchange.
AccessGrant
protected RestTemplate getRestTemplate()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |