|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractMap<String,Object>
com.google.api.client.util.GenericData
com.google.api.client.auth.oauth2.draft10.AccessTokenRequest
public class AccessTokenRequest
OAuth 2.0 (draft 10) request for an access token as specified in Obtaining an Access Token.
The AccessTokenRequest() or
AccessTokenRequest(HttpTransport, JsonFactory, String, String, String) constructors may
be used directly when no access grant is included, such as when the client is requesting access
to the protected resources under its control. Otherwise, use one of the subclasses, which add
custom parameters to specify the access grant. Call execute() to execute the request and
use the AccessTokenResponse. On error, use AccessTokenErrorResponse instead.
Sample usage when the client is requesting access to the protected resources under its control:
static void requestAccessToken() throws IOException {
try {
AccessTokenRequest request =
new AccessTokenRequest(new NetHttpTransport(), new JacksonFactory(),
"https://server.example.com/authorize", "s6BhdRkqt3", "gX1fBat3bV");
AccessTokenResponse response = request.execute();
System.out.println("Access token: " + response.accessToken);
} catch (HttpResponseException e) {
AccessTokenErrorResponse response = e.response.parseAs(AccessTokenErrorResponse.class);
System.out.println("Error: " + response.error);
}
}
| Nested Class Summary | |
|---|---|
static class |
AccessTokenRequest.AssertionGrant
OAuth 2.0 Assertion Flow: request an access token based on as assertion as specified in Assertion. |
static class |
AccessTokenRequest.AuthorizationCodeGrant
OAuth 2.0 Web Server Flow: request an access token based on a verification code as specified in Authorization Code. |
static class |
AccessTokenRequest.GrantType
Access grant type. |
static class |
AccessTokenRequest.RefreshTokenGrant
OAuth 2.0 request to refresh an access token as specified in Refresh Token. |
static class |
AccessTokenRequest.ResourceOwnerPasswordCredentialsGrant
OAuth 2.0 Username and Password Flow: request an access token based on resource owner credentials used in the as specified in Resource Owner Password Credentials. |
| Nested classes/interfaces inherited from class java.util.AbstractMap |
|---|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V> |
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
Map.Entry<K,V> |
| Field Summary | |
|---|---|
String |
authorizationServerUrl
(REQUIRED) Encoded authorization server URL. |
String |
clientId
(REQUIRED, unless the client identity can be establish via other means, for example assertion) The client identifier or null for none. |
String |
clientSecret
(REQUIRED) The client secret. |
AccessTokenRequest.GrantType |
grantType
(REQUIRED) The access grant type included in the request. |
JsonFactory |
jsonFactory
(REQUIRED) JSON factory to use for parsing response in execute(). |
String |
scope
(OPTIONAL) The scope of the access request expressed as a list of space-delimited strings or null for none. |
HttpTransport |
transport
(REQUIRED) HTTP transport required for executing request in execute(). |
boolean |
useBasicAuthorization
false to specify the password in the request body using the "clientSecret"
parameter in the HTTP body or true to use Basic Authentication as recommended in Client Password
Credentials. |
| Fields inherited from class com.google.api.client.util.GenericData |
|---|
unknownFields |
| Constructor Summary | |
|---|---|
|
AccessTokenRequest()
|
protected |
AccessTokenRequest(HttpTransport transport,
JsonFactory jsonFactory,
String authorizationServerUrl,
String clientSecret)
|
|
AccessTokenRequest(HttpTransport transport,
JsonFactory jsonFactory,
String authorizationServerUrl,
String clientId,
String clientSecret)
|
| Method Summary | |
|---|---|
AccessTokenResponse |
execute()
Executes request for an access token, and returns the parsed access token response. |
HttpResponse |
executeUnparsed()
Executes request for an access token, and returns the HTTP response. |
| Methods inherited from class com.google.api.client.util.GenericData |
|---|
clone, entrySet, get, put, putAll, remove, set |
| Methods inherited from class java.util.AbstractMap |
|---|
clear, containsKey, containsValue, equals, hashCode, isEmpty, keySet, size, toString, values |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public HttpTransport transport
execute().
public JsonFactory jsonFactory
execute().
public AccessTokenRequest.GrantType grantType
public String clientId
null for none.
public String clientSecret
public String scope
null for none. The value of the "scope" parameter is defined by the authorization
server. If the value contains multiple space-delimited strings, their order does not matter,
and each string adds an additional access range to the requested scope. If the access grant
being used already represents an approved scope (e.g. authorization code, assertion), the
requested scope MUST be equal or lesser than the scope previously granted.
public String authorizationServerUrl
public boolean useBasicAuthorization
false to specify the password in the request body using the "clientSecret"
parameter in the HTTP body or true to use Basic Authentication as recommended in Client Password
Credentials.
Defaults to false.
| Constructor Detail |
|---|
public AccessTokenRequest()
protected AccessTokenRequest(HttpTransport transport,
JsonFactory jsonFactory,
String authorizationServerUrl,
String clientSecret)
transport - HTTP transport for executing request in execute()jsonFactory - JSON factory to use for parsing response in execute()authorizationServerUrl - encoded authorization server URLclientSecret - client secret
public AccessTokenRequest(HttpTransport transport,
JsonFactory jsonFactory,
String authorizationServerUrl,
String clientId,
String clientSecret)
transport - HTTP transport for executing request in execute()jsonFactory - JSON factory to use for parsing response in execute()authorizationServerUrl - encoded authorization server URLclientId - client identifierclientSecret - client secret| Method Detail |
|---|
public final HttpResponse executeUnparsed()
throws IOException
To execute and parse the response to AccessTokenResponse, use execute()
HttpResponse.parseAs(Class) or some other parsing method
HttpResponseException - for an HTTP error response, which can then be parsed using
HttpResponse.parseAs(Class) on HttpResponseException.response using
AccessTokenErrorResponse
IOException
public final AccessTokenResponse execute()
throws IOException
To execute without parsing the response, use executeUnparsed()
HttpResponseException - for an HTTP error response, which can then be parsed using
HttpResponse.parseAs(Class) on HttpResponseException.response using
AccessTokenErrorResponse
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||