com.google.api.client.auth.oauth2
Class TokenRequest

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.TokenRequest
All Implemented Interfaces:
Cloneable, Map<String,Object>
Direct Known Subclasses:
AuthorizationCodeTokenRequest, RefreshTokenRequest

public class TokenRequest
extends GenericData

OAuth 2.0 request for an access token as specified in Obtaining Authorization.

Call execute() to execute the request and use the returned TokenResponse. On error, it will instead throw TokenResponseException.

Implementation is not thread-safe.

Since:
1.7
Author:
Yaniv Inbar

Nested Class Summary
 
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>
 
Constructor Summary
TokenRequest(HttpTransport transport, JsonFactory jsonFactory, GenericUrl tokenServerUrl, String grantType)
           
 
Method Summary
 TokenResponse execute()
          Executes request for an access token, and returns the parsed access token response.
 HttpResponse executeUnparsed()
          Executes request for an access token, and returns the HTTP response.
 HttpExecuteInterceptor getClientAuthentication()
          Returns the client authentication or null for none.
 String getGrantType()
          Returns the grant type ("authorization_code", "password", "client_credentials", "refresh_token" or absolute URI of the extension grant type).
 JsonFactory getJsonFactory()
          Returns the JSON factory.
 HttpRequestInitializer getRequestInitializer()
          Returns the HTTP request initializer or null for none.
 String getScopes()
          Returns the space-separated list of scopes (as specified in Access Token Scope) or null for none.
 GenericUrl getTokenServerUrl()
          Returns the token server URL.
 HttpTransport getTransport()
          Returns the HTTP transport.
 TokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
          Sets the client authentication or null for none.
 TokenRequest setGrantType(String grantType)
          Sets the grant type ("authorization_code", "password", "client_credentials", "refresh_token" or absolute URI of the extension grant type).
 TokenRequest setRequestInitializer(HttpRequestInitializer requestInitializer)
          Sets the HTTP request initializer or null for none.
 TokenRequest setScopes(Iterable<String> scopes)
          Sets the list of scopes (as specified in Access Token Scope) or null for none.
 TokenRequest setScopes(String... scopes)
          Sets the list of scopes (as specified in Access Token Scope) or null for none.
 TokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
          Sets the token server URL.
 
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
 

Constructor Detail

TokenRequest

public TokenRequest(HttpTransport transport,
                    JsonFactory jsonFactory,
                    GenericUrl tokenServerUrl,
                    String grantType)
Parameters:
transport - HTTP transport
jsonFactory - JSON factory
tokenServerUrl - token server URL
grantType - grant type ("authorization_code", "password", "client_credentials", "refresh_token" or absolute URI of the extension grant type)
Method Detail

getTransport

public final HttpTransport getTransport()
Returns the HTTP transport.


getJsonFactory

public final JsonFactory getJsonFactory()
Returns the JSON factory.


getRequestInitializer

public final HttpRequestInitializer getRequestInitializer()
Returns the HTTP request initializer or null for none.


setRequestInitializer

public TokenRequest setRequestInitializer(HttpRequestInitializer requestInitializer)
Sets the HTTP request initializer or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.


getClientAuthentication

public final HttpExecuteInterceptor getClientAuthentication()
Returns the client authentication or null for none.


setClientAuthentication

public TokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
Sets the client authentication or null for none.

The recommended initializer by the specification is BasicAuthentication. All authorization servers must support that. A common alternative is ClientParametersAuthentication. An alternative client authentication method may be provided that implements HttpRequestInitializer.

This HTTP request execute interceptor is guaranteed to be the last execute interceptor before the request is executed, and after any execute interceptor set by the getRequestInitializer().

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.


getTokenServerUrl

public final GenericUrl getTokenServerUrl()
Returns the token server URL.


setTokenServerUrl

public TokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
Sets the token server URL.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.


getScopes

public final String getScopes()
Returns the space-separated list of scopes (as specified in Access Token Scope) or null for none.


setScopes

public TokenRequest setScopes(String... scopes)
Sets the list of scopes (as specified in Access Token Scope) or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameters:
scopes - list of scopes to be joined by a space separator (or a single value containing multiple space-separated scopes)

setScopes

public TokenRequest setScopes(Iterable<String> scopes)
Sets the list of scopes (as specified in Access Token Scope) or null for none.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameters:
scopes - list of scopes to be joined by a space separator (or a single value containing multiple space-separated scopes)

getGrantType

public final String getGrantType()
Returns the grant type ("authorization_code", "password", "client_credentials", "refresh_token" or absolute URI of the extension grant type).


setGrantType

public TokenRequest setGrantType(String grantType)
Sets the grant type ("authorization_code", "password", "client_credentials", "refresh_token" or absolute URI of the extension grant type).

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.


executeUnparsed

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

To execute and parse the response to TokenResponse, instead use execute().

Returns:
successful access token response, which can then be parsed directly using HttpResponse.parseAs(Class) or some other parsing method
Throws:
TokenResponseException - for an error response
IOException

execute

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

To execute but parse the response in an alternate way, use executeUnparsed().

Default implementation calls executeUnparsed() and then parses using TokenResponse. Subclasses may override to change the return type, but must still call executeUnparsed().

Returns:
parsed successful access token response
Throws:
TokenResponseException - for an error response
IOException


Copyright © 2011-2012 Google. All Rights Reserved.