public class TokenRequest
extends com.google.api.client.util.GenericData
Call execute()
to execute the request and use the returned TokenResponse
. On
error, it will instead throw TokenResponseException
.
Implementation is not thread-safe.
com.google.api.client.util.GenericData.Flags
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
TokenRequest(com.google.api.client.http.HttpTransport transport,
com.google.api.client.json.JsonFactory jsonFactory,
com.google.api.client.http.GenericUrl tokenServerUrl,
String grantType) |
Modifier and Type | Method and Description |
---|---|
TokenResponse |
execute()
Executes request for an access token, and returns the parsed access token response.
|
com.google.api.client.http.HttpResponse |
executeUnparsed()
Executes request for an access token, and returns the HTTP response.
|
com.google.api.client.http.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). |
com.google.api.client.json.JsonFactory |
getJsonFactory()
Returns the JSON factory.
|
com.google.api.client.http.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. |
com.google.api.client.http.GenericUrl |
getTokenServerUrl()
Returns the token server URL.
|
com.google.api.client.http.HttpTransport |
getTransport()
Returns the HTTP transport.
|
TokenRequest |
set(String fieldName,
Object value) |
TokenRequest |
setClientAuthentication(com.google.api.client.http.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(com.google.api.client.http.HttpRequestInitializer requestInitializer)
Sets the HTTP request initializer or
null for none. |
TokenRequest |
setScopes(Collection<String> scopes)
Sets the list of scopes (as specified in Access Token Scope) or
null
for none. |
TokenRequest |
setTokenServerUrl(com.google.api.client.http.GenericUrl tokenServerUrl)
Sets the token server URL.
|
clone, entrySet, get, getClassInfo, getUnknownKeys, put, putAll, remove, setUnknownKeys
clear, containsKey, containsValue, equals, hashCode, isEmpty, keySet, size, toString, values
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
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)
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 final com.google.api.client.http.HttpTransport getTransport()
public final com.google.api.client.json.JsonFactory getJsonFactory()
public final com.google.api.client.http.HttpRequestInitializer getRequestInitializer()
null
for none.public TokenRequest setRequestInitializer(com.google.api.client.http.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 com.google.api.client.http.HttpExecuteInterceptor getClientAuthentication()
null
for none.public TokenRequest setClientAuthentication(com.google.api.client.http.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 com.google.api.client.http.GenericUrl getTokenServerUrl()
public TokenRequest setTokenServerUrl(com.google.api.client.http.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 com.google.api.client.http.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 com.google.api.client.util.GenericData
Copyright © 2011–2021 Google. All rights reserved.