Class OAuth2Utils

java.lang.Object
com.google.auth.oauth2.OAuth2Utils

class OAuth2Utils extends Object
Internal utilities for the com.google.auth.oauth2 namespace.
  • Field Details

    • SIGNATURE_ALGORITHM

      static final String SIGNATURE_ALGORITHM
      See Also:
    • TOKEN_TYPE_ACCESS_TOKEN

      static final String TOKEN_TYPE_ACCESS_TOKEN
      See Also:
    • TOKEN_TYPE_TOKEN_EXCHANGE

      static final String TOKEN_TYPE_TOKEN_EXCHANGE
      See Also:
    • GRANT_TYPE_JWT_BEARER

      static final String GRANT_TYPE_JWT_BEARER
      See Also:
    • IAM_ID_TOKEN_ENDPOINT_FORMAT

      static final String IAM_ID_TOKEN_ENDPOINT_FORMAT
      See Also:
    • IAM_ACCESS_TOKEN_ENDPOINT_FORMAT

      static final String IAM_ACCESS_TOKEN_ENDPOINT_FORMAT
      See Also:
    • SIGN_BLOB_ENDPOINT_FORMAT

      static final String SIGN_BLOB_ENDPOINT_FORMAT
      See Also:
    • TOKEN_SERVER_URI

      static final URI TOKEN_SERVER_URI
    • TOKEN_REVOKE_URI

      static final URI TOKEN_REVOKE_URI
    • USER_AUTH_URI

      static final URI USER_AUTH_URI
    • HTTP_TRANSPORT

      static final com.google.api.client.http.HttpTransport HTTP_TRANSPORT
    • HTTP_TRANSPORT_FACTORY

      static final HttpTransportFactory HTTP_TRANSPORT_FACTORY
    • JSON_FACTORY

      static final com.google.api.client.json.JsonFactory JSON_FACTORY
    • VALUE_NOT_FOUND_MESSAGE

      private static String VALUE_NOT_FOUND_MESSAGE
    • VALUE_WRONG_TYPE_MESSAGE

      private static String VALUE_WRONG_TYPE_MESSAGE
    • BEARER_PREFIX

      static final String BEARER_PREFIX
      See Also:
    • TOKEN_RESPONSE_SCOPE

      static final String TOKEN_RESPONSE_SCOPE
      See Also:
    • INITIAL_RETRY_INTERVAL_MILLIS

      static final int INITIAL_RETRY_INTERVAL_MILLIS
      See Also:
    • RETRY_RANDOMIZATION_FACTOR

      static final double RETRY_RANDOMIZATION_FACTOR
      See Also:
    • RETRY_MULTIPLIER

      static final double RETRY_MULTIPLIER
      See Also:
    • DEFAULT_NUMBER_OF_RETRIES

      static final int DEFAULT_NUMBER_OF_RETRIES
      See Also:
    • TOKEN_ENDPOINT_RETRYABLE_STATUS_CODES

      public static final Set<Integer> TOKEN_ENDPOINT_RETRYABLE_STATUS_CODES
  • Constructor Details

    • OAuth2Utils

      private OAuth2Utils()
  • Method Details

    • headersContainValue

      static boolean headersContainValue(com.google.api.client.http.HttpHeaders headers, String headerName, String value)
      Returns whether the headers contain the specified value as one of the entries in the specified header.
    • parseJson

      static com.google.api.client.json.GenericJson parseJson(String json) throws IOException
      Parses the specified JSON text.
      Throws:
      IOException
    • validateString

      static String validateString(Map<String,Object> map, String key, String errorPrefix) throws IOException
      Return the specified string from JSON or throw a helpful error message.
      Throws:
      IOException
    • writeInputStreamToFile

      static void writeInputStreamToFile(InputStream credentials, String filePath) throws IOException
      Saves the end user credentials into the given file path.
      Parameters:
      credentials - InputStream containing user credentials in JSON format
      filePath - Path to file where to store the credentials
      Throws:
      IOException - An error saving the credentials.
    • validateOptionalString

      static String validateOptionalString(Map<String,Object> map, String key, String errorPrefix) throws IOException
      Return the specified optional string from JSON or throw a helpful error message.
      Throws:
      IOException
    • validateOptionalListString

      static List<String> validateOptionalListString(Map<String,Object> map, String key, String errorPrefix) throws IOException
      Return the specified list of strings from JSON or throw a helpful error message.
      Throws:
      IOException
    • validateInt32

      static int validateInt32(Map<String,Object> map, String key, String errorPrefix) throws IOException
      Return the specified integer from JSON or throw a helpful error message.
      Throws:
      IOException
    • validateLong

      static long validateLong(Map<String,Object> map, String key, String errorPrefix) throws IOException
      Return the specified long from JSON or throw a helpful error message.
      Throws:
      IOException
    • validateMap

      static Map<String,Object> validateMap(Map<String,Object> map, String key, String errorPrefix) throws IOException
      Return the specified map from JSON or throw a helpful error message.
      Throws:
      IOException
    • privateKeyFromPkcs8

      static PrivateKey privateKeyFromPkcs8(String privateKeyPkcs8) throws IOException
      Helper to convert from a PKCS#8 String to an RSA private key
      Throws:
      IOException
    • generateBasicAuthHeader

      static String generateBasicAuthHeader(String username, String password)
      Generates a Basic Authentication header string for the provided username and password.

      This method constructs a Basic Authentication string using the provided username and password. The credentials are encoded in Base64 format and prefixed with the "Basic " scheme identifier.

      Parameters:
      username - The username for authentication.
      password - The password for authentication.
      Returns:
      The Basic Authentication header value.
      Throws:
      IllegalArgumentException - if either username or password is null or empty.