Class ClientParametersAuthentication

  • All Implemented Interfaces:
    com.google.api.client.http.HttpExecuteInterceptor, com.google.api.client.http.HttpRequestInitializer

    public class ClientParametersAuthentication
    extends java.lang.Object
    implements com.google.api.client.http.HttpRequestInitializer, com.google.api.client.http.HttpExecuteInterceptor
    Client credentials specified as URL-encoded parameters in the HTTP request body as specified in Client Password

    This implementation assumes that the HttpRequest.getContent() is null or an instance of UrlEncodedContent. This is used as the client authentication in TokenRequest.setClientAuthentication(HttpExecuteInterceptor).

    Sample usage:

      static void requestAccessToken() throws IOException {
        try {
          TokenResponse response = new AuthorizationCodeTokenRequest(new NetHttpTransport(),
              new JacksonFactory(), new GenericUrl("https://server.example.com/token"),
              "SplxlOBeZQQYbYS6WxSbIA").setRedirectUri("https://client.example.com/rd")
              .setClientAuthentication(
                  new ClientParametersAuthentication("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());
          }
        }
      }
     

    Implementation is immutable and thread-safe.

    Since:
    1.7
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String clientId
      Client identifier issued to the client during the registration process.
      private java.lang.String clientSecret
      Client secret or null for none.
    • Constructor Summary

      Constructors 
      Constructor Description
      ClientParametersAuthentication​(java.lang.String clientId, java.lang.String clientSecret)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getClientId()
      Returns the client identifier issued to the client during the registration process.
      java.lang.String getClientSecret()
      Returns the client secret or null for none.
      void initialize​(com.google.api.client.http.HttpRequest request)  
      void intercept​(com.google.api.client.http.HttpRequest request)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • clientId

        private final java.lang.String clientId
        Client identifier issued to the client during the registration process.
      • clientSecret

        private final java.lang.String clientSecret
        Client secret or null for none.
    • Constructor Detail

      • ClientParametersAuthentication

        public ClientParametersAuthentication​(java.lang.String clientId,
                                              java.lang.String clientSecret)
        Parameters:
        clientId - client identifier issued to the client during the registration process
        clientSecret - client secret or null for none
    • Method Detail

      • initialize

        public void initialize​(com.google.api.client.http.HttpRequest request)
                        throws java.io.IOException
        Specified by:
        initialize in interface com.google.api.client.http.HttpRequestInitializer
        Throws:
        java.io.IOException
      • intercept

        public void intercept​(com.google.api.client.http.HttpRequest request)
                       throws java.io.IOException
        Specified by:
        intercept in interface com.google.api.client.http.HttpExecuteInterceptor
        Throws:
        java.io.IOException
      • getClientId

        public final java.lang.String getClientId()
        Returns the client identifier issued to the client during the registration process.
      • getClientSecret

        public final java.lang.String getClientSecret()
        Returns the client secret or null for none.