Skip to content

Commit

Permalink
add pkgdown site
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulC91 committed Dec 12, 2019
1 parent 8e0de7a commit ea10bfd
Show file tree
Hide file tree
Showing 25 changed files with 2,668 additions and 39 deletions.
7 changes: 5 additions & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
^.*\.Rproj$
^\.Rproj\.user$
^.*\.Rproj$
^\.Rproj\.user$
^_pkgdown\.yml$
^docs$
^pkgdown$
20 changes: 6 additions & 14 deletions R/login.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ loginUI <- function(id, title = "Please log in", user_title = "User Name", pass_
#' a successful login or not. Second element \code{info} will be the data frame provided
#' to the function, filtered to the row matching the succesfully logged in username.
#' When \code{user_auth} is FALSE \code{info} is NULL.
#'
#' @author Paul Campbell, \email{[email protected]}
#'
#' @importFrom rlang :=
#'
Expand Down Expand Up @@ -104,7 +102,7 @@ login <- function(input, output, session, data, user_col, pwd_col, sodium_hashed
# ensure all text columns are character class
data <- dplyr::mutate_if(data, is.factor, as.character)
# if password column hasn't been hashed with sodium, do it for them
if (!sodium_hashed) data <- dplyr::mutate(data, !!pwds := sapply(!!pwds, sodium::password_store))
# if (!sodium_hashed) data <- dplyr::mutate(data, !!pwds := sapply(!!pwds, sodium::password_store))

shiny::observeEvent(input$button, {

Expand All @@ -114,20 +112,14 @@ login <- function(input, output, session, data, user_col, pwd_col, sodium_hashed
if (length(row_username)) {
row_password <- dplyr::filter(data,dplyr::row_number() == row_username)
row_password <- dplyr::pull(row_password, !!pwds)
password_match <- sodium::password_verify(row_password, input$password)
if (sodium_hashed) {
password_match <- sodium::password_verify(row_password, input$password)
} else {
password_match <- identical(row_password, input$password)
}
} else {
password_match <- FALSE
}

# if (hashed) {
# # check for match of hashed input password to hashed password column in data
# row_password <- which(dplyr::pull(data, !! pwds) == digest::digest(input$password, algo = algo))
#
# } else {
# # if passwords are not hashed, hash them with md5 and do the same with the input password
# data <- dplyr::mutate(data, !! pwds := sapply(!! pwds, digest::digest))
# row_password <- which(dplyr::pull(data, !! pwds) == digest::digest(input$password))
# }

# if user name row and password name row are same, credentials are valid
if (length(row_username) == 1 && password_match) {
Expand Down
4 changes: 0 additions & 4 deletions R/logout.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#'
#' @return Shiny UI action button
#'
#' @author Paul Campbell, \email{[email protected]}
#'
#' @export
logoutUI <- function(id, label = "Log out", icon = NULL, class = "btn-danger", style = "color: white;") {
ns <- shiny::NS(id)
Expand All @@ -38,8 +36,6 @@ logoutUI <- function(id, label = "Log out", icon = NULL, class = "btn-danger", s
#' @return The reactive output of this module should be supplied as the \code{log_out} argument to the
#' \link{login} module to trigger the logout process
#'
#' @author Paul Campbell, \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' logout_init <- shiny::callModule(logout, "logout",
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
# shinyauthr

<!-- badges: start -->
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)
<!-- badges: end -->

`shinyauthr` is an R package providing module functions that can be used to add an authentication layer to your shiny apps.

It borrows some code from treysp's [shiny_password](https://github.com/treysp/shiny_password) template with the goal of making implementation simpler for end users and allowing the login/logout UIs to fit easily into any UI framework, including [shinydashboard](https://rstudio.github.io/shinydashboard/). See [live example app here](https://cultureofinsight.shinyapps.io/shinyauthr/) and code in the [inst directory](inst/shiny-examples/shinyauthr_example).

## Installation

```r
devtools::install_github("paulc91/shinyauthr")
remotes::install_github("paulc91/shinyauthr")
```
## Usage

The package provides 2 module functions each with a UI and server element:

- `login`
- `loginUI`
- `logout`
- `logoutUI`
- `login()`
- `loginUI()`
- `logout()`
- `logoutUI()`

Below is a minimal reproducible example of how to use the authentication modules in a shiny app. Note that you must initiate the use of the shinyjs package with `shinyjs::useShinyjs()` in your UI code for this to work appropriately.

Expand All @@ -39,9 +43,9 @@ ui <- fluidPage(
# must turn shinyjs on
shinyjs::useShinyjs(),
# add logout button UI
div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
div(class = "pull-right", logoutUI(id = "logout")),
# add login panel UI function
shinyauthr::loginUI(id = "login"),
loginUI(id = "login"),
# setup table output to show user info after login
tableOutput("user_table")
)
Expand Down Expand Up @@ -131,12 +135,10 @@ I'm not a security professional so cannot guarantee this authentication procedur

I would welcome any feedback on any potential vulnerabilities in the process. I know that apps hosted on a server without an SSL certificate could be open to interception of usernames and passwords submitted by a user. As such I would not recommend the use of shinyauthr without an HTTPS connection.

For apps intended for use within commercial organisations, I would recommend one of RStudio's commercial shiny hosting options with built in authetication.
For apps intended for use within commercial organisations, I would recommend one of RStudio's commercial shiny hosting options, or [shinyproxy](https://www.shinyproxy.io/), both of which have built in authetication options.

However, I hope that having an easy-to-implement open-source shiny authentication option like this will prove useful when alternative options are not feasible.

_Paul Campbell_

_April 2019_


36 changes: 36 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
destination: docs
url:

authors:
Paul Campbell:
href: https://github.com/paulc91

template:
params:
bootswatch: simplex

navbar:
left:
- icon: fa-home fa-lg
href: index.html
- text: Reference
href: reference/index.html
- text: Changelog
href: news/index.html
right:
- icon: fa-github fa-lg
href: https://github.com/paulc91/shinyauthr

reference:
- title: "Login"
desc: >
Login modules
contents:
- login
- loginUI
- title: "Logout"
desc: >
Logout modules
contents:
- logout
- logoutUI
138 changes: 138 additions & 0 deletions docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea10bfd

Please sign in to comment.