Google Drive

Back up your end users device's key shares to Google Drive.

This is how you set up Google Drive backups in your app. The first five steps are for all apps - both on Android and iOS.

Create a Google app

To enable Google Drive backups, first create a Google Project within your organization that will act as the OAuth consumer.

  1. Create a new Google project in the Google Cloud Console. ​
  2. In the APIs & Services page, click ENABLE APIS AND SERVICES.
  3. Search for Google Drive API, select it, and click Enable.
  4. Click the OAuth consent screen.
    • For user type, select internal.
    • Provide the relevant information.
      (Skip scopes.)
  5. Click Credentials in the left menu and select Create Credentials.

Continue for Android apps

  1. Select OAuth client ID and choose Android from the Application Type list.
  1. Provide details in the form, as instructed, with Name, Package name, and SHA-1 from your Keystore.
    Note that when testing, it's recommended to use your debug.keystore at /android/app/debug.keystore. However, you'll need to switch this value when pushing it to the store.

  2. Find the Sha-1 fingerprint with this command from the root project folder:
    keytool -keystore ./app/debug.keystore -list -v

  3. Once you have successfully created your Android Client ID , download the JSON, and rename it to google-service.json.

  4. Move the downloaded file into the /android/app directory.

  5. Add emails for internal testing until you've published your app for external use.

  6. Add dependencies to the following Fordefi SDKs into package.json:

    npm i @fordefi/wallet-sdk-react-native
    npm i @fordefi/backup-provider-react-native
    
  7. Into your android/app/build.gradle add the following dependencies:

    dependencies{
    ...
    
     implementation 'com.google.android.gms:play-services-auth:20.7.0'
     implementation('com.google.api-client:google-api-client-android:2.2.0') {
         exclude group: 'org.apache.httpcomponents'
         exclude module: 'guava-jdk5'
     }
     implementation('com.google.apis:google-api-services-drive:v3-rev20230822-2.0.0') {
         exclude group: 'org.apache.httpcomponents'
         exclude module: 'guava-jdk5'
     }
        implementation('com.google.api-client:google-api-client-android:2.2.0'){
            exclude group: 'org.apache.httpcomponents'
        }
        implementation('com.google.apis:google-api-services-drive:v3-rev197-1.25.0')  {
            exclude group: 'org.apache.httpcomponents'
        }
    }
    
  8. Using in a React Native project:

    import {
        backupKeyset,
        CloudBackupOptions,
        BackupProvider,
    } from '@fordefi/wallet-sdk-react-native';
    
    import {
        initBackupProvider,
        BackupConfiguration,
    } from '@fordefi/backup-provider-react-native';
    
  9. Call to init BackupProvider:

    await initBackupProvider(null)
    
  10. Call backup with Google Drive backup option:

    const backupOptions: CloudBackupOptions = {
      backupProvider: BackupProvider.GoogleDrive,
    };
    const result = await backupKeyset(keysetId, backupOptions);
    

Continue for iOS apps

  1. Select OAuth client ID and choose iOS from the Application Type list.
  1. Get your Bundle ID from the React Native or iOS project.

  2. Once you've successfully created your iOS client ID, download the .plist configuration and copy the REVERSED_CLIENT_ID to the URL Scheme section of your info.plist - either in Xcode or your IDE:

    ...  
    <key>CFBundleURLTypes</key>  
    <array>  
    	<dict>  
    		<key>CFBundleTypeRole</key>  
    		<string>Editor</string>  
    		<key>CFBundleURLSchemes</key>  
    		<array>  
    			<string>REVERSE_CLIENT_ID</string>  
    		</array>  
    	</dict>  
    </array>  
    ...
    
  3. Rename the downloaded .plist file to GoogleService-Info.plist and save it to your /ios directory.

  4. Set up in the project:

    plugin 'cocoapods-user-defined-build-types'
    
    enable_user_defined_build_types!
    
    pod 'GoogleSignIn', '7.0.0', :build_type => :dynamic_framework
    pod 'GoogleAPIClientForREST/Drive', '3.1.0', :build_type => :dynamic_framework
    
  5. After adding new dependencies, remove the pods folder and node_modules and run:

    sudo gem install cocoapods-user-defined- 
    build-types
    
  6. Then run:

     pod install --repo-update
    
  7. Using in the React Native project:

    import {
        backupKeyset,
        FordefiSdkErrorResult,
        FordefiSdkConfiguration,
        CloudBackupOptions,
        BackupProvider,
    } from '@fordefi/wallet-sdk-react-native';
    
    import {
        initBackupProvider,
        BackupConfiguration,
    } from '@fordefi/backup-provider-react-native';
    
  8. Register your GOOGLE_DRIVE_IOS_CLIENT_ID in the BackupConfiguration function and call to init BackupProvider:

    const config: BackupConfiguration = {
        googleDriveClientID: Config.GOOGLE_DRIVE_IOS_CLIENT_ID,
    };
    await initBackupProvider(config)
    
  9. Call backup with Google Drive backup option:

    const backupOptions: CloudBackupOptions = {
         backupProvider: BackupProvider.GoogleDrive,
    };
    const result = await backupKeyset(keysetId, backupOptions);