connect_viewer_token {connectcreds}R Documentation

Viewer-based credentials on Posit Connect

Description

Request 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.

Usage

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())

Arguments

resource

The URI that identifies the resource that the client is trying to access, if applicable.

scope

Scopes to be requested from the resource owner.

session

A Shiny session object. By default, this grabs the Shiny session of the parent environment (if any), provided we are also running on Connect.

server_url

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.

api_key

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().

Details

connect_viewer_token() handles caching automatically.

Value

connect_viewer_token() returns an httr2::oauth_token.

has_viewer_token() returns TRUE if the session has a viewer token and FALSE otherwise.

Examples

token <- "default-token"
if (has_viewer_token()) {
  token <- connect_viewer_token()
}

[Package connectcreds version 0.1.0 Index]