Class GoogleServiceAccountCredentials
java.lang.Object
com.codename1.backend.security.oauth2.client.credentials.GoogleServiceAccountCredentials
A Google service account, read from the JSON key file the Cloud console
downloads, as a JwtBearerGrant. No Google library is involved: the key is
the file's PKCS#8 PEM, the assertion is signed by this runtime's own RSA, and
the exchange is one POST.
AccessTokenProvider storage = new AccessTokenProvider(
GoogleServiceAccountCredentials.fromFile("/etc/app/service-account.json")
.grant("https://www.googleapis.com/auth/devstorage.read_only"));
Web.Result listing = Web.getJson(
"https://storage.googleapis.com/storage/v1/b/my-bucket/o",
storage.getToken().getTokenValue());
The key file is a credential: keep it out of the repository and readable by
the server's user alone. toString() names the account, never the key.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbuilder()A builder preset for this account, for a subject (domain-wide delegation), a transport or a clock.Reads a service-account key file.Reads the contents of a service-account key file.A grant for these scopes, acting as the service account itself.grant(Collection<String> scopes) A grant for these scopes, acting as the service account itself.toString()Returns a string representation of the object.
-
Field Details
-
TOKEN_URI
Where Google exchanges an assertion when the file does not say.- See Also:
-
-
Method Details
-
fromFile
Reads a service-account key file.- Throws:
IOException- when it cannot be read, or is not a service-account key
-
fromJson
Reads the contents of a service-account key file.- Throws:
IOException- when it is not a service-account key; the message names the field that is wrong and never repeats the key
-
getClientEmail
-
getProjectId
-
getTokenUri
-
grant
A grant for these scopes, acting as the service account itself. -
grant
A grant for these scopes, acting as the service account itself. -
builder
A builder preset for this account, for a subject (domain-wide delegation), a transport or a clock. -
toString
Description copied from class:ObjectReturns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
-