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 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.
Inheritance
Object > java.util.AbstractMap > com.google.api.client.util.GenericData > com.google.api.client.auth.oauth2.TokenRequest > com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest > GoogleAuthorizationCodeTokenRequestConstructors
GoogleAuthorizationCodeTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String clientId, String clientSecret, String code, String redirectUri)
public GoogleAuthorizationCodeTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String clientId, String clientSecret, String code, String redirectUri)
Name | Description |
transport | com.google.api.client.http.HttpTransport HTTP transport |
jsonFactory | com.google.api.client.json.JsonFactory JSON factory |
clientId | String client identifier issued to the client during the registration process |
clientSecret | String client secret |
code | String authorization code generated by the authorization server |
redirectUri | String redirect URL parameter matching the redirect URL parameter in the authorization request (see #setRedirectUri(String) |
GoogleAuthorizationCodeTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String tokenServerEncodedUrl, String clientId, String clientSecret, String code, String redirectUri)
public GoogleAuthorizationCodeTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String tokenServerEncodedUrl, String clientId, String clientSecret, String code, String redirectUri)
Name | Description |
transport | com.google.api.client.http.HttpTransport HTTP transport |
jsonFactory | com.google.api.client.json.JsonFactory JSON factory |
tokenServerEncodedUrl | String token server encoded URL |
clientId | String client identifier issued to the client during the registration process |
clientSecret | String client secret |
code | String authorization code generated by the authorization server |
redirectUri | String redirect URL parameter matching the redirect URL parameter in the authorization request (see #setRedirectUri(String) |
Methods
execute()
public GoogleTokenResponse execute()
Type | Description |
GoogleTokenResponse |
Type | Description |
IOException |
set(String fieldName, Object value)
public GoogleAuthorizationCodeTokenRequest set(String fieldName, Object value)
Name | Description |
fieldName | String |
value | Object |
Type | Description |
GoogleAuthorizationCodeTokenRequest |
setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
public GoogleAuthorizationCodeTokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
Name | Description |
clientAuthentication | com.google.api.client.http.HttpExecuteInterceptor |
Type | Description |
GoogleAuthorizationCodeTokenRequest |
setCode(String code)
public GoogleAuthorizationCodeTokenRequest setCode(String code)
Name | Description |
code | String |
Type | Description |
GoogleAuthorizationCodeTokenRequest |
setGrantType(String grantType)
public GoogleAuthorizationCodeTokenRequest setGrantType(String grantType)
Name | Description |
grantType | String |
Type | Description |
GoogleAuthorizationCodeTokenRequest |
setRedirectUri(String redirectUri)
public GoogleAuthorizationCodeTokenRequest setRedirectUri(String redirectUri)
Name | Description |
redirectUri | String |
Type | Description |
GoogleAuthorizationCodeTokenRequest |
setRequestInitializer(HttpRequestInitializer requestInitializer)
public GoogleAuthorizationCodeTokenRequest setRequestInitializer(HttpRequestInitializer requestInitializer)
Name | Description |
requestInitializer | com.google.api.client.http.HttpRequestInitializer |
Type | Description |
GoogleAuthorizationCodeTokenRequest |
setScopes(Collection<String> scopes)
public GoogleAuthorizationCodeTokenRequest setScopes(Collection<String> scopes)
Name | Description |
scopes | Collection<String> |
Type | Description |
GoogleAuthorizationCodeTokenRequest |
setTokenServerUrl(GenericUrl tokenServerUrl)
public GoogleAuthorizationCodeTokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
Name | Description |
tokenServerUrl | com.google.api.client.http.GenericUrl |
Type | Description |
GoogleAuthorizationCodeTokenRequest |