Class TokenRequest
- Direct Known Subclasses:
AuthorizationCodeTokenRequest, ClientCredentialsTokenRequest, PasswordTokenRequest, RefreshTokenRequest
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
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.api.client.util.GenericData
com.google.api.client.util.GenericData.FlagsNested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescription(package private) com.google.api.client.http.HttpExecuteInterceptorClient authentication ornullfor none.private StringGrant type ("authorization_code","password","client_credentials","refresh_token"or absolute URI of the extension grant type).private final com.google.api.client.json.JsonFactoryJSON factory.(package private) com.google.api.client.http.HttpRequestInitializerHTTP request initializer ornullfor none.private StringSpace-separated list of scopes (as specified in Access Token Scope) ornullfor none.private com.google.api.client.http.GenericUrlToken server URL.private final com.google.api.client.http.HttpTransportHTTP transport. -
Constructor Summary
ConstructorsConstructorDescriptionTokenRequest(com.google.api.client.http.HttpTransport transport, com.google.api.client.json.JsonFactory jsonFactory, com.google.api.client.http.GenericUrl tokenServerUrl, String grantType) -
Method Summary
Modifier and TypeMethodDescriptionexecute()Executes request for an access token, and returns the parsed access token response.final com.google.api.client.http.HttpResponseExecutes request for an access token, and returns the HTTP response.final com.google.api.client.http.HttpExecuteInterceptorReturns the client authentication ornullfor none.final StringReturns the grant type ("authorization_code","password","client_credentials","refresh_token"or absolute URI of the extension grant type).final com.google.api.client.json.JsonFactoryReturns the JSON factory.final com.google.api.client.http.HttpRequestInitializerReturns the HTTP request initializer ornullfor none.final StringReturns the space-separated list of scopes (as specified in Access Token Scope) ornullfor none.final com.google.api.client.http.GenericUrlReturns the token server URL.final com.google.api.client.http.HttpTransportReturns the HTTP transport.setClientAuthentication(com.google.api.client.http.HttpExecuteInterceptor clientAuthentication) Sets the client authentication ornullfor none.setGrantType(String grantType) Sets the grant type ("authorization_code","password","client_credentials","refresh_token"or absolute URI of the extension grant type).setRequestInitializer(com.google.api.client.http.HttpRequestInitializer requestInitializer) Sets the HTTP request initializer ornullfor none.setScopes(Collection<String> scopes) Sets the list of scopes (as specified in Access Token Scope) ornullfor none.setTokenServerUrl(com.google.api.client.http.GenericUrl tokenServerUrl) Sets the token server URL.Methods inherited from class com.google.api.client.util.GenericData
clone, entrySet, get, getClassInfo, getUnknownKeys, put, putAll, remove, setUnknownKeysMethods inherited from class AbstractMap
clear, containsKey, containsValue, equals, hashCode, isEmpty, keySet, size, toString, valuesMethods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
requestInitializer
com.google.api.client.http.HttpRequestInitializer requestInitializerHTTP request initializer ornullfor none. -
clientAuthentication
com.google.api.client.http.HttpExecuteInterceptor clientAuthenticationClient authentication ornullfor none. -
transport
private final com.google.api.client.http.HttpTransport transportHTTP transport. -
jsonFactory
private final com.google.api.client.json.JsonFactory jsonFactoryJSON factory. -
tokenServerUrl
private com.google.api.client.http.GenericUrl tokenServerUrlToken server URL. -
scopes
Space-separated list of scopes (as specified in Access Token Scope) ornullfor none. -
grantType
Grant type ("authorization_code","password","client_credentials","refresh_token"or absolute URI of the extension grant type).
-
-
Constructor Details
-
TokenRequest
public TokenRequest(com.google.api.client.http.HttpTransport transport, com.google.api.client.json.JsonFactory jsonFactory, com.google.api.client.http.GenericUrl tokenServerUrl, String grantType) - Parameters:
transport- HTTP transportjsonFactory- JSON factorytokenServerUrl- token server URLgrantType- grant type ("authorization_code","password","client_credentials","refresh_token"or absolute URI of the extension grant type)
-
-
Method Details
-
getTransport
public final com.google.api.client.http.HttpTransport getTransport()Returns the HTTP transport. -
getJsonFactory
public final com.google.api.client.json.JsonFactory getJsonFactory()Returns the JSON factory. -
getRequestInitializer
public final com.google.api.client.http.HttpRequestInitializer getRequestInitializer()Returns the HTTP request initializer ornullfor none. -
setRequestInitializer
public TokenRequest setRequestInitializer(com.google.api.client.http.HttpRequestInitializer requestInitializer) Sets the HTTP request initializer ornullfor none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
-
getClientAuthentication
public final com.google.api.client.http.HttpExecuteInterceptor getClientAuthentication()Returns the client authentication ornullfor none. -
setClientAuthentication
public TokenRequest setClientAuthentication(com.google.api.client.http.HttpExecuteInterceptor clientAuthentication) Sets the client authentication ornullfor none.The recommended initializer by the specification is
BasicAuthentication. All authorization servers must support that. A common alternative isClientParametersAuthentication. An alternative client authentication method may be provided that implementsHttpRequestInitializer.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 com.google.api.client.http.GenericUrl getTokenServerUrl()Returns the token server URL. -
setTokenServerUrl
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
Returns the space-separated list of scopes (as specified in Access Token Scope) ornullfor none. -
setScopes
Sets the list of scopes (as specified in Access Token Scope) ornullfor none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Parameters:
scopes- collection of scopes to be joined by a space separator (or a single value containing multiple space-separated scopes)- Since:
- 1.15
-
getGrantType
Returns the grant type ("authorization_code","password","client_credentials","refresh_token"or absolute URI of the extension grant type). -
setGrantType
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
Executes request for an access token, and returns the HTTP response.To execute and parse the response to
TokenResponse, instead useexecute().Callers should call
HttpResponse.disconnect()when the returned HTTP response object is no longer needed. However,HttpResponse.disconnect()does not have to be called if the response stream is properly closed. Example usage:HttpResponse response = tokenRequest.executeUnparsed(); try { // process the HTTP response object } finally { response.disconnect(); }- 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 responseIOException
-
execute
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 usingTokenResponse. Subclasses may override to change the return type, but must still callexecuteUnparsed().- Returns:
- parsed successful access token response
- Throws:
TokenResponseException- for an error responseIOException
-
set
- Overrides:
setin classcom.google.api.client.util.GenericData
-