Skip to content

Bringing Posit Connect's viewer-based credentials to R

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

posit-dev/connectcreds

Repository files navigation

connectcreds

lifecycle R-CMD-check

connectcreds provides low-level utilities for Shiny developers and R package authors building tools that make use of Posit Connect’s viewer-based credentials.

Installation

You can install the development version of connectcreds from GitHub with:

# install.packages("pak")
pak::pak("posit-dev/connectcreds")

Usage

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:

server <- function(input, output, session) {
  token <- "PAT for local development"
  if (connectcreds::has_viewer_token(session)) {
    token <- connectcreds::connect_viewer_token(session)
  }

  # ...
}

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:

gh_token <- function(session = NULL) {
  if (!is.null(session)) {
    rlang::check_installed("connectcreds", "for viewer-based authentication")
    if (connectcreds::has_viewer_token(session, "https://github.com")) {
      token <- connectcreds::connect_viewer_token(session, "https://github.com")
      return(token)
    }
  }
  Sys.getenv("GITHUB_PAT")
}

server <- function(input, output, session) {
  # A Shiny output that shows the user's GitHub username:
  output$gh_handle <- renderText({
    resp <- gh::gh_whoami(.token = gh_token(session = session))
    resp$login
  })

  # ...
}

License

MIT (c) Posit Software, PBC

About

Bringing Posit Connect's viewer-based credentials to R

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages