I'm trying to migrate a project from objectify5 to objectify6.
All works well when running the app locally, but when running in production appengine standard I get
Caused by: com.google.datastore.v1.client.DatastoreException: Request is missing required
authentication credential. Expected OAuth 2 access token, login cookie or other valid
authentication credential.
See https://developers.google.com/identity/sign-in/web/devconsole-project.,
code=UNAUTHENTICATED
at com.google.datastore.v1.client.RemoteRpc.makeException(RemoteRpc.java:171)
at com.google.datastore.v1.client.RemoteRpc.makeException(RemoteRpc.java:239)
at com.google.datastore.v1.client.RemoteRpc.call(RemoteRpc.java:100)
at com.google.datastore.v1.client.Datastore.lookup(Datastore.java:93)
at com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.lookup(HttpDatastoreRpc.java:171)
This is very strange since the documentation specifically states that if my app is running on appengine env standard all I need to do is
ObjectifyService.init();
I have also tried this
String projectId = "my-project-id";
Credentials defaultCredentials = GoogleCredentials.getApplicationDefault();
DatastoreOptions.Builder datastoreOptionsBuilder =
DatastoreOptions.newBuilder()
.setProjectId(projectId)
.setCredentials(defaultCredentials);
ObjectifyService.init(new ObjectifyFactory(datastoreOptionsBuilder.build()
.getService()));
and got this
Caused by: java.io.IOException: The Application Default Credentials are not available.
They are available if running in Google Compute Engine. Otherwise, the environment variable
GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(
DefaultCredentialsProvider.java:134)
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(
GoogleCredentials.java:125)
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(
GoogleCredentials.java:97)
at media.vrtual.api.configuration.jersey.VrtualApiApplication.setUpDatabase(
VrtualApiApplication.java:283)
This is very confusing because my app is running on appengine standard environment. The default credentials should be available but they are not.
How can I provide the credentials for this to work?