I have created a user with access to a specific google drive. Through a Spring Boot application (jhipster) I connect with this user to the G-Drive. My problem is the authentication. I use this code in order to authenticate (as in the samples that Google provides for web applications):
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(".")))
.setApprovalPrompt("auto")
.build();
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
The first time the application starts it tries to find the StoredCredential file. If it does not then Google provides a link for the user to open it in his browser:
Please open the following address in your browser:
https://accounts.google.com/o/oauth2/auth?...
Since I am not able to do this from the EC2 instance I do this on my local computer and I upload the file on the expected location from the server. Finally a restart makes the web server to work for a while until the token expires. After that I have to do the same procedure.
Obviously I am doing something wrong here. What is the correct procedure for a web application to connect on the G-Drive every few minutes?
UPDATE: I found (https://cloud.google.com/storage/docs/authentication) that I must use a service account as the link suggests for the cloud storage. Unfortunately I have downloaded the json for the service account, set the env variable but this seems that it does not work for the google drive rest api (v3).
Thank you