Package com.google.auth.oauth2
Class OAuth2Utils
- java.lang.Object
-
- com.google.auth.oauth2.OAuth2Utils
-
class OAuth2Utils extends java.lang.Object
Internal utilities for the com.google.auth.oauth2 namespace.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
OAuth2Utils.DefaultHttpTransportFactory
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
BEARER_PREFIX
(package private) static int
DEFAULT_NUMBER_OF_RETRIES
(package private) static java.lang.String
GRANT_TYPE_JWT_BEARER
(package private) static com.google.api.client.http.HttpTransport
HTTP_TRANSPORT
(package private) static HttpTransportFactory
HTTP_TRANSPORT_FACTORY
(package private) static java.lang.String
IAM_ACCESS_TOKEN_ENDPOINT_FORMAT
(package private) static java.lang.String
IAM_ID_TOKEN_ENDPOINT_FORMAT
(package private) static int
INITIAL_RETRY_INTERVAL_MILLIS
(package private) static com.google.api.client.json.JsonFactory
JSON_FACTORY
(package private) static double
RETRY_MULTIPLIER
(package private) static double
RETRY_RANDOMIZATION_FACTOR
(package private) static java.lang.String
SIGN_BLOB_ENDPOINT_FORMAT
(package private) static java.lang.String
SIGNATURE_ALGORITHM
static java.util.Set<java.lang.Integer>
TOKEN_ENDPOINT_RETRYABLE_STATUS_CODES
(package private) static java.lang.String
TOKEN_RESPONSE_SCOPE
(package private) static java.net.URI
TOKEN_REVOKE_URI
(package private) static java.net.URI
TOKEN_SERVER_URI
(package private) static java.lang.String
TOKEN_TYPE_ACCESS_TOKEN
(package private) static java.lang.String
TOKEN_TYPE_TOKEN_EXCHANGE
(package private) static java.net.URI
USER_AUTH_URI
private static java.lang.String
VALUE_NOT_FOUND_MESSAGE
private static java.lang.String
VALUE_WRONG_TYPE_MESSAGE
-
Constructor Summary
Constructors Modifier Constructor Description private
OAuth2Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static java.lang.String
generateBasicAuthHeader(java.lang.String username, java.lang.String password)
Generates a Basic Authentication header string for the provided username and password.(package private) static boolean
headersContainValue(com.google.api.client.http.HttpHeaders headers, java.lang.String headerName, java.lang.String value)
Returns whether the headers contain the specified value as one of the entries in the specified header.(package private) static com.google.api.client.json.GenericJson
parseJson(java.lang.String json)
Parses the specified JSON text.(package private) static java.security.PrivateKey
privateKeyFromPkcs8(java.lang.String privateKeyPkcs8)
Helper to convert from a PKCS#8 String to an RSA private key(package private) static int
validateInt32(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix)
Return the specified integer from JSON or throw a helpful error message.(package private) static long
validateLong(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix)
Return the specified long from JSON or throw a helpful error message.(package private) static java.util.Map<java.lang.String,java.lang.Object>
validateMap(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix)
Return the specified map from JSON or throw a helpful error message.(package private) static java.util.List<java.lang.String>
validateOptionalListString(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix)
Return the specified list of strings from JSON or throw a helpful error message.(package private) static java.lang.String
validateOptionalString(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix)
Return the specified optional string from JSON or throw a helpful error message.(package private) static java.lang.String
validateString(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix)
Return the specified string from JSON or throw a helpful error message.(package private) static void
writeInputStreamToFile(java.io.InputStream credentials, java.lang.String filePath)
Saves the end user credentials into the given file path.
-
-
-
Field Detail
-
SIGNATURE_ALGORITHM
static final java.lang.String SIGNATURE_ALGORITHM
- See Also:
- Constant Field Values
-
TOKEN_TYPE_ACCESS_TOKEN
static final java.lang.String TOKEN_TYPE_ACCESS_TOKEN
- See Also:
- Constant Field Values
-
TOKEN_TYPE_TOKEN_EXCHANGE
static final java.lang.String TOKEN_TYPE_TOKEN_EXCHANGE
- See Also:
- Constant Field Values
-
GRANT_TYPE_JWT_BEARER
static final java.lang.String GRANT_TYPE_JWT_BEARER
- See Also:
- Constant Field Values
-
IAM_ID_TOKEN_ENDPOINT_FORMAT
static final java.lang.String IAM_ID_TOKEN_ENDPOINT_FORMAT
- See Also:
- Constant Field Values
-
IAM_ACCESS_TOKEN_ENDPOINT_FORMAT
static final java.lang.String IAM_ACCESS_TOKEN_ENDPOINT_FORMAT
- See Also:
- Constant Field Values
-
SIGN_BLOB_ENDPOINT_FORMAT
static final java.lang.String SIGN_BLOB_ENDPOINT_FORMAT
- See Also:
- Constant Field Values
-
TOKEN_SERVER_URI
static final java.net.URI TOKEN_SERVER_URI
-
TOKEN_REVOKE_URI
static final java.net.URI TOKEN_REVOKE_URI
-
USER_AUTH_URI
static final java.net.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 java.lang.String VALUE_NOT_FOUND_MESSAGE
-
VALUE_WRONG_TYPE_MESSAGE
private static java.lang.String VALUE_WRONG_TYPE_MESSAGE
-
BEARER_PREFIX
static final java.lang.String BEARER_PREFIX
- See Also:
- Constant Field Values
-
TOKEN_RESPONSE_SCOPE
static final java.lang.String TOKEN_RESPONSE_SCOPE
- See Also:
- Constant Field Values
-
INITIAL_RETRY_INTERVAL_MILLIS
static final int INITIAL_RETRY_INTERVAL_MILLIS
- See Also:
- Constant Field Values
-
RETRY_RANDOMIZATION_FACTOR
static final double RETRY_RANDOMIZATION_FACTOR
- See Also:
- Constant Field Values
-
RETRY_MULTIPLIER
static final double RETRY_MULTIPLIER
- See Also:
- Constant Field Values
-
DEFAULT_NUMBER_OF_RETRIES
static final int DEFAULT_NUMBER_OF_RETRIES
- See Also:
- Constant Field Values
-
TOKEN_ENDPOINT_RETRYABLE_STATUS_CODES
public static final java.util.Set<java.lang.Integer> TOKEN_ENDPOINT_RETRYABLE_STATUS_CODES
-
-
Method Detail
-
headersContainValue
static boolean headersContainValue(com.google.api.client.http.HttpHeaders headers, java.lang.String headerName, java.lang.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(java.lang.String json) throws java.io.IOException
Parses the specified JSON text.- Throws:
java.io.IOException
-
validateString
static java.lang.String validateString(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix) throws java.io.IOException
Return the specified string from JSON or throw a helpful error message.- Throws:
java.io.IOException
-
writeInputStreamToFile
static void writeInputStreamToFile(java.io.InputStream credentials, java.lang.String filePath) throws java.io.IOException
Saves the end user credentials into the given file path.- Parameters:
credentials
- InputStream containing user credentials in JSON formatfilePath
- Path to file where to store the credentials- Throws:
java.io.IOException
- An error saving the credentials.
-
validateOptionalString
static java.lang.String validateOptionalString(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix) throws java.io.IOException
Return the specified optional string from JSON or throw a helpful error message.- Throws:
java.io.IOException
-
validateOptionalListString
static java.util.List<java.lang.String> validateOptionalListString(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix) throws java.io.IOException
Return the specified list of strings from JSON or throw a helpful error message.- Throws:
java.io.IOException
-
validateInt32
static int validateInt32(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix) throws java.io.IOException
Return the specified integer from JSON or throw a helpful error message.- Throws:
java.io.IOException
-
validateLong
static long validateLong(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix) throws java.io.IOException
Return the specified long from JSON or throw a helpful error message.- Throws:
java.io.IOException
-
validateMap
static java.util.Map<java.lang.String,java.lang.Object> validateMap(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String key, java.lang.String errorPrefix) throws java.io.IOException
Return the specified map from JSON or throw a helpful error message.- Throws:
java.io.IOException
-
privateKeyFromPkcs8
static java.security.PrivateKey privateKeyFromPkcs8(java.lang.String privateKeyPkcs8) throws java.io.IOException
Helper to convert from a PKCS#8 String to an RSA private key- Throws:
java.io.IOException
-
generateBasicAuthHeader
static java.lang.String generateBasicAuthHeader(java.lang.String username, java.lang.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:
java.lang.IllegalArgumentException
- if either username or password is null or empty.
-
-