public class GoogleAuthorizationCodeTokenRequest
extends com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest
Use GoogleCredential
to access protected resources from the resource server using the
TokenResponse
returned by execute()
. On error, it will instead throw
TokenResponseException
.
Sample usage:
static void requestAccessToken() throws IOException { try { GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(), "812741506391.apps.googleusercontent.com", "{client_secret}", "4/P7q7W91a-oMsCeLvIaQm6bTrgtp7", "https://oauth2-login-demo.appspot.com/code") .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()); } } }
Implementation is not thread-safe.
com.google.api.client.util.GenericData.Flags
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
GoogleAuthorizationCodeTokenRequest(com.google.api.client.http.HttpTransport transport,
com.google.api.client.json.JsonFactory jsonFactory,
String clientId,
String clientSecret,
String code,
String redirectUri) |
GoogleAuthorizationCodeTokenRequest(com.google.api.client.http.HttpTransport transport,
com.google.api.client.json.JsonFactory jsonFactory,
String tokenServerEncodedUrl,
String clientId,
String clientSecret,
String code,
String redirectUri) |
Modifier and Type | Method and Description |
---|---|
GoogleTokenResponse |
execute() |
GoogleAuthorizationCodeTokenRequest |
set(String fieldName,
Object value) |
GoogleAuthorizationCodeTokenRequest |
setClientAuthentication(com.google.api.client.http.HttpExecuteInterceptor clientAuthentication) |
GoogleAuthorizationCodeTokenRequest |
setCode(String code) |
GoogleAuthorizationCodeTokenRequest |
setGrantType(String grantType) |
GoogleAuthorizationCodeTokenRequest |
setRedirectUri(String redirectUri) |
GoogleAuthorizationCodeTokenRequest |
setRequestInitializer(com.google.api.client.http.HttpRequestInitializer requestInitializer) |
GoogleAuthorizationCodeTokenRequest |
setScopes(Collection<String> scopes) |
GoogleAuthorizationCodeTokenRequest |
setTokenServerUrl(com.google.api.client.http.GenericUrl tokenServerUrl) |
getCode, getRedirectUri, setResponseClass
executeUnparsed, getClientAuthentication, getGrantType, getJsonFactory, getRequestInitializer, getResponseClass, getScopes, getTokenServerUrl, getTransport
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
public GoogleAuthorizationCodeTokenRequest(com.google.api.client.http.HttpTransport transport, com.google.api.client.json.JsonFactory jsonFactory, String clientId, String clientSecret, String code, String redirectUri)
transport
- HTTP transportjsonFactory
- JSON factoryclientId
- client identifier issued to the client during the registration processclientSecret
- client secretcode
- authorization code generated by the authorization serverredirectUri
- redirect URL parameter matching the redirect URL parameter in the
authorization request (see setRedirectUri(String)
public GoogleAuthorizationCodeTokenRequest(com.google.api.client.http.HttpTransport transport, com.google.api.client.json.JsonFactory jsonFactory, String tokenServerEncodedUrl, String clientId, String clientSecret, String code, String redirectUri)
transport
- HTTP transportjsonFactory
- JSON factorytokenServerEncodedUrl
- token server encoded URLclientId
- client identifier issued to the client during the registration processclientSecret
- client secretcode
- authorization code generated by the authorization serverredirectUri
- redirect URL parameter matching the redirect URL parameter in the
authorization request (see setRedirectUri(String)
public GoogleAuthorizationCodeTokenRequest setRequestInitializer(com.google.api.client.http.HttpRequestInitializer requestInitializer)
setRequestInitializer
in class com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setTokenServerUrl(com.google.api.client.http.GenericUrl tokenServerUrl)
setTokenServerUrl
in class com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setScopes(Collection<String> scopes)
setScopes
in class com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setGrantType(String grantType)
setGrantType
in class com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setClientAuthentication(com.google.api.client.http.HttpExecuteInterceptor clientAuthentication)
setClientAuthentication
in class com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setCode(String code)
setCode
in class com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setRedirectUri(String redirectUri)
setRedirectUri
in class com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest
public GoogleTokenResponse execute() throws IOException
execute
in class com.google.api.client.auth.oauth2.TokenRequest
IOException
public GoogleAuthorizationCodeTokenRequest set(String fieldName, Object value)
set
in class com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest
Copyright © 2010–2019 Google. All rights reserved.