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

lahma

Member
OP
Newcomer
Joined
Nov 29, 2017
Messages
24
Trophies
0
XP
231
Country
United States


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 have not updated this utility in awhile, so it is possible this info is outdated or irrelevant. Whenever I have some free time, I will update the utility/thread.

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/lahma0/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
 
Last edited by lahma,
D

Deleted User

Guest
lol If this was a complete guide on how to pirate games from HBG there would be no issue and would be left uncensored.

If you want to post this guide on the TX Community forums, you are always welcome to do so.

Thanks.
 
  • Like
Reactions: Switch_Maniac

x65943

i can be your sega dreamcast or sega nightmarecast
Supervisor
GBAtemp Patron
Joined
Jun 23, 2014
Messages
6,230
Trophies
3
Location
ΗΠΑ
XP
26,440
Country
United States
lol If this was a complete guide on how to pirate games from HBG there would be no issue and would be left uncensored.

If you want to post this guide on the TX Community forums, you are always welcome to do so.

Thanks.
New members with low post counts can't post links anywhere, not even links to GBAtemp itself.

It's a form of spam prevention.

As you can see it's all been sorted now.
 

lahma

Member
OP
Newcomer
Joined
Nov 29, 2017
Messages
24
Trophies
0
XP
231
Country
United States
As @x65943 stated, it was simply because I am a new forum user. I have the required post count now to put URLs in my post as needed. No big deal. All sorted out now :)
 
Last edited by lahma,
  • Like
Reactions: x65943

lahma

Member
OP
Newcomer
Joined
Nov 29, 2017
Messages
24
Trophies
0
XP
231
Country
United States
I would love to hear some feedback from anyone who has made use of my documentation or utility. I guess its utility is currently a bit limited with it only working with SX Installer.. It will probably be useful to more people if/when another Tinfoil variant adds authenticated Google Drive support. Does anyone know if any of the current forks have plans for adding such support?
 

Andalitez

Well-Known Member
Member
Joined
Jul 2, 2018
Messages
507
Trophies
0
Location
Final Space
XP
1,299
Country
United States
I would love to hear some feedback from anyone who has made use of my documentation or utility. I guess its utility is currently a bit limited with it only working with SX Installer.. It will probably be useful to more people if/when another Tinfoil variant adds authenticated Google Drive support. Does anyone know if any of the current forks have plans for adding such support?
@blawar
 
D

Deleted-452294

Guest
Tinfoil has had this feature already for quite some time (since 4.10, if I remember correctly). I believe that the authentication handshake is meant to be done over "nut".
This feature was already documented, as far as I know.
 

blawar

Developer
Developer
Joined
Nov 21, 2016
Messages
1,708
Trophies
1
Age
40
XP
4,311
Country
United States
  • Like
Reactions: Deleted-452294

lahma

Member
OP
Newcomer
Joined
Nov 29, 2017
Messages
24
Trophies
0
XP
231
Country
United States
https://github.com/blawar/nut#gdrive-auth

though this utility has merit for a nutless gdrive auth setup.
Ah, thanks for the info blawar. Definitely couldn't come from a more direct source. I had actually seen the documentation for using nut to do the authentication, but I was under the impression that all of the authentication and communication with Google Drive was being done on the nut server side (and I think you're saying that is indeed the case, correct me if I'm wrong).

What I am still not sure of is whether Tinfoil supports Google Drive authentication/communication on the Tinfoil (client) side such as SX Installer is doing in its latest release. I just read the release notes for "NUT Server 2.1" which says:

Accessing gdrive while connected to nut will download the credentials so further gdrive authentication will not need to be tethered to Nut.

So does this mean NUT is generating the token file and then transferring the credentials (client secret) and token JSON file to the Switch so that Tinfoil can access authenticated Google Drive paths on its own without being connected to NUT? If so, that would be great. Only reason I have been using this latest SX Installer release instead of Tinfoil is because I thought the stand-alone authenticated Google Drive support was currently unique to SX Installer.

If this is indeed the case, can you tell me what the credentials (client secret) JSON and token JSON files need to be named as well as their expected location on the Switch Micro SD? Is it the same as I described in my documentation (credentials.json and gdrive.token in the same directory as locations.conf)? I appreciate you taking time to answer my questions!
 
  • Like
Reactions: straumli

Cory321

Well-Known Member
Newcomer
Joined
Apr 6, 2009
Messages
50
Trophies
0
XP
144
Country
United States
@lahma Yes it's supposed to be a nutless auth to google drive once you set up the credentials with nut and connect for the first time, however that's not the case. I've already tried and the google drive auth won't work in Tinfoil on its own unless tethering through nut. Seems like the token does get generated but gets rewritten each time a location with the gdrive:/ protocol gets loaded.

This is a neat solution to that problem though.

And by the way SX Installer 3.0.0 is literally blawar's Tinfoil 5.0.0 but customized with SX OS features.
 
Last edited by Cory321,

blawar

Developer
Developer
Joined
Nov 21, 2016
Messages
1,708
Trophies
1
Age
40
XP
4,311
Country
United States
@lahma Yes it's supposed to be a nutless auth to google drive once you set up the credentials with nut and connect for the first time, however that's not the case. I've already tried and the google drive auth won't work in Tinfoil on its own unless tethering through nut. Seems like the token does get generated but gets rewritten each time a location with the gdrive:/ protocol gets loaded.

