I have an Angular app, developed in Angular 8 using Google Earth Engine for NDVI mapping.
Below is the basic code tried initially:
ee.data.authenticateViaPrivateKey(PRIVATE_KEY_JSON_FILE_PATH);
Since, it showed an error so tried to call this file with microservice API call
this.googleapi.authGoogleEarthEngineService().subscribe(
(data) => {
ee.data.authenticateViaPrivateKey(data);
// HERE data HAS RECEIVED THE JSON FILE CORRECT. CHECKED WITH CONSOLE.LOG FUNCTION
return data;
},
(err: HttpErrorResponse) => {
// ERROR HANDLING
}
);
I tried microservice approach because a connection of mine suggested to use server-side call to this privatekey JSON file.
Also, tried this code to see if something else isn't the issue:
ee.data.authenticateViaPrivateKey(
PRIVATE_KEY, () => {
console.log('Authentication succeeded!');
// Attempt to initialize Earth Engine.
ee.initialize(
null, null,
// On a successful initialize
() => {
console.log('Successfully initialized the EE client library.');
app.listen(PORT);
console.log(`Listening on port ${PORT}`);
res.send("Authenticated and initialized!\n");
},
// On a failure to initialize
(err) => {
console.log(err);
console.log(`Initialization failed.`);
}
);
},
// When the authentication failed.
(err) => {
console.log(err);
console.log('Authentication failed');
}
);
In either case, the error is same i.e.
ERROR Error: Use of private key authentication in the browser is insecure. Consider using OAuth, instead.
With ee.data.authenticateViaOauth(this.CLIENT_ID)
, it logs permission denied error when any email ID other than email ID associated with Google Earth billing is used. So, that approach also doesn't work out for me. However, I've checked Google cloud console and billing. Everything seems good.
Any guidance or resource in the right direction?
Edit:
After considering Daniel's answer, if I try with OAuth then it authenticates only with the email ID associated in the billing. Is this a normal behavior or am I missing something in the process?