# Class AuthorizationCodeTokenRequest (1.39.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [1.39.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)
- [1.38.2](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.38.2/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)
- [1.37.0](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.37.0/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)
- [1.36.0](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.36.0/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)
- [1.34.1](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.34.1/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)
- [1.33.3](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.33.3/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)
- [1.32.1](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.32.1/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)

    public class AuthorizationCodeTokenRequest extends TokenRequest

OAuth 2.0 request for an access token using an authorization code as specified in [Access Token Request](http://tools.ietf.org/html/rfc6749#section-4.1.3).

Use [Credential](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.Credential) to access protected resources from the resource server using the TokenResponse returned by #execute(). On error, it will instead throw [TokenResponseException](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenResponseException).

Sample usage:


     static void requestAccessToken() throws IOException {
     try {
     TokenResponse response =
     new AuthorizationCodeTokenRequest(new NetHttpTransport(), new GsonFactory(),
     new GenericUrl("https://server.example.com/token"), "SplxlOBeZQQYbYS6WxSbIA")
     .setRedirectUri("https://client.example.com/rd")
     .setClientAuthentication(
     new BasicAuthentication("s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw")).execute();
     System.out.println("Access token: " + response.getAccessToken());
     } catch (TokenResponseException e) {
     if (e.getDetails() != null) {
     System.err.println("Error: " + e.getDetails().getError());
     if (e.getDetails().getErrorDescription() != null) {
     System.err.println(e.getDetails().getErrorDescription());
     }
     if (e.getDetails().getErrorUri() != null) {
     System.err.println(e.getDetails().getErrorUri());
     }
     } else {
     System.err.println(e.getMessage());
     }
     }
     }
     
Some OAuth 2.0 providers don't support BasicAuthentication but instead support [ClientParametersAuthentication](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.ClientParametersAuthentication). In the above sample code, simply replace the class name and it
will work the same way.

Implementation is not thread-safe.

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> java.util.AbstractMap \> com.google.api.client.util.GenericData \> [TokenRequest](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest) \> AuthorizationCodeTokenRequest

## Inherited Members

[TokenRequest.execute()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_execute__) [TokenRequest.executeUnparsed()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_executeUnparsed__) [TokenRequest.getClientAuthentication()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_getClientAuthentication__) [TokenRequest.getGrantType()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_getGrantType__) [TokenRequest.getJsonFactory()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_getJsonFactory__) [TokenRequest.getRequestInitializer()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_getRequestInitializer__) [TokenRequest.getResponseClass()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_getResponseClass__) [TokenRequest.getScopes()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_getScopes__) [TokenRequest.getTokenServerUrl()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_getTokenServerUrl__) [TokenRequest.getTransport()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_getTransport__) [TokenRequest.set(String,Object)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_set_java_lang_String_java_lang_Object_) [TokenRequest.setClientAuthentication(HttpExecuteInterceptor)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setClientAuthentication_com_google_api_client_http_HttpExecuteInterceptor_) [TokenRequest.setGrantType(String)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setGrantType_java_lang_String_) [TokenRequest.setRequestInitializer(HttpRequestInitializer)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setRequestInitializer_com_google_api_client_http_HttpRequestInitializer_) [TokenRequest.setResponseClass(Class\<? extends TokenResponse\>)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setResponseClass_java_lang_Class___extends_com_google_api_client_auth_oauth2_TokenResponse__) [TokenRequest.setScopes(Collection\<String\>)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setScopes_java_util_Collection_java_lang_String__) [TokenRequest.setTokenServerUrl(GenericUrl)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setTokenServerUrl_com_google_api_client_http_GenericUrl_) com.google.api.client.util.GenericData.clone() com.google.api.client.util.GenericData.entrySet() com.google.api.client.util.GenericData.equals(java.lang.Object) com.google.api.client.util.GenericData.get(java.lang.Object) com.google.api.client.util.GenericData.getClassInfo() com.google.api.client.util.GenericData.getUnknownKeys() com.google.api.client.util.GenericData.hashCode() com.google.api.client.util.GenericData.put(java.lang.String,java.lang.Object) com.google.api.client.util.GenericData.putAll(java.util.Map\<? extends java.lang.String,?\>) com.google.api.client.util.GenericData.remove(java.lang.Object) com.google.api.client.util.GenericData.setUnknownKeys(java.util.Map\<java.lang.String,java.lang.Object\>) com.google.api.client.util.GenericData.toString() [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-) [AbstractMap.clear()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#clear--) [AbstractMap.containsKey(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsKey-java.lang.Object-) [AbstractMap.containsValue(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsValue-java.lang.Object-) [AbstractMap.isEmpty()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#isEmpty--) [AbstractMap.keySet()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#keySet--) [AbstractMap.put(K,V)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#put-K-V-) [AbstractMap.putAll(Map\<? extends K,? extends V\>)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#putAll-java.util.Map<? extends K-? extends V>-) [AbstractMap.size()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#size--) [AbstractMap.values()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#values--)

## Constructors

### AuthorizationCodeTokenRequest(HttpTransport transport, JsonFactory jsonFactory, GenericUrl tokenServerUrl, String code)

    public AuthorizationCodeTokenRequest(HttpTransport transport, JsonFactory jsonFactory, GenericUrl tokenServerUrl, String code)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `transport` | `com.google.api.client.http.HttpTransport` HTTP transport |
| `jsonFactory` | `com.google.api.client.json.JsonFactory` JSON factory |
| `tokenServerUrl` | `com.google.api.client.http.GenericUrl` token server URL |
| `code` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` authorization code generated by the authorization server |

## Methods

### getCode()

    public final String getCode()

Returns the authorization code generated by the authorization server.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getRedirectUri()

    public final String getRedirectUri()

Returns the redirect URI parameter matching the redirect URI parameter in the authorization
request or `null` for none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### set(String fieldName, Object value)

    public AuthorizationCodeTokenRequest set(String fieldName, Object value)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `fieldName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest` |   |

**Overrides** [TokenRequest.set(String fieldName, Object value)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_set_java_lang_String_java_lang_Object_)

### setClientAuthentication(HttpExecuteInterceptor clientAuthentication)

    public AuthorizationCodeTokenRequest 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](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `clientAuthentication` | `com.google.api.client.http.HttpExecuteInterceptor` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest` |   |

**Overrides** [TokenRequest.setClientAuthentication(HttpExecuteInterceptor clientAuthentication)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setClientAuthentication_com_google_api_client_http_HttpExecuteInterceptor_)

### setCode(String code)

    public AuthorizationCodeTokenRequest setCode(String code)

Sets the authorization code generated by the authorization server.

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

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `code` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest` |   |

### setGrantType(String grantType)

    public AuthorizationCodeTokenRequest 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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `grantType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest` |   |

**Overrides** [TokenRequest.setGrantType(String grantType)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setGrantType_java_lang_String_)

### setRedirectUri(String redirectUri)

    public AuthorizationCodeTokenRequest setRedirectUri(String redirectUri)

Sets the redirect URI parameter matching the redirect URI parameter in the authorization
request or `null` for none.

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

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `redirectUri` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest` |   |

### setRequestInitializer(HttpRequestInitializer requestInitializer)

    public AuthorizationCodeTokenRequest 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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `requestInitializer` | `com.google.api.client.http.HttpRequestInitializer` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest` |   |

**Overrides** [TokenRequest.setRequestInitializer(HttpRequestInitializer requestInitializer)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setRequestInitializer_com_google_api_client_http_HttpRequestInitializer_)

### setResponseClass(Class\<? extends TokenResponse\> responseClass)

    public AuthorizationCodeTokenRequest setResponseClass(Class<? extends TokenResponse> responseClass)

Sets the TokenResponse class to allow specifying object parsing.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `responseClass` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<? extends com.google.api.client.auth.oauth2.TokenResponse>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest` |   |

**Overrides** [TokenRequest.setResponseClass(Class\<? extends TokenResponse\> responseClass)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setResponseClass_java_lang_Class___extends_com_google_api_client_auth_oauth2_TokenResponse__)

### setScopes(Collection\<String\> scopes)

    public AuthorizationCodeTokenRequest setScopes(Collection<String> scopes)

Sets the list of scopes (as specified in [Access Token Scope](http://tools.ietf.org/html/rfc6749#section-3.3)) or `null`
for none.

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

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `scopes` | `https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest` |   |

**Overrides** [TokenRequest.setScopes(Collection\<String\> scopes)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setScopes_java_util_Collection_java_lang_String__)

### setTokenServerUrl(GenericUrl tokenServerUrl)

    public AuthorizationCodeTokenRequest 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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `tokenServerUrl` | `com.google.api.client.http.GenericUrl` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest` |   |

**Overrides** [TokenRequest.setTokenServerUrl(GenericUrl tokenServerUrl)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth2.TokenRequest#com_google_api_client_auth_oauth2_TokenRequest_setTokenServerUrl_com_google_api_client_http_GenericUrl_)