com.google.api.client.auth.oauth2.draft10
Class AccessTokenRequest

java.lang.Object
  extended by java.util.AbstractMap<String,Object>
      extended by com.google.api.client.util.GenericData
          extended by com.google.api.client.auth.oauth2.draft10.AccessTokenRequest
All Implemented Interfaces:
Cloneable, Map<String,Object>
Direct Known Subclasses:
AccessTokenRequest.AssertionGrant, AccessTokenRequest.AuthorizationCodeGrant, AccessTokenRequest.RefreshTokenGrant, AccessTokenRequest.ResourceOwnerPasswordCredentialsGrant

Deprecated. (scheduled to be removed in 1.9) Use TokenRequest

@Deprecated
public class AccessTokenRequest
extends GenericData

OAuth 2.0 (draft 10) request for an access token as specified in Obtaining an Access Token.

The AccessTokenRequest() or AccessTokenRequest(HttpTransport, JsonFactory, String, String, String) constructors may be used directly when no access grant is included, such as when the client is requesting access to the protected resources under its control. Otherwise, use one of the subclasses, which add custom parameters to specify the access grant. Call execute() to execute the request and use the AccessTokenResponse. On error, use AccessTokenErrorResponse instead.

Sample usage when the client is requesting access to the protected resources under its control:

 
  static void requestAccessToken() throws IOException {
    try {
      AccessTokenRequest request =
          new AccessTokenRequest(new NetHttpTransport(), new JacksonFactory(),
              "https://server.example.com/authorize", "s6BhdRkqt3", "gX1fBat3bV");
      AccessTokenResponse response = request.execute();
      System.out.println("Access token: " + response.accessToken);
    } catch (HttpResponseException e) {
      AccessTokenErrorResponse response = e.response.parseAs(AccessTokenErrorResponse.class);
      System.out.println("Error: " + response.error);
    }
  }
 
 

Since:
1.4
Author:
Yaniv Inbar

Nested Class Summary
static class AccessTokenRequest.AssertionGrant
          Deprecated. (scheduled to be removed in 1.9) Use TokenRequest
static class AccessTokenRequest.AuthorizationCodeGrant
          Deprecated. (scheduled to be removed in 1.9) Use AuthorizationCodeTokenRequest
static class AccessTokenRequest.GrantType
          Deprecated. Access grant type.
static class AccessTokenRequest.RefreshTokenGrant
          Deprecated. (scheduled to be removed in 1.9) Use RefreshTokenRequest
static class AccessTokenRequest.ResourceOwnerPasswordCredentialsGrant
          Deprecated. (scheduled to be removed in 1.9) Use TokenRequest
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 String authorizationServerUrl
          Deprecated. (REQUIRED) Encoded authorization server URL.
 String clientId
          Deprecated. (REQUIRED, unless the client identity can be establish via other means, for example assertion) The client identifier or null for none.
 String clientSecret
          Deprecated. (REQUIRED) The client secret.
 AccessTokenRequest.GrantType grantType
          Deprecated. (REQUIRED) The access grant type included in the request.
 JsonFactory jsonFactory
          Deprecated. (REQUIRED) JSON factory to use for parsing response in execute().
 String scope
          Deprecated. (OPTIONAL) The scope of the access request expressed as a list of space-delimited strings or null for none.
 HttpTransport transport
          Deprecated. (REQUIRED) HTTP transport required for executing request in execute().
 boolean useBasicAuthorization
          Deprecated. false to specify the password in the request body using the "clientSecret" parameter in the HTTP body or true to use Basic Authentication as recommended in Client Password Credentials.
 
Constructor Summary
  AccessTokenRequest()
          Deprecated.  
protected AccessTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String authorizationServerUrl)
          Deprecated.  
protected AccessTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String authorizationServerUrl, String clientSecret)
          Deprecated.  
  AccessTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String authorizationServerUrl, String clientId, String clientSecret)
          Deprecated.  
 
Method Summary
 AccessTokenResponse execute()
          Deprecated. Executes request for an access token, and returns the parsed access token response.
 HttpResponse executeUnparsed()
          Deprecated. Executes request for an access token, and returns the HTTP response.
 