This is a neat solution to that problem though.

And by the way SX Installer 3.0.0 is literally blawar's Tinfoil 5.0.0 but customized with SX OS features.

For it to transfer the token, you have to manually add the gdrive location while connected to nut, not access gdrive through usbfs / nutfs.

Documentation is not my strong suit.
 
  • Like
Reactions: Cory321

Cory321

Well-Known Member
Newcomer
Joined
Apr 6, 2009
Messages
50
Trophies
0
XP
144
Country
United States
For it to transfer the token, you have to manually add the gdrive location while connected to nut, not access gdrive through usbfs / nutfs.

Documentation is not my strong suit.

Sweet, I finally got it to work. Thank you for the clarification.
 

lahma

Member
OP
Newcomer
Joined
Nov 29, 2017
Messages
24
Trophies
0
XP
231
Country
United States
@lahma Been getting a "cannot rename file error" after attempting to backup a game save. Any thoughts on how to fix that?
As far as I've been able to ascertain, save backups to gdrive do not work (even though the update notes imply that it does). I poked around a bit in the new SX Installer 3.0.1 binary and it appears that they are still using a hardcoded readonly value for the oauth token's scope value, so I'm pretty sure that it is not possible for it to be writing anything to gdrive storage at this point.

You can see a bit more discussion about the issue here:
https://github.com/lahma69/SxGDriveTokenGenerator/issues/1

Maybe @blawar or someone else that knows a bit more can chime in with some more info.
 
  • Like
Reactions: straumli

blawar

Developer
Developer
Joined
Nov 21, 2016
Messages
1,708
Trophies
1
Age
40
XP
4,311
Country
United States
As far as I've been able to ascertain, save backups to gdrive do not work (even though the update notes imply that it does). I poked around a bit in the new SX Installer 3.0.1 binary and it appears that they are still using a hardcoded readonly value for the oauth token's scope value, so I'm pretty sure that it is not possible for it to be writing anything to gdrive storage at this point.

You can see a bit more discussion about the issue here:
https://github.com/lahma69/SxGDriveTokenGenerator/issues/1

Maybe @blawar or someone else that knows a bit more can chime in with some more info.

the authorization / permissions are done in open source nut on the PC, though i’m trying to remember off he top of my head of permissions are sent with the refresh token.
 

lahma

Member
OP
Newcomer
Joined
Nov 29, 2017
Messages
24
Trophies
0
XP
231
Country
United States
the authorization / permissions are done in open source nut on the PC, though i’m trying to remember off he top of my head of permissions are sent with the refresh token.
So you can backup saves to gdrive as long as you are connected to a NUT server? Will this work with credentials.json and gdrive.token inside of the tinfoil/SX-Installer folder on the Switch side (micro sd)?
 

blawar

Developer
Developer
Joined
Nov 21, 2016
Messages
1,708
Trophies
1
Age
40
XP
4,311
Country
United States
So you can backup saves to gdrive as long as you are connected to a NUT server? Will this work with credentials.json and gdrive.token inside of the tinfoil/SX-Installer folder on the Switch side (micro sd)?

I verified, you are correct, scope is sent with refresh token. Will be updated soon.
 

lahma

Member
OP
Newcomer
Joined
Nov 29, 2017
Messages
24
Trophies
0
XP
231
Country
United States
I verified, you are correct, scope is sent with refresh token. Will be updated soon.
I have several people asking me about this on my Github and Xecuter forum thread, so before I report back to them, I just want to ensure I'm understanding you correctly. You're saying save backups to gdrive will not work in the current version of Tinfoil when the credentials file is in the Switch Tinfoil folder (because tinfoil.nro is using a hardcoded readonly scope value), right? However, if you put the credentials file on the nut server side (next to nut binary or conf directory), then it will work correctly (because nut is using the correct scope value), correct?

I'm glad to hear that you are going to fix this in an update. I think many people will find it very useful, including myself. Being able to do cloud saves to Google Drive any time you want without having to be connected to a nut server will be awesome.

While we're on the topic, I guess I should also mention that I tried backing up saves to a smb/samba location (without being connected to my nut server) and that also failed. I think it was the same exact error as when trying to backup to gdrive... something about "cannot rename file" or something to that effect (I can get the exact error msg if that would be helpful.. just let me know).
 

Arkangelshadow

Well-Known Member
Member
Joined
Jun 6, 2013
Messages
151
Trophies
1
Age
38
XP
1,455
Country
Mexico
Hi, thx for your guide. I was able to see my gdrive files inside SX Installer.

But it is not sorted; how can I sort them by name at least?

For example i just want to update a game but i can't find it; or install all the dlc?
 

lahma

Member
OP
Newcomer
Joined
Nov 29, 2017
Messages
24
Trophies
0
XP
231
Country
United States
Sorry @Arkangelshadow I just now saw your msg. You can sort any listing in Tinfoil/SX Installer. Once you are in the list of titles that you want to sort, simply press the "+" button on your controller, select "Name", and hit the "A" button on your controller. This will sort the list alphabetically by their title. Let me know if you have any problems or have any other questions. I'd be glad to help.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    SylverReZ @ SylverReZ: Or Genesis.