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

Problem with authentication #274

Closed
DavidGarciaEstaun opened this issue Sep 4, 2019 · 9 comments

Comments

@DavidGarciaEstaun
Copy link

@DavidGarciaEstaun DavidGarciaEstaun commented Sep 4, 2019

Hi,

I am trying to authenticate with the new authentication method but something goes wrong.
When I execute this code:
drive_auth()

I am receiving this message:

> drive_auth()
Error: Can't get Google credentials.
Are you running googledrive in a non-interactive session? Consider:
  * `drive_deauth()` to prevent the attempt to get credentials.
  * Call `drive_auth()` directly with all necessary specifics.

Session info:

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 
 
locale:
[1] es_ES.UTF-8/es_ES.UTF-8/es_ES.UTF-8/C/es_ES.UTF-8/es_ES.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] googledrive_1.0.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2       crayon_1.3.4     dplyr_0.8.3      assertthat_0.2.1 R6_2.4.0         jsonlite_1.6    
 [7] magrittr_1.5     httr_1.4.1       pillar_1.4.2     rlang_0.4.0      curl_4.0         fs_1.3.1        
[13] rstudioapi_0.10  tools_3.6.1      glue_1.3.1       purrr_0.3.2      compiler_3.6.1   askpass_1.1     
[19] pkgconfig_2.0.2  gargle_0.3.1     openssl_1.4.1    tidyselect_0.2.5 tibble_2.1.3 

Can you help me please?

Thanks!

@jennybc

This comment has been minimized.

Copy link
Member

@jennybc jennybc commented Sep 4, 2019

We can get more information if, in a fresh session, before you execute drive_auth(), directly or indirectly, you set an option to make gargle more chatty:

options(gargle_quiet = FALSE)

Is your report above totally complete? You execute drive_auth() in an interactive session and this is truly all that happens -- you see that error?

@DavidGarciaEstaun

This comment has been minimized.

Copy link
Author

@DavidGarciaEstaun DavidGarciaEstaun commented Sep 5, 2019

Thanks for your asnwer.
I am executing this code in a normal session with R Studio Desktop:

library(googledrive)

options(gargle_quiet = FALSE)
drive_auth()

And here the traces:

trying token_fetch()
trying credentials_service_account()
Error: Argument 'txt' must be a JSON string, URL or file.
trying credentials_app_default()
trying credentials_gce()
trying credentials_byo_oauth()
Error: inherits(token, "Token2.0") is not TRUE
trying credentials_user_oauth2()
Gargle2.0 initialize
attempt from: googledrive
adding 'userinfo.email' scope
loading token from the cache
Error: Cache contains tokens with names that do not match their hash:
  * Token stored as 'ff5ac8544ab9d11dda711c6555a0c8cf_asimon@bobochoses.com'
        but hash is 'd8bd72a790109fea516d638703457f64_asimon@bobochoses.com'
Error: Can't get Google credentials.
Are you running googledrive in a non-interactive session? Consider:
  * `drive_deauth()` to prevent the attempt to get credentials.
  * Call `drive_auth()` directly with all necessary specifics.

Thanks in advance.

@jennybc

This comment has been minimized.

Copy link
Member

@jennybc jennybc commented Sep 5, 2019

So here is our problem:

Error: Cache contains tokens with names that do not match their hash:
  * Token stored as 'ff5ac8544ab9d11dda711c6555a0c8cf_asimon@bobochoses.com'
        but hash is 'd8bd72a790109fea516d638703457f64_asimon@bobochoses.com'

It would be nice to know how things got this way. Have you done anything interesting with this files, like move them from one computer to another? Or have you upgraded R very recently? Or are you using your own OAuth app?

But we don't actually have to solve that mystery to get you unstuck (unless it keeps recurring). You should delete the borked cached token and walk through the OAuth dance again. You could delete that file any way you know how, but here's one way to do it from R:

cache <- gargle::gargle_oauth_cache()
if(is.na(cache)) {
  cache <- "~/.R/gargle/gargle-oauth"
}
bad_hash <- "ff5ac8544ab9d11dda711c6555a0c8cf_asimon@bobochoses.com"
(delete_me <- fs::dir_ls(cache, regexp = bad_hash))
fs::file_delete(delete_me)

Each .rds file there holds on OAuth2 token, which should be regarded as semi-perishable, so it's also not crazy to just clean everything out. Especially if you suspect you have a borked cache. But the code above targets the specific token that you error indicates is the problem.

@DavidGarciaEstaun

This comment has been minimized.

Copy link
Author

@DavidGarciaEstaun DavidGarciaEstaun commented Sep 9, 2019

Hi Jenny,

