I am failing in trying to use gmailr on a headless server, though I have another server where it is working. I have looked through the documentation, but I have not found anything similar to my problem.
Several months ago I set up an Oauth Client account at Google, downloaded the json file and generated a token. I use the json and the token on my personal laptop and on a remote headless server every day. The laptop runs Linux Mint 18.3 and the server runs Ubuntu 16.04. I have now copied, via scp, the same json file and token to a new machine running Ubuntu 22.04. When I try to send an email, I get the message
! Cache contains a token with a name that does not match its hash:
The token is then renamed and the process fails, as shown below where the gargle verbosity has been set to "debug".
I would be very grateful for any guidance, as I am a novice at authentication set up.
See Edit below
> library(gmailr)
Attaching package: ‘gmailr’
The following object is masked from ‘package:utils’:
history
The following objects are masked from ‘package:base’:
body, date, labels, message
> options(gargle_verbosity = "debug")
> options(gargle_oauth_email = "fjcc.email@gmail.com")
> gm_auth_configure(path = "mail/MyApp2.json")
> gm_auth(path = "mail/MyApp2.json", cache = "mail")
trying `token_fetch()`
trying `credentials_service_account()`
JSON does not appear to represent a service account
Did you provide the JSON for an OAuth client instead of for a service account?
trying `credentials_external_account()`
aws.ec2metadata not installed; cant detect whether running on EC2 instance
trying `credentials_app_default()`
trying `credentials_gce()`
trying `credentials_byo_oauth()`
Error caught by `token_fetch()`:
inherits(token, "Token2.0") is not TRUE
trying `credentials_user_oauth2()`
Gargle2.0 initialize
adding "userinfo.email" scope
! Cache contains a token with a name that does not match its hash:
• "209fa3fd00668f622046dcf6xxxxxxxx_fjcc.email@gmail.com" (name)
• 3596ec5a3e0c1801a184031exxxxxxxx_fjcc.email@gmail.com (hash)
Will attempt to repair by renaming
loading token from the cache
no matching token in the cache
initiating new token
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
/usr/bin/xdg-open: line 882: www-browser: command not found
/usr/bin/xdg-open: line 882: links2: command not found
/usr/bin/xdg-open: line 882: elinks: command not found
/usr/bin/xdg-open: line 882: links: command not found
/usr/bin/xdg-open: line 882: lynx: command not found
/usr/bin/xdg-open: line 882: w3m: command not found
xdg-open: no method available for opening 'https://accounts.google.com...'
EDIT:
I can focus this question better with the following example. Why does the value of the token hash change when it is copied to server3? I forgot to mention that the R versions are very different (there are obstacles to updating server2 and I kept the laptop in the same state) but I'm only copying the token, I think.
#On my laptop (Linux Mint 18.3, R 3.5.1)
> TOKEN <- readRDS("mail/209fa3fd00668f622046dcf6xxxxxxxx_fjcc.email@gmail.com")
> TOKEN$hash()
[1] "209fa3fd00668f622046dcf6xxxxxxxx_fjcc.email@gmail.com"
#scp the files to the two servers
fjcc$ scp mail/209fa3fd00668f622046dcf6xxxxxxxx_fjcc.email@gmail.com username@server3:~/R/
209fa3fd00668f622046dcf6xxxxxxxx_fjcc.email@gmail.com 100% 7256 7.1KB/s 00:00
fjcc$ scp mail/209fa3fd00668f622046dcf6xxxxxxxx_fjcc.email@gmail.com username@server2:~/R/
209fa3fd00668f622046dcf6xxxxxxxx_fjcc.email@gmail.com 100% 7256 7.1KB/s 00:00
#Check the hash on server2 (Ubuntu 16.04, R 3.5.1)
> TOKEN2 <- readRDS("209fa3fd00668f622046dcf6xxxxxxxx_fjcc.email@gmail.com")
> TOKEN2$hash()
[1] "209fa3fd00668f622046dcf6xxxxxxxx_fjcc.email@gmail.com"
#Check the hash on server3 (Ubuntu 22.04, R 4.2.1)
> TOKEN3 <- readRDS("209fa3fd00668f622046dcf6xxxxxxxx_fjcc.email@gmail.com")
> TOKEN3$hash()
[1] "3596ec5a3e0c1801a184031exxxxxxxx_fjcc.email@gmail.com"