R/lockWidget.R

#' Auth0 lock authentication wrapper
#'
#' Auth0 is an 'authentication as a service' provider. with an account in https://auth0.com
#' is is possible to easily insert lock (https://auth0.com/lock) in a shiny app.
#'
#'
#' @section Auth0 account:
#' this is just a test to see how it looks like
#'
#' @section Options content:
#' There are a number of configuration options, detailed in
#' https://auth0.com/docs/libraries/lock/v11/configuration.
#'
#'\describe{
#'   \item{allowAutocomplete}{(First item)}
#'   \item{allowShowPassword}{(vector): this is a test}
#'   \item{languageDictionary}{(List)}
#'   \item{closable}{(Boolean)}
#'   \item{container}{(String)}
#'   \item{rememberLastLogin}{(Boolean)}
#'   \item{logo}{(String) Path to the image to display.}
#'   \item{primaryColor}{(String)}
#'   \item{labeledSubmitButton}{(Boolean)}
#'   \item{sso}{(Boolean)}
#'   \item{additionalSignUpFields}{(List)}
#'   \item{allowLogin}{(Boolean)}
#'   \item{allowForgotPassword}{(Boolean)}
#'   \item{allowSignUp}{(Boolean)}
#'   \item{initialScreen}{(String)}
#'   \item{prefill}{(List)}
#' }
#'
#'@param elementId Id of the authentication object.
#'@param clientId Client ID oof Auth0 account (see relevant section below).
#'@param auth0Domain Auth0 domain (see relevant section below).
#'@param width Is this useless?
#'@param height Is this useless?
#'@param options List with settings to Auth0 lock (see relevant section below).
#'
#'@import htmlwidgets
#'
#'@export
lockWidget <- function(elementId = NULL,
                       clientId = Sys.getenv("CLIENT_ID"),
                       auth0Domain = Sys.getenv("AUTH0_DOMAIN"),
                       width = NULL,
                       height = NULL,
                       options = NULL
)
{


  stopifnot(is.character(elementId))

  # forward options using x
  x <-  list(
    elementId = elementId,
    clientId = clientId,
    auth0Domain = auth0Domain,
    settings = options
  )

  # create widget
  htmlwidgets::createWidget(
    name = 'lockWidget',
    x,
    width = width,
    height = height,
    package = 'lockr',
    elementId = elementId
  )
}

#' Shiny bindings for lockWidget
#'
#' Output and render functions for using lockWidget within Shiny
#' applications and interactive Rmd documents.
#'
#' @param outputId output variable to read from
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
#'   \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
#'   string and have \code{'px'} appended.
#' @param expr An expression that generates a lockWidget
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#'   is useful if you want to save an expression in a variable.
#'
#' @name lockWidget-shiny
#'
#' @export
lockWidgetOutput <- function(outputId, width = '100%', height = '400px'){
  htmlwidgets::shinyWidgetOutput(outputId, 'lockWidget', width, height, package = 'lockr')
}

#' @rdname lockWidget-shiny
#' @export
renderLockWidget <- function(expr, env = parent.frame(), quoted = FALSE) {
  if (!quoted) { expr <- substitute(expr) } # force quoted
  htmlwidgets::shinyRenderWidget(expr, lockWidgetOutput, env, quoted = TRUE)
}
cvmartin/lockr documentation built on May 26, 2019, 6:34 a.m.