Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bigrquery::bq_auth() Doesn't work, Warning message: Unable to refresh token: invalid_grant Account has been deleted #610

Closed
benyamindsmith opened this issue May 29, 2024 · 3 comments

Comments

@benyamindsmith
Copy link

I am trying to use the bigrquery package to read and write data to BigQuery.

When I try to get started with the bq_auth() function I get the following error:

> library(bigrquery)
> bq_auth()
Warning message:
Unable to refresh token: invalid_grant
Account has been deleted

Whats the issue here? Do I need to do anything which I missed in the docs?

@jennybc
Copy link
Collaborator

jennybc commented May 29, 2024

This would be pretty surprising as a very first bq_auth() experience, because ... what token is it trying to refresh? 🤔

Can you give any more details about the context?

@benyamindsmith
Copy link
Author

@jennybc just following up on this so that if someone else runs into the same issue they can see it here.

This was the first time I installed bigrquery and I wanted to connect to bigquery in a manner that would be similar to how I usually experienced things with googlesheets4.

As a workaround there are 2 approaches:

Possible Workarounds

1. Making a token with gargle

token<-gargle::credentials_user_oauth2(scopes="https://www.googleapis.com/auth/bigquery")
bigrquery::bq_auth(token = token)  

2. Use service account credentials.

Navigate in the GCP console to "IAM & Admin", add/select a relevant account and permissions. Generate an access key and run in R.

bq_token <- gargle::credentials_service_account(
  path = "./data/service.json",
  scopes = "https://www.googleapis.com/auth/bigquery"
)
bigrquery::bq_auth(token=bq_token)

I find 2. a better solution for pipeline development as its more friendly to deal with in a Docker setting.

Feel free to close the issue.

@jennybc
Copy link
Collaborator

jennybc commented Jun 13, 2024

I still don't understand what token the initial attempt was failing to refresh. But I can live with the mystery. The typical user can allow bq_auth() to "just work", i.e. it eventually calls the gargle functions shown above . But yes, the explicit token creation and use you show works. It just shouldn't be necessary, in general.

@jennybc jennybc closed this as completed Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants