Comments (6)
The bottom line is that the OAuth client needs to match in these two contexts (along with other token details, such as the target user, scopes, etc.):
- The context where you interactively obtain and cache the token
- The context where you want to non-interactively rediscover and refresh the token
The tricky bit to appreciate is that the default OAuth client varies with the computing environment:
- On a local computer, the default is a tidyverse client, of the "installed" type
- On RStudio Server, Posit Workbench/Connect/Cloud, and Google Colab, the default is a tidyverse client, of the "web" type
So, to ensure client matching, you probably need to explicitly specify the client type on one end, to match the other.
If you've got something working, then godspeed.
from googledrive.
I can tell you are using an OAuth client of the "installed" or "Desktop app" type, which is likely no longer going to work in a cloud setting.
oauth client name: tidyverse-clio
oauth client name: installed
(that second debugging message should read "oauth client type", oops)
Can you say more about the context and computing environment?
What is the process you are using to put that token into the .secrets
cache?
Overall this feels like you've gotten a token in one (non-cloud?) context and are then trying to use it in a cloud context. And since we default to OAuth clients of a different type in those two settings, it's causing the cache miss. I just need to understand your situation better to advise on what to do.
from googledrive.
Ah, I misunderstood the documentation. I interpreted it to mean that if there is a single token in the cache then it must match.
You are correct about my process. The token was generated using googledrive on my local machine, and I just added it to .secrets using git. Then it is failing to match in the cloud. I cannot generate the token in the cloud anymore, because Rstudio server no longer works there.
Is there a way to generate a token locally that will match, or to instruct the cloud to accept the locally generated token?
from googledrive.
In the code that needs to use a cached token (originally obtained on your local computer) in a cloud context, you'll want to set some options:
options(
gargle_oauth_cache = ".secrets",
gargle_oauth_email = TRUE,
gargle_oauth_client_type = "installed"
)
Or you can intentionally use the OAuth client of "web" type locally, which is a clunkier flow, but still works, when you first capture the token:
options(
gargle_oauth_cache = ".secrets",
gargle_oauth_client_type = "web"
)
# obtain a token interactively HERE
in which case you would delete gargle_oauth_client_type = "installed"
from the code running in the cloud (because the default "web" is what you want). Or have gargle_oauth_client_type = "web"
everywhere just to remind yourself what you're doing.
from googledrive.
The first approach was unsuccessful, adding the option gargle_oauth_client_type = "installed"
still misses the cached token:
> files <- drive_ls(instances_id)
attempt to access internal gargle data from: googledrive
trying `token_fetch()`
Trying `credentials_byo_oauth()` ...
Error caught by `token_fetch()`:
inherits(token, "Token2.0") is not TRUE
trying `credentials_service_account()`
Error caught by `token_fetch()`:
Argument 'txt' must be a JSON string, URL or file.
trying `credentials_external_account()`
aws.ec2metadata not installed; can't detect whether running on EC2 instance
trying `credentials_app_default()`
Trying `credentials_gce()` ...
Error caught by `token_fetch()`:
Expected content type application/json, not application/text.
trying `credentials_user_oauth2()`
attempt to access internal gargle data from: googledrive
Gargle2.0 initialize
adding "userinfo.email" scope
loading token from the cache
email: '*'
oauth client name: tidyverse-clio
oauth client name: installed
oauth client id: 603366585132-dpeg5tt0et3go5of2374d83ifevk5086.apps.googleusercontent.com
scopes: ...drive, ...userinfo.email
token(s) found in cache:
134f22af3ae3a9f0b7f0eb57dd61916f_james.hirschorn@quantitative-technologies.com
token we are looking for:
no matching token in the cache
initiating new token
Since rstudio server is working again (in the cloud), I generated a new token interactively in the cloud.
I also need to use this noninteractively in the cloud, so I put the option gargle_oauth_client_type = "web"
in my script (not sure if this should be necessary?) and everything seems OK now.
from googledrive.
Well, it seems to have solved my issue. I can use my token with noninteractive authentication is two different contexts by specifying the client type.
from googledrive.
Related Issues (20)
- googledrive::drive_mkdir() stalls forever when path is to a shared drive, overwrite = FALSE, and file name already exists in path
- Embrace `@examplesIf` harder HOT 1
- Implement `drive_scopes()`
- Release googledrive 2.1.1 HOT 2
- Access blocked: This app’s request is invalid HOT 5
- unable to generate Google autharization tokens in rstudioserver HOT 3
- drive_auth() throws `Error in value[[3L]](cond) : attempt to apply non-function` HOT 4
- drive_ls returns error due to "colonnade" being deprecated HOT 1
- Unclear how to access "shared folders" from "shared drives" vs. shared HOT 2
- `drive_download()` error with KML mimeType HOT 4
- Service account authorization HOT 3
- Legacy app documentation still online on the official website
- google drive authentication problem
- Revoke Anyone With Link Permission. HOT 1
- as_dribble() and drive_ls() get stuck in folders 3 levels deep HOT 2
- read file into environment
- Should ?drive_upload:overwrite mention drive_put? HOT 1
- Error in curl::curl_fetch_memory(url, handle = handle) when uploading to googledrive in Rstudio
- Allow to parse URL with query string
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from googledrive.