Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class GoogleServiceAccountCredentials
- Object
- 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.
Fields
public static final String TOKEN_URI = "https://oauth2.googleapis.com/token" | Where Google exchanges an assertion when the file does not say. |
Methods
public static GoogleServiceAccountCredentials fromFile(String path)
throws IOException | Reads a service-account key file. |
public static GoogleServiceAccountCredentials fromJson(String json)
throws IOException | Reads the contents of a service-account key file. |
public String getClientEmail() | |
public String getProjectId() | |
public String getTokenUri() | |
public JwtBearerGrant grant(String... scopes) | A grant for these scopes, acting as the service account itself. |
public JwtBearerGrant grant(Collection<String> scopes) | A grant for these scopes, acting as the service account itself. |
public JwtBearerGrant.Builder builder() | A builder preset for this account, for a subject (domain-wide delegation), a transport or a clock. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Field details
TOKEN_URI
public static final String TOKEN_URI = "https://oauth2.googleapis.com/token"Where Google exchanges an assertion when the file does not say.
Method details
fromFile
public static GoogleServiceAccountCredentials fromFile(String path)
throws IOExceptionReads a service-account key file.
Throws
IOException- when it cannot be read, or is not a service-account key
fromJson
public static GoogleServiceAccountCredentials fromJson(String json)
throws IOExceptionReads 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
public String getClientEmail()getProjectId
public String getProjectId()getTokenUri
public String getTokenUri()grant
public JwtBearerGrant grant(String... scopes)A grant for these scopes, acting as the service account itself.
grant
public JwtBearerGrant grant(Collection<String> scopes)A grant for these scopes, acting as the service account itself.
builder
public JwtBearerGrant.Builder builder()A builder preset for this account, for a subject (domain-wide delegation),
a transport or a clock.
toString
public String toString()Returns 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())