I have doubts about how the Google Drive API works and how should I use it for my use cases. I have a REST API (based on NodeJS) which uploads documents in the drive. The only user that is actually accessing the drive is the one that runs the REST API (the root on the machine). As I understand, the OAuth2 protocol allows user to allow third-party applications to access it's information. So I'm not sure how my case is compatible with it. I have only one user that requires a one-time permission to be available forever.
Currently I have managed to use the Drive by doing authentication as follows:
const { google } = require('googleapis');
const oauth2Client = new google.auth.OAuth2(
CLIENT_ID,
CLIENT_SECRET,
REDIRECT_URI
);
oauth2Client.setCredentials({ refresh_token: REFRESH_TOKEN });
drive_instance = google.drive({
version: 'v3',
auth: oauth2Client,
});
For that, I registered the Google Drive through the Google Console. There I have the following fields:
{
"web": {
"client_id": "CILENT_ID",
"project_id": "project-id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "CLIENT_SECRET"
"redirect_uris": [
]
}
}
Now, going over the docs, they suggest using their Playground. But the period of it being valid is one week.
I want to go production with my REST API but I'm not sure what REDIRECT_URI
and REFRESH_TOKEN
should be in that case. I actually want to have three instances:
Dev
- For development.Prod
- For production.Test
- For integration tests.
I have the basic understanding of how the OAuth2 Protocol works but I'm not sure how to create those three instances, based no my use case. Basically I thought of keeping a config file, one for each mode, and the REST API will use it (based on the CLI options). Can someone please explain the general idea of all the options CLIENT_ID
, CLIENT_SECRET
, REDIRECT_URI
, REFRESH_TOKEN
? Do I actually need to "redirect" in each mode, even if it's one user?