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

Update instructions re: how to get one's own app #143

Closed
jennybc opened this issue Aug 31, 2020 · 7 comments · Fixed by #183
Closed

Update instructions re: how to get one's own app #143

jennybc opened this issue Aug 31, 2020 · 7 comments · Fixed by #183
Labels
documentation good first issue ❤️ good issue for first-time contributors help wanted ❤️ we'd love your help! tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day

Comments

@jennybc
Copy link
Member

jennybc commented Aug 31, 2020

I used gmailr today for the time in a long time (definitely since the switch to gargle).

Overall, it was really smooth! I used the env var approach to convey the path to the JSON holding client ID and secret.

The process of getting one's own oauth app isn't reflected very well by the current README. I was able to do it because I have a lot of background knowledge, but it would be nice to update this. I might do this myself or perhaps someone else will do so.

@jennybc jennybc added documentation good first issue ❤️ good issue for first-time contributors help wanted ❤️ we'd love your help! tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day labels Aug 31, 2020
@maelle
Copy link
Contributor

maelle commented May 4, 2021

I'd like to read these explanations as I suspect it'd solve #152 (or make me give up, if one needs to verify the app). 😁

@thisisnic
Copy link

I just went through this process today to get gmailr working, and it wasn't too bad after a bit of googling and mild confusion. If nobody is currently working on this, I'm happy to write up what I've learned and submit a PR updating the README?

@jtr13
Copy link

jtr13 commented Jan 27, 2022

This is what worked for me today. It's an updated version of https://www.infoworld.com/article/3398701/how-to-send-email-from-r-and-gmail.html by Sharon Machlis. (Thank you Sharon!) Happy to ask students to test and write up more formally somewhere if that's helpful.

  1. Go to https://console.developers.google.com/apis/library

  2. If you have more than one Google account, make sure you’re logged
    into the correct one–check the icon on the top right of the screen.
    It’s a good idea to only be logged into the account that you want to
    use.

  3. Click “Select a project”, “NEW PROJECT”, give it a project name,
    click “Create”. It’s ok if the Location field says “No
    organization.” (Note: if you have other projects, creating a new
    project won’t necessarily move you into the new project, so be sure
    to choose “Select Project” after creating.)

  4. Search for “gmail”, choose Gmail API, and click “Enable”. If you
    don’t see a search option, click “APIs & Services” on the left and
    then “Library”. If it’s already enabled it will say “Manage”.

  5. Click “Create Credentials” then the following:

    • Credential Type: Choose “Gmail API” for Select an API, choose
      “User data”, NEXT

    • OAuth Consent Screen: Choose an App name (I don’t think this
      matters), and a support email and developer contact info (also
      don’t matter afaik), then SAVE AND CONTINUE.

    • Scopes: Click SAVE AND CONTINUE

    • OAuth Client ID: Choose “Desktop app” for the Application Type
      field. Choose any name or leave “Desktop client 1” for the name
      field. Click CREATE. Download the .json file. Click DONE.

  6. Choose the “OAuth consent screen” tab on the left. Click “PUBLISH
    APP” under “Testing”. Click “Confirm”.

Continue with Setup instructions in the README.md starting with “Tell gmailr
where the JSON lives…”

@ThoDuyNguyen
Copy link

ThoDuyNguyen commented Jan 25, 2023

This approach seems not working now. Here is what I got (Client app was set as "Desktop App")

Code

options(
  gargle_oauth_cache = "REMOVE",
  gargle_verbosity = "debug",
  gargle_oauth_email = ""REMOVE""
)

gmailr::gm_auth_configure(path = "/path/to/json")

gmailr::gm_auth(email = "REMOVE")

Output

trying `token_fetch()`
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()`
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
loading token from the cache
no matching token in the cache
initiating new token

The process halt.

image

image

My session

R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] gmailr_1.0.1 gargle_1.2.1

loaded via a namespace (and not attached):
 [1] httr_1.4.4      compiler_4.2.2  magrittr_2.0.3  R6_2.5.1        cli_3.4.1       tools_4.2.2     base64enc_0.1-3 fs_1.5.2        glue_1.6.2      rstudioapi_0.14 lifecycle_1.0.3 rlang_1.0.6  

@superkeyor
Copy link

@ThoDuyNguyen you may also need to specify test users (your own email), and scope (GMail) in OAuth consent screen.

@maelle
Copy link
Contributor

maelle commented Feb 20, 2023

Not for GMail but trackdown has a nice article on setting up an app (for GMail one would "just" use other APIs/scopes) https://claudiozandonella.github.io/trackdown/articles/oauth-app-configuration.html

@jennybc
Copy link
Member Author

jennybc commented Feb 20, 2023

Out-of-band auth has been partially shut down and that appears to play a role in what some people are seeing here (there is now a lot of different stuff reported in this thread). The latest gargle release has more details:

https://gargle.r-lib.org/news/index.html#gargle-130

To remind everyone, gmailr can't use the built-in tidyverse app, because we can't get those scopes approved.

So gmailr users often have to bring their own app and this has gotten noticeably more complicated for those who need out of band auth (OOB), i.e. where R/RStudio is running in the browser (vs. local computer). This is handled by what we now call pseudo-OOB. This requires a client of "web application" type.

These are the basic instruction for getting one's own app:

https://gargle.r-lib.org/articles/get-api-credentials.html#oauth-client-id-and-secret

If one is using a web application client and the pseudo-OOB flow, you'll also need to redirect to a static page that aids with token exchange. This is discussed in the later part of this thread:

r-lib/gargle#202

The short version is that, at least for early experimentation, people can probably use the tidyverse page for exchange. Otherwise, you can serve your own somewhere, using example HTML provided in the gargle package.

If anyone pursues this, I'd love to hear from you, so we can form a more official stance on the callback page and improve the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation good first issue ❤️ good issue for first-time contributors help wanted ❤️ we'd love your help! tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants