See the article Set up an OAuth client for instructions on how to get an OAuth client.
These functions give more control over and visibility into the auth
configuration than gm_auth() does. gm_auth_configure()
lets the user specify their own:
OAuth client, which is used when obtaining a user token.
See the vignette("get-api-credentials", package = "gargle")
for more.
gm_oauth_client() retrieves the currently configured OAuth client.
Usage
gm_auth_configure(client = NULL, path = gm_default_oauth_client())
gm_oauth_client()Arguments
- client
A Google OAuth client, presumably constructed via
gargle::gargle_oauth_client_from_json(). Note, however, that it is preferred to specify the client with JSON, using thepathargument.- path
JSON downloaded from Google Cloud Console, containing a client id and secret, in one of the forms supported for the
txtargument ofjsonlite::fromJSON()(typically, a file path or JSON string).
Value
gm_auth_configure(): An object of R6 class gargle::AuthState, invisibly.gm_oauth_client(): the current user-configured OAuth client.
See also
gm_default_oauth_client() to learn how you can make your OAuth
client easy for gmailr to discover.
Other auth functions:
gm_auth(),
gm_deauth(),
gm_scopes(),
gmailr-configuration
Examples
if (FALSE) { # rlang::is_interactive()
# if your OAuth client can be auto-discovered (see ?gm_default_oauth_client),
# you don't need to provide anything!
gm_auth_configure()
}
# see and store the current user-configured OAuth client
(original_client <- gm_oauth_client())
#> NULL
# the preferred way to configure your own client is via a JSON file
# downloaded from Google Developers Console
# this example JSON is indicative, but fake
path_to_json <- system.file(
"extdata", "client_secret_installed.googleusercontent.com.json",
package = "gargle"
)
gm_auth_configure(path = path_to_json)
# confirm that a (fake) OAuth client is now configured
gm_oauth_client()
#> <gargle_oauth_client>
#> name: a_project_59aa1797ab7ac4667a77617c3400999c
#> id: abc.apps.googleusercontent.com
#> secret: <REDACTED>
#> type: installed
#> redirect_uris: http://localhost
# restore original auth config
gm_auth_configure(client = original_client)