connectcreds
provides low-level utilities for Shiny
developers and R package authors building tools that make use of Posit
Connect’s viewer-based
credentials.
You can install connectcreds from CRAN with:
install.packages("connectcreds")
Or, install the development version of connectcreds from GitHub with:
# install.packages("pak")
::pak("posit-dev/connectcreds") pak
connectcreds
includes helper functions for implementing
Posit Connect’s viewer-based credentials in Shiny applications. These
helpers are meant to be called in the context of a Shiny server
function, as follows:
<- function(input, output, session) {
server <- "PAT for local development"
token if (connectcreds::has_viewer_token()) {
<- connectcreds::connect_viewer_token()
token
}
# ...
}
Usually, though, these helpers will be used internally by packages
that authenticate with various services. For example, here is a
simplified version of gh::gh_token()
that returns a GitHub
OAuth token for the viewer on Connect but uses a GitHub personal access
token when testing locally:
<- function() {
gh_token ::check_installed("connectcreds", "for viewer-based authentication")
rlangif (connectcreds::has_viewer_token("https://github.com")) {
<- connectcreds::connect_viewer_token("https://github.com")
token return(token$access_token)
}Sys.getenv("GITHUB_PAT")
}
<- function(input, output, session) {
server # A Shiny output that shows the user's GitHub username:
$gh_handle <- renderText({
output<- gh::gh_whoami(.token = gh_token())
resp $login
resp
})
# ...
}
MIT (c) Posit Software, PBC