Sorry for the delay.
I just install R again from 0 and I am getting the same error.
If I put the code to remove the token I see this:


> fs::dir_ls(cache, regexp = bad_hash)
Error in enc2utf8(path) : argument is not a character vector
> cache
[1] TRUE
> cache <- gargle_oauth_cache()
> if(is.na(cache)) {
+     cache <- "~/.R/gargle/gargle-oauth"
+ }
> bad_hash <- "ff5ac8544ab9d11dda711c6555a0c8cf_asimon@bobochoses.com"
> (delete_me <- fs::dir_ls(cache, regexp = bad_hash)) 
Error in enc2utf8(path) : argument is not a character vector
> fs::file_delete(delete_me)
Error in which(is.na(x)) : objeto 'delete_me' no encontrado
> 
@jennybc

This comment has been minimized.

Copy link
Member

@jennybc jennybc commented Sep 9, 2019

Maybe our current struggle is around finding the "right" definition of home directory on Windows.

Small adaptation of the troubleshooting code:

cache <- gargle::gargle_oauth_cache()
if(is.logical(cache)) {
  cache <- fs::path_home_r(".R/gargle/gargle-oauth")
}
bad_hash <- "ff5ac8544ab9d11dda711c6555a0c8cf_asimon@bobochoses.com"
(delete_me <- fs::dir_ls(cache, regexp = bad_hash))
fs::file_delete(delete_me)

Feel free to accomplish this anyway you know how. We're just trying to delete the file that's generating this "Error: Cache contains tokens with names that do not match their hash". The code is just an attempt to be helfpul and explicit.

@batpigandme

This comment has been minimized.

Copy link
Member

@batpigandme batpigandme commented Sep 11, 2019

Woo! This worked for me (Mac OS 10.14.6), thus resolving my +1 in r-lib/gargle#109.

I ended up just manually going to "~/.R/gargle/gargle-oauth", but that might have been because I was using your first code chunk without the fs::path_home("blah"). In that case, the error messages were the same as above.

(delete_me <- fs::dir_ls(cache, regexp = bad_hash))
#> Error in enc2utf8(path) : argument is not a character vector
fs::file_delete(delete_me)
#> Error in which(is.na(x)) : object 'delete_me' not found

From there, I was able to authenticate with multiple emails.


Notes:
I wouldn't call my R version update "very recent," but it was definitely after my first use of gargle authentication (which was probably around when you presented in to the t'verse team, Jenny, in mid-February).

My first troubleshooting move (which didn't work) was taken from the gmailr 1.0.0 release article:

We recommend that you delete any vestigial .httr-oauth files lying around your gmailr projects and re-authorize gmailr, i.e. get a new token, stored in the new way.

Might it be worth adding something to a similar effect re. vestigial gargle-oauth hashes? Happy to PR this to wherever you think is best (gargle would take care of the possibility of running into this in multiple packages, but I'm not sure if end users will see it there).

@MarkEdmondson1234

This comment has been minimized.

Copy link

@MarkEdmondson1234 MarkEdmondson1234 commented Sep 11, 2019

I reckon this is the difference between R 3.5 and 3.6 serialization of rds, as I had similar issues when I updated R.

@jennybc

This comment has been minimized.

Copy link
Member

@jennybc jennybc commented Sep 11, 2019

Yeah I have been suspecting what @MarkEdmondson1234 says. My main takeaway from these 2 threads is that I have to surface this sort of mismatch differently or repair it automatically or something.

@enricodata

This comment has been minimized.

Copy link

@enricodata enricodata commented Sep 27, 2019

I have a similar problem in Rstudio server.
I have some code that it used to run correctly until one week ago but not when I try to get data from googledrive I get the following error:

createTcpServer: address already in use Error: Can't get Google credentials. Are you running googledrive in a non-interactive session? Consider: * drive_deauth() to prevent the attempt to get credentials. * Call drive_auth() directly with all necessary specifics.

Therefore I run and the following again:
drive_auth(use_oob=TRUE)
but when I restart the session or knit a rmd document then I get again the above error.

Then I run the following:
options(gargle_quiet = FALSE)
drive_auth(use_oob=TRUE)
and this is the result:

trying token_fetch()
trying credentials_service_account()
Error: Argument 'txt' must be a JSON string, URL or file.
trying credentials_app_default()
trying credentials_gce()
trying credentials_byo_oauth()
Error: inherits(token, "Token2.0") is not TRUE
trying credentials_user_oauth2()
Gargle2.0 initialize
attempt from: googledrive
adding 'userinfo.email' scope
loading token from the cache
no matching token in the cache

putting token into the cache

I also tried the same in Rstudio with a mac and the result is the same.

Do you have any suggestions how to solve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.