Enable Google Drive automatic backups for users
Zero-TOTP offers a very important feature to ensure the availability of your users’ data: automatic backups to Google Drive. This feature allows users to automatically backup their data to their Google Drive account, ensuring that they can restore their data in case of loss, corruption or downtime.
By default, this feature is disabled since it requires this tenant of Zero-TOTP to be authorized by the user to access their Google Drive account (via OAuth2).
How to enable Google Drive backups
1 - Create an Oauth consent screen
Recommended : Google documentation To enable Google Drive backups, you first need to create an OAuth consent screen. This screen is necessary for users to authorize your application to access their Google Drive account. Follow these steps:
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to the APIs & Services section.
- Click on OAuth consent screen in the left sidebar.
- Select the External user type.
- Fill in the required fields such as App name, User support email, and Developer contact information.
2 - Register your application on Google Cloud
Recommended : Google documentation
To enable Google Drive backups, you need to register your application on Google Cloud and obtain the necessary credentials. Follow these steps:
- Go to the Google Cloud Console.
- Select the project you created in the previous step.
- Navigate to the APIs & Services section.
- Click on Credentials in the left sidebar.
- Click on Create credentials and select OAuth client ID.
- Configure the consent screen by providing the necessary information (application name, support email, etc.).
- Select Web application as the application type.
- Add the following authorized Javascript origins:Replace
https://<your-domain>
<your-domain>
with your actual domain name. - Add the following redirect URI:Replace
https://<your-domain>/api/v1/google-drive/oauth/callback
<your-domain>
with your actual domain name. - Click on Create to generate your OAuth client ID and secret.
- Download the JSON file containing your credentials. This file will be used to configure Zero-TOTP.
3 - Configure Google Drive access
- Go to the Google Cloud Console.
- Select the project you created in the previous step.
- Navigate to the APIs & Services section.
- Click on Library in the left sidebar.
- Search for Google Drive API and click on it.
- Click on the Enable button to enable the Google Drive API for your project.
- Go back to APIs & Services and click on Oauth Consent Screen in the left sidebar.
- Click on Data Access in the left sidebar.
- Click on Add or remove scopes.
- Add the following scopes:
.../auth/drive.appdata .../auth/drive.file
- Click on Update to save the changes.
- Publish your OAuth consent screen by clicking on the Publish App button. You will need to fill in some additional information such as the application homepage, privacy policy URL, and terms of service URL. Google will review your application before it can be published. This process may take some time, so be patient. In the meantime, you can test the Google Drive backups feature in development mode. In development mode, only whitelisted users can use the Oauth consent screen. You can add users to the whitelist by going to the OAuth consent screen page in the Google Cloud Console and clicking on the Test users tab. Add the email addresses of the users you want to whitelist.
4 - Configure Zero-TOTP
- Upload the JSON file containing your credentials to the Zero-TOTP server host.
- Mount the file into the Zero-TOTP API container. You can choose the path you want. The most convenient way is to use the already mounted
/api/config/
directory. - Edit the
config.yml
file of your Zero-TOTP instance and configure the following fields :
# [...]
features:
google_drive_backup:
enabled: true
client_secret_file_path: "/api/config/your_client_secret_file.json" # Path to the JSON file containing your credentials
# [...]