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 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.
GenericData.FlagsAbstractMap.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, setResponseClassexecuteUnparsed, getClientAuthentication, getGrantType, getJsonFactory, getRequestInitializer, getResponseClass, getScopes, getTokenServerUrl, getTransportclone, entrySet, equals, get, getClassInfo, getUnknownKeys, hashCode, put, putAll, remove, setUnknownKeys, toStringclear, containsKey, containsValue, isEmpty, keySet, size, valuesfinalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllpublic 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 AuthorizationCodeTokenRequestpublic GoogleAuthorizationCodeTokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
setTokenServerUrl in class AuthorizationCodeTokenRequestpublic GoogleAuthorizationCodeTokenRequest setScopes(Collection<String> scopes)
setScopes in class AuthorizationCodeTokenRequestpublic GoogleAuthorizationCodeTokenRequest setGrantType(String grantType)
setGrantType in class AuthorizationCodeTokenRequestpublic GoogleAuthorizationCodeTokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
setClientAuthentication in class AuthorizationCodeTokenRequestpublic GoogleAuthorizationCodeTokenRequest setCode(String code)
setCode in class AuthorizationCodeTokenRequestpublic GoogleAuthorizationCodeTokenRequest setRedirectUri(String redirectUri)
setRedirectUri in class AuthorizationCodeTokenRequestpublic GoogleTokenResponse execute() throws IOException
execute in class TokenRequestIOExceptionpublic GoogleAuthorizationCodeTokenRequest set(String fieldName, Object value)
set in class AuthorizationCodeTokenRequestCopyright © 2010–2019 Google. All rights reserved.