Methods inherited from class com.google.api.client.util.GenericData
clone, entrySet, get, getUnknownKeys, put, putAll, remove, set, setUnknownKeys
 
Methods inherited from class java.util.AbstractMap
clear, containsKey, containsValue, equals, hashCode, isEmpty, keySet, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

transport

public HttpTransport transport
Deprecated. 
(REQUIRED) HTTP transport required for executing request in execute().


jsonFactory

public JsonFactory jsonFactory
Deprecated. 
(REQUIRED) JSON factory to use for parsing response in execute().


grantType

public AccessTokenRequest.GrantType grantType
Deprecated. 
(REQUIRED) The access grant type included in the request.


clientId

public String clientId
Deprecated. 
(REQUIRED, unless the client identity can be establish via other means, for example assertion) The client identifier or null for none.


clientSecret

public String clientSecret
Deprecated. 
(REQUIRED) The client secret.


scope

public String scope
Deprecated. 
(OPTIONAL) The scope of the access request expressed as a list of space-delimited strings or null for none. The value of the "scope" parameter is defined by the authorization server. If the value contains multiple space-delimited strings, their order does not matter, and each string adds an additional access range to the requested scope. If the access grant being used already represents an approved scope (e.g. authorization code, assertion), the requested scope MUST be equal or lesser than the scope previously granted.


authorizationServerUrl

public String authorizationServerUrl
Deprecated. 
(REQUIRED) Encoded authorization server URL.


useBasicAuthorization

public boolean useBasicAuthorization
Deprecated. 
false to specify the password in the request body using the "clientSecret" parameter in the HTTP body or true to use Basic Authentication as recommended in Client Password Credentials.

Defaults to false.

Constructor Detail

AccessTokenRequest

public AccessTokenRequest()
Deprecated. 

AccessTokenRequest

protected AccessTokenRequest(HttpTransport transport,
                             JsonFactory jsonFactory,
                             String authorizationServerUrl)
Deprecated. 
Parameters:
transport - HTTP transport for executing request in execute()
jsonFactory - JSON factory to use for parsing response in execute()
authorizationServerUrl - encoded authorization server URL

AccessTokenRequest

protected AccessTokenRequest(HttpTransport transport,
                             JsonFactory jsonFactory,
                             String authorizationServerUrl,
                             String clientSecret)
Deprecated. 
Parameters:
transport - HTTP transport for executing request in execute()
jsonFactory - JSON factory to use for parsing response in execute()
authorizationServerUrl - encoded authorization server URL
clientSecret - client secret

AccessTokenRequest

public AccessTokenRequest(HttpTransport transport,
                          JsonFactory jsonFactory,
                          String authorizationServerUrl,
                          String clientId,
                          String clientSecret)
Deprecated. 
Parameters:
transport - HTTP transport for executing request in execute()
jsonFactory - JSON factory to use for parsing response in execute()
authorizationServerUrl - encoded authorization server URL
clientId - client identifier
clientSecret - client secret
Method Detail

executeUnparsed

public final HttpResponse executeUnparsed()
                                   throws IOException
Deprecated. 
Executes request for an access token, and returns the HTTP response.

To execute and parse the response to AccessTokenResponse, use execute()

Returns:
HTTP response, which can then be parsed directly using HttpResponse.parseAs(Class) or some other parsing method
Throws:
HttpResponseException - for an HTTP error response, which can then be parsed using HttpResponse.parseAs(Class) on HttpResponseException.getResponse() using AccessTokenErrorResponse
IOException

execute

public final AccessTokenResponse execute()
                                  throws IOException
Deprecated. 
Executes request for an access token, and returns the parsed access token response.

To execute without parsing the response, use executeUnparsed()

Returns:
parsed access token response
Throws:
HttpResponseException - for an HTTP error response, which can then be parsed using HttpResponse.parseAs(Class) on HttpResponseException.getResponse() using AccessTokenErrorResponse
IOException


Copyright © 2011-2012 Google. All Rights Reserved.