Class TokenRequest

    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.google.api.client.util.GenericData

        com.google.api.client.util.GenericData.Flags
      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) com.google.api.client.http.HttpExecuteInterceptor clientAuthentication
      Client authentication or null for none.
      private java.lang.String grantType
      Grant type ("authorization_code", "password", "client_credentials", "refresh_token" or absolute URI of the extension grant type).
      private com.google.api.client.json.JsonFactory jsonFactory
      JSON factory.
      (package private) com.google.api.client.http.HttpRequestInitializer requestInitializer
      HTTP request initializer or null for none.
      private java.lang.String scopes
      Space-separated list of scopes (as specified in Access Token Scope) or null for none.
      private com.google.api.client.http.GenericUrl tokenServerUrl
      Token server URL.
      private com.google.api.client.http.HttpTransport transport
      HTTP transport.
    • Constructor Summary

      Constructors 
      Constructor Description
      TokenRequest​(com.google.api.client.http.HttpTransport transport, com.google.api.client.json.JsonFactory jsonFactory, com.google.api.client.http.GenericUrl tokenServerUrl, java.lang.String grantType)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TokenResponse execute()
      Executes request for an access token, and returns the parsed access token response.
      com.google.api.client.http.HttpResponse executeUnparsed()
      Executes request for an access token, and returns the HTTP response.
      com.google.api.client.http.HttpExecuteInterceptor getClientAuthentication()
      Returns the client authentication or null for none.
      java.lang.String getGrantType()
      Returns the grant type ("authorization_code", "password", "client_credentials", "refresh_token" or absolute URI of the extension grant type).
      com.google.api.client.json.JsonFactory getJsonFactory()
      Returns the JSON factory.
      com.google.api.client.http.HttpRequestInitializer getRequestInitializer()
      Returns the HTTP request initializer or null for none.
      java.lang.String getScopes()
      Returns the space-separated list of scopes (as specified in Access Token Scope) or null for none.
      com.google.api.client.http.GenericUrl getTokenServerUrl()
      Returns the token server URL.
      com.google.api.client.http.HttpTransport getTransport()
      Returns the HTTP transport.
      TokenRequest set​(java.lang.String fieldName, java.lang.Object value)  
      TokenRequest setClientAuthentication​(com.google.api.client.http.HttpExecuteInterceptor clientAuthentication)
      Sets the client authentication or null for none.
      TokenRequest setGrantType​(java.lang.String grantType)
      Sets the grant type ("authorization_code", "password", "client_credentials", "refresh_token" or absolute URI of the extension grant type).
      TokenRequest setRequestInitializer​(com.google.api.client.http.HttpRequestInitializer requestInitializer)
      Sets the HTTP request initializer or null for none.
      TokenRequest setScopes​(java.util.Collection<java.lang.String> scopes)
      Sets the list of scopes (as specified in Access Token Scope) or null for none.
      TokenRequest setTokenServerUrl​(com.google.api.client.http.GenericUrl tokenServerUrl)
      Sets the token server URL.
      • Methods inherited from class com.google.api.client.util.GenericData

        clone, entrySet, get, getClassInfo, getUnknownKeys, put, putAll, remove, 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
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • requestInitializer

        com.google.api.client.http.HttpRequestInitializer requestInitializer
        HTTP request initializer or null for none.
      • clientAuthentication

        com.google.api.client.http.HttpExecuteInterceptor clientAuthentication
        Client authentication or null for none.
      • transport

        private final com.google.api.client.http.HttpTransport transport
        HTTP transport.
      • jsonFactory

        private final com.google.api.client.json.JsonFactory jsonFactory
        JSON factory.
      • tokenServerUrl

        private com.google.api.client.http.GenericUrl tokenServerUrl
        Token server URL.
      • scopes

        private java.lang.String scopes
        Space-separated list of scopes (as specified in Access Token Scope) or null for none.
      • grantType

        private java.lang.String grantType
        Grant type ("authorization_code", "password", "client_credentials", "refresh_token" or absolute URI of the extension grant type).
    • Constructor Detail

      • TokenRequest

        public TokenRequest​(com.google.api.client.http.HttpTransport transport,
                            com.google.api.client.json.JsonFactory jsonFactory,
                            com.google.api.client.http.GenericUrl tokenServerUrl,
                            java.lang.String grantType)
        Parameters:
        transport - HTTP transport
        jsonFactory - JSON factory
        tokenServerUrl - token server URL
        grantType - grant type ("authorization_code", "password", "client_credentials", "refresh_token" or absolute URI of the extension grant type)
    • Method Detail

      • getTransport

        public final com.google.api.client.http.HttpTransport getTransport()
        Returns the HTTP transport.
      • getJsonFactory

        public final com.google.api.client.json.JsonFactory getJsonFactory()
        Returns the JSON factory.
      • getRequestInitializer

        public final com.google.api.client.http.HttpRequestInitializer getRequestInitializer()
        Returns the HTTP request initializer or null for none.
      • setRequestInitializer

        public TokenRequest setRequestInitializer​(com.google.api.client.http.HttpRequestInitializer requestInitializer)
        Sets the HTTP request initializer or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

      • getClientAuthentication

        public final com.google.api.client.http.HttpExecuteInterceptor getClientAuthentication()
        Returns the client authentication or null for none.
      • setClientAuthentication

        public TokenRequest setClientAuthentication​(com.google.api.client.http.HttpExecuteInterceptor clientAuthentication)
        Sets the client authentication or null 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 getRequestInitializer().

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

      • getTokenServerUrl

        public final com.google.api.client.http.GenericUrl getTokenServerUrl()
        Returns the token server URL.
      • setTokenServerUrl

        public TokenRequest setTokenServerUrl​(com.google.api.client.http.GenericUrl tokenServerUrl)
        Sets the token server URL.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

      • getScopes

        public final java.lang.String getScopes()
        Returns the space-separated list of scopes (as specified in Access Token Scope) or null for none.
      • setScopes

        public TokenRequest setScopes​(java.util.Collection<java.lang.String> scopes)
        Sets the list of scopes (as specified in Access Token Scope) or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Parameters:
        scopes - collection of scopes to be joined by a space separator (or a single value containing multiple space-separated scopes)
        Since:
        1.15
      • getGrantType

        public final java.lang.String getGrantType()
        Returns the grant type ("authorization_code", "password", "client_credentials", "refresh_token" or absolute URI of the extension grant type).
      • setGrantType

        public TokenRequest setGrantType​(java.lang.String grantType)
        Sets the grant type ("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.

      • executeUnparsed

        public final com.google.api.client.http.HttpResponse executeUnparsed()
                                                                      throws java.io.IOException
        Executes request for an access token, and returns the HTTP response.

        To execute and parse the response to TokenResponse, instead use execute().

        Callers should call HttpResponse.disconnect() when the returned HTTP response object is no longer needed. However, HttpResponse.disconnect() does not have to be called if the response stream is properly closed. Example usage:

             HttpResponse response = tokenRequest.executeUnparsed();
             try {
               // process the HTTP response object
             } finally {
               response.disconnect();
             }
         
        Returns:
        successful access token response, which can then be parsed directly using HttpResponse.parseAs(Class) or some other parsing method
        Throws:
        TokenResponseException - for an error response
        java.io.IOException
      • execute

        public TokenResponse execute()
                              throws java.io.IOException
        Executes request for an access token, and returns the parsed access token response.

        To execute but parse the response in an alternate way, use executeUnparsed().

        Default implementation calls executeUnparsed() and then parses using TokenResponse. Subclasses may override to change the return type, but must still call executeUnparsed().

        Returns:
        parsed successful access token response
        Throws:
        TokenResponseException - for an error response
        java.io.IOException
      • set

        public TokenRequest set​(java.lang.String fieldName,
                                java.lang.Object value)
        Overrides:
        set in class com.google.api.client.util.GenericData