GDrive Token Generator for SX Installer (Authenticated Google Drive Support)

lahma0

VIP Member
Oct 15, 2018
18
8


SX Google Drive Token Generator
This Python script/app is used to simplify the process of creating an OAuth token file for use with SX Installer homebrew app on the Nintendo Switch. SX Installer v3.00 added authenticated Google Drive support via gdrive:/ paths. Despite this, Xecuter does not appear to have posted any instructions on how to actually make use of the new feature. By poking around in the .nro file, I eventually figured out its usage. This utility should make it quick and easy to create the necessary files to make use of this new feature.

Note: I suspect other variants of Tinfoil will shortly add authenticated Google Drive support (if they don't already). It is very likely that the setup process will be nearly identical if that happens, but I will update this info if I learn of any developments in this regard.

Requirements

Python script version
  • Python 3.7+
  • Python Packages:
    • oauth2client
    • google-api-python-client
EXE version
  • None
Generating OAuth Credentials
Before adding an authenticated Google Drive folder to SX Installer, you will first need to generate your OAuth credentials/token files and transfer them to your Switch Micro SD.

  • Download and extract the latest version of the Python script or EXE version from https://github.com/lahma69/SxGDriveTokenGenerator/releases
  • Ensure you are logged into the relevant Google Drive account and navigate to https://developers.google.com/drive/api/v3/quickstart/python
  • Complete Step 1, clicking the Download Client Configuration button when it appears, and save the credentials.json file to the same directory you extracted the app package to
  • Run the Python script or EXE (depending on which you downloaded)
  • Follow the prompts in the app cmd/shell window to verify your OAuth credentials (the app will open a browser window to complete this process)
  • After the app completes and the cmd/shell window closes, ensure the following 2 files exist:
    • [App/Script-Directory]/switch/sx/credentials.json
    • [App/Script-Directory]/switch/sx/gdrive.token
  • From the app directory, copy the switch folder to the root of your Switch Micro SD card
  • At the conclusion of this process, you should have the files credentials.json and gdrive.token in the directory /switch/sx on your Switch Micro SD
Note: You should delete or move any .JSON files from the app directory to a safe location. With these files, an unauthorized party could gain access to all of the files on your Google Drive.

Adding a Google Drive Folder to SX Installer
After generating your credentials/token files and transferring them to your Micro SD, you will need to add a Google Drive path to SX Installer. You can do this through either the SX Installer UI or by manually adding a path to your SX Installer locations.conf file.

To add a File Browser entry to SX Installer that points to the root of your Google Drive, you simply leave use a blank gdrive path: gdrive:/. If you're adding a File Browser entry via the SX Installer UI, simply leave the Path element empty.

If however you want to add an entry that points to a specific folder in your Google Drive, you first need to get the ID of this folder. Foruntately, this is very easy to do. Simply open https://drive.google.com, navigate to the desired folder, and then look at your browser's address bar. You will see a URL in the format of: https://drive.google.com/drive/folders/XXXXXXXXXXXX. The long string of characters (represented by X's in this example) is your folder's ID.

If you're adding a File Browser entry using the SX Installer UI, insert your folder's ID into the Path element. If you're adding an entry by modifying your locations.conf file, insert your folder's ID following the 'gdrive:/' text such as in this example: gdrive:/XXXXXXXXXXXXX.

Add via SX Installer UI
To create a File Browser entry that points to the root directory of your Google Drive, do the following:

  • Open SX Installer
  • Scroll down to File Browser and hit (A) button
  • Hit (-) button
  • Select Protocol, hit (A) button, press down until gdrive is selected, and then hit the (A) button
  • Select Title, hit (A) button, type in whatever name you want, and then hit the (+) button
  • Hit the (X) button to save the entry
Note: If you wanted the entry to point to a specific folder instead of the root of your Google Drive, before saving the entry, you would enter your folder's ID into the Path element.

Add via locations.conf
Here are a few examples of a locations.conf file to demonstrate the use of Google Drive paths. The relevant parts will appear in bold font. In the examples below, the enabled variable defines whether you want SX Installer to automatically load/scan the URL at startup. I'm not entirely sure if SX Installer even pays attention to this value on gdrive entries.

Simple entry that points to the root of your Google Drive

["usb:/","usbfs:/","sdmc:/","usbhdd:/","gdrive:/"]
Custom 'Display Name' - points to root of your Google Drive

["usb:/","usbfs:/","sdmc:/","usbhdd:/",{"url":"gdrive:/","title":"GDrive-root","enabled":1}]
Point to specific Google Drive folder

Note: Substitute the X's with your folder's ID.

["usb:/","usbfs:/","sdmc:/","usbhdd:/",{"url":"gdrive:/XXXXXXXXXX","title":"GDrive-Homebrew","enabled":1}]
Config File
Custom values can be provided to the app through the use of a JSON config file. By default, the app will attempt to load config.json from the app directory and if it is not found, a new config file will be generated using default values. A user-defined path to the config file can also be used by providing the config file path as an argument to the app:
python GenerateSxiGdCreds.py "Documents/gsxigdcreds_config.json".
Continue below for additional info.

Config File - Key/Values
KeyDefault ValueInfo
"client_secret_json_paths"["credentials.json", "client_secret*.json"]All values in this array will be searched in order until a match is found. Paths support wildcards (*) in the filename part of the path (not directory). For example, the default value "client_secret*.json" will match a file named client_secret_XX-XX.apps.googleusercontent.com.json. If multiple wildcard matches are found, the 1st will be used. Windows paths must be separated with double backslashes (\\) or forwardslashes (/).
"output_folder_path""switch/sx/"This is where the token and credentials file will be written to. The default path makes it easy to copy the switch folder to the root of your SD. Your client secret JSON is renamed/copied to the output folder as credentials.json. The output token file is named gdrive.token.
"scopes"["https://www.googleapis.com/auth/drive.readonly"]This value should be not be changed unless you have a good reason to do so. SX Installer uses the readonly scope and does not support writing anyways. Keeping it readonly means your files cannot be modified/deleted if your token is stolen.
"output_token_json_name""gdrive.token"The name of the output token file. This should not be changed or SX Installer will not find it.
"output_client_secret_json_name""credentials.json"The name of the output/copied client secret file. This should not be changed or SX Installer will not find it.

Additional Info
  • The client secrets JSON file can be named anything but most commonly it will be named one of the following:
    • credentials.json
    • client_secret.json
    • client_secret_XXXXX-XXXXX.apps.googleusercontent.com.json
  • SX Installer requires the following 2 files to be located on the SD at '/switch/sx/' for authenticated Google Drive paths to work:
    • gdrive.token
    • credentials.json
 

imprezgc8

Bannnnnn-Kai!
Staff member
Troll Eating Dogs
Nov 26, 2007
2,379
138
The Cloud
This is awesome! Thanks for this. Need to give it a go when I have some time.
 
  • Like
Reactions: lahma0

lahma0

VIP Member
Oct 15, 2018
18
8
This is awesome! Thanks for this. Need to give it a go when I have some time.
Thanks man. I would love to hear some feedback. My instructions/documentation are a bit "overdone" but the process is actually very simple. Basically just follow the instructions under "Generating OAuth Credentials". Should only take 5 min or so. Let me know how it goes.
 
  • Like
Reactions: Billy Hill

Zam89

Junior Member
Jan 3, 2019
21
13
Germany
Hi, I got everytime the error message: "failed to rename gfrive:/…"

I put the two files into switch/sx
  • gdrive.token
  • credentials.json
is there anything I missed?
OK I think the issue is that the app has no permissions to upload data to the gdrive, any idea how we can add this permissions?
 
Last edited:
  • Like
Reactions: Billy Hill

Billy Hill

Full Member
Mar 9, 2019
37
8
Germany
Hi, I got everytime the error message: "failed to rename gfrive:/…"

I put the two files into switch/sx
  • gdrive.token
  • credentials.json
is there anything I missed?
OK I think the issue is that the app has no permissions to upload data to the gdrive, any idea how we can add this permissions?
I have exactly the same problem. Would be nice if someone has an idea how to fix it,
 

lahma0

VIP Member
Oct 15, 2018
18
8
Concerning the issue of save backups not working with gdrive locations, I got an update from @blawar, and it appears that the issue is indeed with tinfoil/SX Installer using a hardcoded readonly scopes value. I think the issue should be resolved some time in the near future, as he said quote, "Will be updated soon." For more info (including a workaround using a nut server in the meantime, which apparently does use the correct scope value), see my GBATemp thread:

By the way, sorry for not replying sooner. I had no idea there were unread replies on this thread.. I guess the forum doesn't automatically subscribe you to email updates when you create a new thread. Definitely going to turn those on now.
 
  • Like
Reactions: Billy Hill

Billy Hill

Full Member
Mar 9, 2019
37
8
Germany
Hey thank u for the information. Good to hear it should be fixed in the future. I´ll check out your liked workaround and will try it.
No problem about the late answer! I dont check the forum everyday nether so i would not have read it earlier anyway.

Edit: I tried the workaround via nut but still have the same problem: "failed to rename"
I placed the credentials.json and gdrive.token into the conf folder of sx server and deleted both from the sx folder.
After starting SX Installer i got asked for permissions in the browser and agreed to it.

Do i need the credentials and gdrive.token files in both places or what im doing wrong. May it be possible that the error is caused by the specific gdrive folder i set up as path? The protocol entrys in SX Installers filebrowser and Settings/Savegames stay on "gdrive" or is it needed to change it to "nut" ? In the 2nd case it would be a problem to have chosen an specific folder?

Just noticed that credtials.json and gdrive.token is automaticaly recreated in switch/sx folder as soon as is start SX-Installer on the Switch.

Thx for any help or ideas.
 
Last edited:

lahma0

VIP Member
Oct 15, 2018
18
8
Hey thank u for the information. Good to hear it should be fixed in the future. I´ll check out your liked workaround and will try it.
No problem about the late answer! I dont check the forum everyday nether so i would not have read it earlier anyway.

Edit: I tried the workaround via nut but still have the same problem: "failed to rename"
I placed the credentials.json and gdrive.token into the conf folder of sx server and deleted both from the sx folder.
After starting SX Installer i got asked for permissions in the browser and agreed to it.

Do i need the credentials and gdrive.token files in both places or what im doing wrong. May it be possible that the error is caused by the specific gdrive folder i set up as path? The protocol entrys in SX Installers filebrowser and Settings/Savegames stay on "gdrive" or is it needed to change it to "nut" ? In the 2nd case it would be a problem to have chosen an specific folder?

Just noticed that credtials.json and gdrive.token is automaticaly recreated in switch/sx folder as soon as is start SX-Installer on the Switch.

Thx for any help or ideas.
Hey @Billy Hill, in my last msg, I was merely passing on information I received from blawar (NUT/Tinfoil dev), but I haven't actually tried it myself. It seems like it is always guess work with his releases since he doesn't document anything. If it still isn't working even through NUT, I suspect it is probably just a bug that needs to be fixed on his end. If I hear back from him, I will post back here with the info he provides. Otherwise, I guess we will have to wait for the next release to see if the problem is fixed.
 
  • Like
Reactions: Billy Hill

219jw

Noob Account
May 9, 2019
2
1
Singapore
Hi, so with this we are able to install nsp directly from the linked Gdrive. How about xci? Can we just copy and paste it over to the sd card?
 

lahma0

VIP Member
Oct 15, 2018
18
8
Yes, you should be able to install an NSP or XCI directly from your GDrive. You can also copy/paste from the GDrive as well (such as when you just want to copy an XCI from your GDrive so you can mount it instead of installing it like an NSP). Be aware that Tinfoil/SX Installer had a major update since I created the app/documentation and I know that @blawar made some significant changes, so if you have any problems, let me know.
 

219jw

Noob Account
May 9, 2019
2
1
Singapore
Yes, you should be able to install an NSP or XCI directly from your GDrive. You can also copy/paste from the GDrive as well (such as when you just want to copy an XCI from your GDrive so you can mount it instead of installing it like an NSP). Be aware that Tinfoil/SX Installer had a major update since I created the app/documentation and I know that @blawar made some significant changes, so if you have any problems, let me know.
Thanks for the info...will try and come back if facing any issue