tidyverse / googledrive

Google Drive R API
https://googledrive.tidyverse.org/
Other
323 stars 48 forks source link

Service account authorization #442

Closed bllittle closed 1 year ago

bllittle commented 1 year ago

Hi. I've used the interactive version for a couple of years fine, but now it appears my organization has a new policy in place that won't allow me to authorize through Tidyverse (the web page that opens says: "Access blocked: Authorization Error" with descriptive text saying "The District does not have an agreement in place with this service"). I do have a service account that I use with C# so I tried changing the authorization method to use that. I placed the service account JSON file in a directory: pathServiceAccount <- "//<>/ServiceAccount/ard-g-drive-63c62d4acb38.json)" and used that in drive_auth(path = pathServiceAccount). I get the following error: Error in drive_auth(): ! path does not represent a service account. If I use list.files(path="<>"), it returns [1] "ard-g-drive-63c62d4acb38.json" so I think I have the path correct. If I open the JSON file with a text editor, it does contain: ""type": "service_account"," as the first attribute, followed by the private key attributes, etc. Since this is not a personal Drive but an enterprise Drive account, are there other parameters I need to set to use drive_auth()? As I recall, there were some additional parameters beyond the typical examples I found online I needed to set in C# before I could get it to work. Thank you.

jennybc commented 1 year ago

Here is the function that generates this message:

https://github.com/r-lib/gargle/blob/1c821900b560d84478fce1067c68cc8a9303be15/R/credentials_service_account.R#L83-L103

Maybe you can run that code by hand with the path you're providing and see where things go awry. Is the JSON being successfully read? Does it have an unexpected form?

bllittle commented 1 year ago

Thanks so much for the quick response and the excellent suggestions. I broke it down piece by piece and even though list.files() is finding the file easily enough, when I tried using jasonlite directly, it had problems with the path. I'm researching what limitations jasonlite might have in traversing a network path now.

bllittle commented 1 year ago

Success! I changed from putting the full path as a text string into a variable passed to drive_auth() to defining the file as an object with serviceFile <- file.path('long file path','myAssignedServiceAccount.json'). Works like a charm now! It might be useful to provide this type of example in the vignette. Here's a truncated version of what works for me: serviceFile <- file.path('', '', 'dpsnt07', 'GoogleDrive','ServiceAccount', 'ard-g-drive-63c62d4acb38.json'). The two initial empty strings represent the UNC "\" drive address prefix in a Windows environment.