public class GoogleAuthorizationCodeTokenRequest extends 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 GsonFactory(), "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.
GenericData.Flags
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
responseClass
Constructor and Description |
---|
GoogleAuthorizationCodeTokenRequest(HttpTransport transport,
JsonFactory jsonFactory,
String clientId,
String clientSecret,
String code,
String redirectUri) |
GoogleAuthorizationCodeTokenRequest(HttpTransport transport,
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(HttpExecuteInterceptor clientAuthentication) |
GoogleAuthorizationCodeTokenRequest |
setCode(String code) |
GoogleAuthorizationCodeTokenRequest |
setGrantType(String grantType) |
GoogleAuthorizationCodeTokenRequest |
setRedirectUri(String redirectUri) |
GoogleAuthorizationCodeTokenRequest |
setRequestInitializer(HttpRequestInitializer requestInitializer) |
GoogleAuthorizationCodeTokenRequest |
setScopes(Collection<String> scopes) |
GoogleAuthorizationCodeTokenRequest |
setTokenServerUrl(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(HttpTransport transport, 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(HttpTransport transport, 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(HttpRequestInitializer requestInitializer)
setRequestInitializer
in class AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
setTokenServerUrl
in class AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setScopes(Collection<String> scopes)
setScopes
in class AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setGrantType(String grantType)
setGrantType
in class AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
setClientAuthentication
in class AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setCode(String code)
setCode
in class AuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest setRedirectUri(String redirectUri)
setRedirectUri
in class AuthorizationCodeTokenRequest
public GoogleTokenResponse execute() throws IOException
execute
in class TokenRequest
IOException
public GoogleAuthorizationCodeTokenRequest set(String fieldName, Object value)
set
in class AuthorizationCodeTokenRequest
Copyright © 2010–2021 Google. All rights reserved.