简体   繁体   中英

Multi-user authentication for googlesheets on an app deployed to shinyapps.io

I have an interactive shiny app which wants to read and write to a user's own Google Drive account. It is using gs4_create , gs4_find and range_read from packages googlesheets4 and googledrive .

When run locally, I get a prompt like this on first usage for each of these packages in turn through the console:

The googledrive package is requesting access to your Google account. Select a pre-authorised account or enter '0' to obtain a new token. Press Esc/Ctrl + C to abort

1: notmyemail@gmail.com

I can just select my gmail account or enter 0 to open the "Choose an account to continue to Tidyverse API Packages" GUI in the browser. Both methods work to (OAuth) authenticate the user and the functions work just fine.

When I deploy the app to shinyapps.io it throws an error on first usage of these functions without even requesting credentials:

Error in value[3L]: 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. Read more in: https://gargle.r-lib.org/articles/non-interactive-auth.html

Obviously, I'm not looking for a console request on the deployed app, but what I think I need is to get the Tidyverse API GUI to trigger (which I assume is the intended behaviour) and enable a user to authenticate their account?

Note that (i) this app is interactive, (ii) the user is seeking to access private files on their own Google Drive, not a communal or public file. For both reasons, I cannot just supply a token.

The documentation for drive_auth_config states that I could set up my own OAuth app to authenticate, but is this necessary?

Any ideas? Thanks.

You app requires credentials to access your enabled API scopes. And also users using your app first need to be authenticated before they give consent to your app to access APIs on their behalf. This means your app should have a consent screen to present to your users, in which it shows which API scopes it is asking permission for.

If you have not set it up correctly, including redirect urls, which in case of an app being deployed on a webserver, the redirection should not be localhost.

So it is important you correctly set up both the consent screen for your project and use the right credentials for it.

I recommed you read through the following documentation to get a better understanding of how to set up authentication for your app.

References:

I enquired on github and the developer of the googlesheets4 package, responded that multi-user authentication in shiny is not yet implemented. The issue is being tracked here: https://github.com/r-lib/gargle/issues/14

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM