r-lib / gargle

Infrastructure for calling Google APIs from R, including auth
https://gargle.r-lib.org/
Other
113 stars 33 forks source link

gargle::credentials_service_account() gives JSON premature EOF error #253

Closed Arf9999 closed 1 year ago

Arf9999 commented 1 year ago

This may be the same issue as #191

I have a google cloud service account JSON file and am trying to create a token for google drive for a script to run independently.

token <- gargle::credentials_service_account("*********74602.json") results in:

Error: parse error: premature EOF

                     (right here) ------^

I have checked the file and jsonlite::fromJSON() parses the file perfectly.

jsonlite::fromJSON("***********74602.json") 
$type
[1] "service_account"

$project_id
[1] "*************"

$private_key_id
[1] "04baa0b74602afd72987bf36345a55b254d418cb"

$private_key
[1] "-----BEGIN PRIVATE KEY-----\
xxxxx redacted xxxxx

\n-----END PRIVATE KEY-----\n"

$client_email
[1] "arf9999@*************iam.gserviceaccount.com"

$client_id
[1] "**************70027"

$auth_uri
[1] "https://accounts.google.com/o/oauth2/auth"

$token_uri
[1] "https://oauth2.googleapis.com/token"

$auth_provider_x509_cert_url
[1] "https://www.googleapis.com/oauth2/v1/certs"

$client_x509_cert_url
[1] "https://www.googleapis.com/robot/v1/metadata/x509/arf9999%40***********.iam.gserviceaccount.com"

$universe_domain
[1] "googleapis.com" 

What am I doing wrong?

jennybc commented 1 year ago

The first argument of credentials_service_account() is scopes, so you are getting the default of path = "", which is what gets sent to jsonlite::fromJSON().

credentials_service_account <- function(scopes = NULL,
                                        path = "",
                                        ...,
                                        subject = NULL) {...}

Name the path argument:

token <- gargle::credentials_service_account(path = "*********74602.json")