|
||||||||||
| 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.TokenRequest
com.google.api.client.auth.oauth2.RefreshTokenRequest
public class RefreshTokenRequest
OAuth 2.0 request to refresh an access token using a refresh token as specified in Refreshing an Access Token.
Use Credential to access protected resources from the resource server using
the TokenResponse returned by TokenRequest.execute(). On error, it will instead throw
TokenResponseException.
Sample usage:
static void refreshAccessToken() throws IOException {
try {
TokenResponse response =
new RefreshTokenRequest(new NetHttpTransport(), new JacksonFactory(), new GenericUrl(
"https://server.example.com/token"), "tGzv3JOkF0XG5Qx2TlKWIA")
.setClientAuthentication(
new BasicAuthentication("s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw")).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());
}
}
}
Some OAuth 2.0 providers don't support BasicAuthentication but instead support
ClientParametersAuthentication. In the above sample code, simply replace the class name
and it will work the same way.
Implementation is not thread-safe.
| Nested Class Summary |
|---|
| 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> |
| Constructor Summary | |
|---|---|
RefreshTokenRequest(HttpTransport transport,
JsonFactory jsonFactory,
GenericUrl tokenServerUrl,
String refreshToken)
|
|
| Method Summary | |
|---|---|
String |
getRefreshToken()
Returns the refresh token issued to the client. |
RefreshTokenRequest |
setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
Sets the client authentication or null for none. |
RefreshTokenRequest |
setGrantType(String grantType)
Sets the grant type ( "authorization_code", "password",
"client_credentials", "refresh_token" or absolute URI of the extension grant
type). |
RefreshTokenRequest |
setRefreshToken(String refreshToken)
Sets the refresh token issued to the client. |
RefreshTokenRequest |
setRequestInitializer(HttpRequestInitializer requestInitializer)
Sets the HTTP request initializer or null for none. |
RefreshTokenRequest |
setScopes(Iterable<String> scopes)
Sets the list of scopes (as specified in Access Token Scope) or null for none. |
RefreshTokenRequest |
setScopes(String... scopes)
Sets the list of scopes (as specified in Access Token Scope) or null for none. |
RefreshTokenRequest |
setTokenServerUrl(GenericUrl tokenServerUrl)
Sets the token server URL. |
| Methods inherited from class com.google.api.client.auth.oauth2.TokenRequest |
|---|
execute, executeUnparsed, getClientAuthentication, getGrantType, getJsonFactory, getRequestInitializer, getScopes, getTokenServerUrl, getTransport |
| Methods inherited from class com.google.api.client.util.GenericData |
|---|
clone, entrySet, get, getUnknownKeys, put, putAll, remove, set, setUnknownKeys |
| 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 |
| Constructor Detail |
|---|
public RefreshTokenRequest(HttpTransport transport,
JsonFactory jsonFactory,
GenericUrl tokenServerUrl,
String refreshToken)
transport - HTTP transportjsonFactory - JSON factorytokenServerUrl - token server URLrefreshToken - refresh token issued to the client| Method Detail |
|---|
public RefreshTokenRequest setRequestInitializer(HttpRequestInitializer requestInitializer)
TokenRequestnull for none.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
setRequestInitializer in class TokenRequestpublic RefreshTokenRequest setTokenServerUrl(GenericUrl tokenServerUrl)
TokenRequestOverriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
setTokenServerUrl in class TokenRequestpublic RefreshTokenRequest setScopes(String... scopes)
TokenRequestnull for none.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
setScopes in class TokenRequestscopes - list of scopes to be joined by a space separator (or a single value containing
multiple space-separated scopes)public RefreshTokenRequest setScopes(Iterable<String> scopes)
TokenRequestnull for none.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
setScopes in class TokenRequestscopes - list of scopes to be joined by a space separator (or a single value containing
multiple space-separated scopes)public RefreshTokenRequest setGrantType(String grantType)
TokenRequest"authorization_code", "password",
"client_credentials", "refresh_token" or absolute URI of the extension grant
type).
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
setGrantType in class TokenRequestpublic RefreshTokenRequest setClientAuthentication(HttpExecuteInterceptor clientAuthentication)
TokenRequestnull for none.
The recommended initializer by the specification is BasicAuthentication. All
authorization servers must support that. A common alternative is
ClientParametersAuthentication. An alternative client authentication method may be
provided that implements HttpRequestInitializer.
This HTTP request execute interceptor is guaranteed to be the last execute interceptor before
the request is executed, and after any execute interceptor set by the
TokenRequest.getRequestInitializer().
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
setClientAuthentication in class TokenRequestpublic final String getRefreshToken()
public RefreshTokenRequest setRefreshToken(String refreshToken)
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||