List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleCredential getServiceAccountPrivateKey
public final PrivateKey getServiceAccountPrivateKey()
From source file:com.spotify.styx.client.auth.GoogleIdTokenAuth.java
License:Apache License
private String getServiceAccountToken(GoogleCredential credential, String targetAudience) throws IOException, GeneralSecurityException { final TokenRequest request = new TokenRequest(this.httpTransport, JSON_FACTORY, new GenericUrl(credential.getTokenServerEncodedUrl()), "urn:ietf:params:oauth:grant-type:jwt-bearer"); final Header header = jwtHeader(); final Payload payload = jwtPayload(targetAudience, credential.getServiceAccountId(), credential.getTokenServerEncodedUrl()); request.put("assertion", JsonWebSignature.signUsingRsaSha256(credential.getServiceAccountPrivateKey(), JSON_FACTORY, header, payload)); final TokenResponse response = request.execute(); return (String) response.get("id_token"); }
From source file:org.silverpeas.core.admin.domain.driver.googledriver.GoogleDirectoryRequester.java
License:Open Source License
/** * Creates an authorized Credential object. * @param httpTransport the HTTP transport. * @return An authorized Credential object. * @throws IOException If the credentials.json file cannot be found. *//* w w w. jav a 2 s. c om*/ private Credential getServiceAccountCredentials(final HttpTransport httpTransport) throws IOException { final GoogleCredential credential; try (InputStream is = new FileInputStream(jsonKeyPath)) { credential = GoogleCredential.fromStream(is); } return new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(JSON_FACTORY) .setServiceAccountUser(serviceAccountUser).setServiceAccountId(credential.getServiceAccountId()) .setServiceAccountScopes(SCOPES) .setServiceAccountPrivateKey(credential.getServiceAccountPrivateKey()) .setServiceAccountPrivateKeyId(credential.getServiceAccountPrivateKeyId()) .setTokenServerEncodedUrl(credential.getTokenServerEncodedUrl()).build(); }