简体   繁体   中英

Application Default Credentials fails to create the Google App Engine service account credentials

I'm working on an app that starts Google VM instances using a rest endpoint deployed on AppEngine.

when initializing Compute Engine API, I provide the application default credential (since I'm expecting that this will return the AppEngine service account credentials)

GoogleCredential credential = GoogleCredential.getApplicationDefault();
if (credential.createScopedRequired()) {
    List<String> scopes = new ArrayList<>();
    // Set Google Compute Engine scope to Read-write.
    scopes.add(ComputeScopes.COMPUTE);
    credential = credential.createScoped(scopes);
}
return new Compute.Builder(httpTransport(), jsonFactory(), credential)
                  .setApplicationName(env.getProperty("spring.application.name"))
                  .build();

But I end up with the error :

java.io.IOException: Application Default Credentials failed to create the Google App Engine service account credentials

I 'm using libraries :

<dependency>
    <groupId>com.google.api-client</groupId>
    <artifactId>google-api-client</artifactId>
    <version>${google-api-client.version}</version>
</dependency>
<dependency>
    <groupId>com.google.apis</groupId>
    <artifactId>google-api-services-compute</artifactId>
    <version>${google-api-services-compute.version}</version>
</dependency>

I solved this by using google-api-cient-appengine instead of google-api-client :

<dependency>
    <groupId>com.google.api-client</groupId>
    <artifactId>google-api-client-appengine</artifactId>
    <version>${google-api-client-appengine.version}</version>
</dependency>

and initialized GoogleCredential using :

GoogleCredential credential = AppEngineCredentialWrapper.getApplicationDefault();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM