public class TokenRequest extends GenericData
Call execute()
to execute the request and use the returned TokenResponse
. On
error, it will instead throw TokenResponseException
.
Implementation is not thread-safe.
GenericData.Flags
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
protected Class<? extends TokenResponse> |
responseClass
Response container class for deserialization.
|
Constructor and Description |
---|
TokenRequest(HttpTransport transport,
JsonFactory jsonFactory,
GenericUrl tokenServerUrl,
String grantType)
Creates a new TokenRequest.
|
TokenRequest(HttpTransport transport,
JsonFactory jsonFactory,
GenericUrl tokenServerUrl,
String grantType,
Class<? extends TokenResponse> responseClass)
Creates a new TokenRequest.
|
Modifier and Type | Method and Description |
---|---|
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. |
Class<? extends TokenResponse> |
getResponseClass()
Returns the response class.
|
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 |
set(String fieldName,
Object value) |
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 |
setResponseClass(Class<? extends TokenResponse> responseClass)
Sets the TokenResponse class to allow specifying object parsing.
|
TokenRequest |
setScopes(Collection<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.
|
clone, entrySet, equals, get, getClassInfo, getUnknownKeys, hashCode, put, putAll, remove, setUnknownKeys, toString
clear, containsKey, containsValue, isEmpty, keySet, size, values
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
protected Class<? extends TokenResponse> responseClass
public TokenRequest(HttpTransport transport, JsonFactory jsonFactory, GenericUrl tokenServerUrl, String grantType)
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)public TokenRequest(HttpTransport transport, JsonFactory jsonFactory, GenericUrl tokenServerUrl, String grantType, Class<? extends TokenResponse> responseClass)
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)responseClass
- class used for deserializing the response.public final HttpTransport getTransport()
public final JsonFactory getJsonFactory()
public final HttpRequestInitializer getRequestInitializer()
null
for none.public TokenRequest setRequestInitializer(HttpRequestInitializer requestInitializer)
null
for none.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
public final HttpExecuteInterceptor getClientAuthentication()
null
for none.public TokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
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.
public final GenericUrl getTokenServerUrl()
public TokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
public final String getScopes()
null
for none.public TokenRequest setScopes(Collection<String> scopes)
null
for none.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
scopes
- collection of scopes to be joined by a space separator (or a single value
containing multiple space-separated scopes)public final String getGrantType()
"authorization_code"
, "password"
,
"client_credentials"
, "refresh_token"
or absolute URI of the extension grant
type).public TokenRequest setGrantType(String grantType)
"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.
public final Class<? extends TokenResponse> getResponseClass()
TokenResponse
.public TokenRequest setResponseClass(Class<? extends TokenResponse> responseClass)
responseClass
- The response class returned by execute()
.public final HttpResponse executeUnparsed() throws IOException
To execute and parse the response to TokenResponse
, instead use execute()
.
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(); }
HttpResponse.parseAs(Class)
or some other parsing methodTokenResponseException
- for an error responseIOException
public TokenResponse execute() throws IOException
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()
.
TokenResponseException
- for an error responseIOException
public TokenRequest set(String fieldName, Object value)
set
in class GenericData
Copyright © 2011–2020 Google. All rights reserved.