google-auth-library-java icon indicating copy to clipboard operation
google-auth-library-java copied to clipboard

Support read CREDENTIAL_ENV_VAR from VM option.

Open haber-he opened this issue 5 years ago • 4 comments

Hi team,

Can we support read CREDENTIAL_ENV_VAR from VM options?

Code snippet

 String credentialsPath = this.getProperty(CREDENTIAL_ENV_VAR, this.getEnv(CREDENTIAL_ENV_VAR));

haber-he avatar Aug 28 '20 23:08 haber-he

Can you elaborate on this? What problem does this solve? Why this choice of variable name? Thanks.

elharo avatar Aug 29 '20 12:08 elharo

I'm trying to integrate the Google reCAPTCHA in the AWS Elastic Beanstalk environment Tomcat & Java application, but Google required one system environment variable for the default credentials, something like this: System.getenv("GOOGLE_APPLICATION_CREDENTIALS"), but looks like AWS ElasticBeanstalkEnvironment only supports the VM options. that's simple and easy if google can read CREDENTIAL_ENV_VAR from VM options, otherwise, I have to write few extra codes to read the credentials from VM options.

GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(System.getProperty("GOOGLE_APPLICATION_CREDENTIALS", System.getenv("GOOGLE_APPLICATION_CREDENTIALS"))));
RecaptchaEnterpriseServiceSettings serviceSettings = RecaptchaEnterpriseServiceSettings.newBuilder()
    .setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build();
try (RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = RecaptchaEnterpriseServiceClient.create(serviceSettings)) {
    xxxx
}

instead of expect one:

try (RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = RecaptchaEnterpriseServiceClient.create()) {
    xxx
}

haber-he avatar Sep 01 '20 01:09 haber-he

so, is it that make sense to read the variable from VM options first and the system as the default? such as

 String credentialsPath = this.getProperty(CREDENTIAL_ENV_VAR, this.getEnv(CREDENTIAL_ENV_VAR));

haber-he avatar Sep 01 '20 01:09 haber-he

cc @lsirac Will the upcoming 3pi credentials work better for this use case?

chingor13 avatar Sep 02 '20 17:09 chingor13