datastorm-open / shinymanager

Simple and secure authentification mechanism for single shiny applications.
https://datastorm-open.github.io/shinymanager/
386 stars 79 forks source link

Warning: Error in : 'db' must be a data.frame or a path to a SQLite database #72

Closed plorch closed 3 years ago

plorch commented 3 years ago

When I run the first part of the "Secure Database" example found here: https://datastorm-open.github.io/shinymanager/index.html#secure-database to create the sqlite db and then set up an app using the second part of the example, I get this error: Warning: Error in : 'db' must be a data.frame or a path to a SQLite database

The example works fine if I cut and paste in the whole example, but nothing gets saved. I may be missing something, but to actually use shinymanager, I should not have to create the DB from scratch every time. If I do that, no new users added in admin mode will be saved. Maybe I am missing something.

pvictor commented 3 years ago

Hello,

What are you using in your server ?

plorch commented 3 years ago

Not sure why that matters. Here is the command that creates the db

create_db(
    credentials_data = credentials,
    sqlite_path = "database.sqlite", # will be created
    passphrase = key_get("R-shinymanager-key", "tgwdnpo400C!")
)

So it is created in the local directory for testing. I am testing on windows and As I said, if I run the whole example with creation step, it works. What does not work is if I create the DB and then set up the app and run it separately.

plorch commented 3 years ago

Here is my server block:

server <- function(input, output, session) {
    res_auth <- secure_server(
        check_credentials = check_credentials(
            db = file.path(getwd(), "database.sqlite"),
            passphrase = key_get("R-shinymanager-key", "tgwdnpo400C!")
        )
    )

    output$auth_output <- renderPrint({
        reactiveValuesToList(res_auth)
    })

    output$distPlot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
}
plorch commented 3 years ago

I should also mention that a "database.sqlite" file is created. When I attempt to look at it, it is empty. File size = 0.

The more I think about it, the more I think it might just be that shiny does not have write permission.

plorch commented 3 years ago

I think I have discovered the root of my problem. I am not sure I understand what keys are used when. I just tried using the original example on a mac instead of Windows. When I did this I realized that I may not understand the prompt for a password when you run key_set("R-shinymanager-key", "tgwdnpo400C!") I think when I first set this up I did not use my windows password to add the key. So I think it creates a file but fails to create the database (explaining the File size = 0). Then when it goes looking for that to read or save credentials it sees it is not a sqlite db and I get the error in the subject. It might be worth adding a note that for key_set to run, you will need to enter your keyring (generally your OS) password.

One thing that is puzzling to me is that key_get returns your keyring password, not the one you saved with key_set.

cherif40 commented 3 years ago

@plorch, I have the same issues, you can, please, better clarify the solution to me.

plorch commented 3 years ago

@cherif40 All I can tell you is that for a database to be set up, you need to enter your keyring password for key_set. Beyond that you will have to get help from the developers. I have moved away from using the keyring methods for securing things.

cherif40 commented 3 years ago

@plorch, Thank you very much