shiny does not have a mechanism for logging in users, so this level of app personalization is not possible using standard
shiny. However, using the
googleAuth module we allow app content to be made conditionally available to 3 classes of user:
This module presents the user a “Login” button which redirects to a Google authentication page. After authenticating, an OAuth token (user- and session-specific) is used by the app to determine the user’s Google email address, display name, and whether they are on the app’s access-control whitelist.
This has the advantage of using Google for access control management rather than locally on the shiny server.
In order to use this module for authentication, your app must:
This vignette explains how to do these.
Make sure that you are logged into Google and visit the Google APIs project page.
Go to the project dropdown menu, and create a new project:
Complete the setup, and after a few seconds, you will be redirected to the Google API manager.
The information you provide in this tab populate the authentication screen that pops up when users click the “Login with Google” link in your app (example).
From the “Create Credentials” dropdown menu, select “OAuth client ID” and select “Web application”" for the application type. Fill in any descriptive name for this client, and in the URLs field add the URL to your app (e.g.,
http://youApp.example.com). To facilitate testing, also add URLs for
http://127.0.0.1:5621 (for use with
shiny::runApp(..., port = 5621), and
http://127.0.0.1:3838 (for use with shiny-server running on port 3838).
The authentication mechanism used by the
googleAuth module relies on the file permissions set on a file in Google Drive. Simply create a blank text file (e.g., name_of_your_app.txt) in Google Drive and edit the access control settings to allow only authorized users to download/view this file. You will need the private URL (link) to this file. Assign this URL to a variable in your
global.R and pass that as the
authFile argument when calling the
authGoogle module (see below).