com.google.api.client.googleapis.auth.oauth2
Class GoogleAuthorizationCodeTokenRequest
java.lang.Object
java.util.AbstractMap<String,Object>
com.google.api.client.util.GenericData
com.google.api.client.auth.oauth2.TokenRequest
com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest
com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest
- All Implemented Interfaces:
- Cloneable, Map<String,Object>
public class GoogleAuthorizationCodeTokenRequest
- extends AuthorizationCodeTokenRequest
Google-specific implementation of the OAuth 2.0 request for an access token based on an
authorization code (as specified in Using OAuth 2.0 for Web
Server Applications).
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.
- Since:
- 1.7
- Author:
- Yaniv Inbar
Nested classes/interfaces inherited from interface java.util.Map |
Map.Entry<K,V> |
GoogleAuthorizationCodeTokenRequest
public GoogleAuthorizationCodeTokenRequest(HttpTransport transport,
JsonFactory jsonFactory,
String clientId,
String clientSecret,
String code,
String redirectUri)
- Parameters:
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)
setRequestInitializer
public GoogleAuthorizationCodeTokenRequest setRequestInitializer(HttpRequestInitializer requestInitializer)
- Overrides:
setRequestInitializer
in class AuthorizationCodeTokenRequest
setTokenServerUrl
public GoogleAuthorizationCodeTokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
- Overrides:
setTokenServerUrl
in class AuthorizationCodeTokenRequest
setScopes
public GoogleAuthorizationCodeTokenRequest setScopes(String... scopes)
- Overrides:
setScopes
in class AuthorizationCodeTokenRequest
setScopes
public GoogleAuthorizationCodeTokenRequest setScopes(Iterable<String> scopes)
- Overrides:
setScopes
in class AuthorizationCodeTokenRequest
setGrantType
public GoogleAuthorizationCodeTokenRequest setGrantType(String grantType)
- Overrides:
setGrantType
in class AuthorizationCodeTokenRequest
setClientAuthentication
public GoogleAuthorizationCodeTokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
- Overrides:
setClientAuthentication
in class AuthorizationCodeTokenRequest
setCode
public GoogleAuthorizationCodeTokenRequest setCode(String code)
- Overrides:
setCode
in class AuthorizationCodeTokenRequest
setRedirectUri
public GoogleAuthorizationCodeTokenRequest setRedirectUri(String redirectUri)
- Overrides:
setRedirectUri
in class AuthorizationCodeTokenRequest
execute
public GoogleTokenResponse execute()
throws IOException
- Overrides:
execute
in class TokenRequest
- Throws:
IOException
Copyright © 2010-2012 Google. All Rights Reserved.