R/viewer-based-credentials.R
connect_viewer_token.RdRequest an OAuth access token for a third-party resource belonging to the user associated with a given Shiny session. This works by exchanging a short-lived session credential for OAuth tokens issued to the client managed by the Connect server, without the Shiny app in question having to manage the user's authentication flow (or the associated client credentials) itself.
connect_viewer_token(
resource = NULL,
scope = NULL,
session = get_connect_session(),
server_url = Sys.getenv("CONNECT_SERVER"),
api_key = Sys.getenv("CONNECT_API_KEY")
)
has_viewer_token(..., session = get_connect_session())The URI that identifies the resource that the client is trying to access, if applicable.
Scopes to be requested from the resource owner.
A Shiny session object. By default, this grabs the Shiny session of the parent environment (if any), provided we are also running on Connect.
The Connect server to exchange credentials with. Defaults
to the value of the CONNECT_SERVER environment variable, which is set
automatically when running on Connect.
An API key for the Connect server. Defaults to the value of
the CONNECT_API_KEY environment variable, which is set automatically when
running on Connect.
Further arguments passed on to connect_viewer_token().
connect_viewer_token() returns an httr2::oauth_token.
has_viewer_token() returns TRUE if the session has a viewer
token and FALSE otherwise.
connect_viewer_token() handles caching automatically.
token <- "default-token"
if (has_viewer_token()) {
token <- connect_viewer_token()
}