Code Monkey home page Code Monkey logo

firebase's Introduction

Google Firebase for shiny, built with packer.

Lifecycle: stable R-CMD-check packer

Website | Demo | Get Started

Authentication Methods

Currently the following methods from Google Firebase are available in the package:

  • Email & Password
  • Email Link
  • Google
  • Github
  • Facebook
  • Twitter
  • Microsoft
  • Yahoo!
  • Phone

Example

An application that provides authentication could look like this.

library(shiny)
library(firebase)

ui <- fluidPage(
  useFirebase(), # import dependencies,
  firebaseUIContainer()
)

server <- function(input, output){
  f <- FirebaseUI$
    new()$ # instantiate
    set_providers( # define providers
      email = TRUE, 
      google = TRUE
    )$
    launch() # launch
}

shinyApp(ui, server)

Install

Install the stable version from CRAN:

install.packages("firebase")

Install the development from Github using remotes:

# install.packages("remotes")
remotes::install_github("JohnCoene/firebase")

Get the current bleeding edge refactor with webpack with packer to improve performances and use firebase JavaScript version 9. It also includes two new classes Storage and Analytics.

remotes::install_github("JohnCoene/firebase@packer")

Related

Below are similar projects:

Code of Conduct

Please note that the firebase project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

firebase's People

Contributors

dependabot[bot] avatar itkonen avatar johncoene avatar munoztd0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

firebase's Issues

Feature request: a way to not load the UI until after logging in

I'm not sure how, or if it's possible, but the current way of requiring all content to use either f$req_sign_in() or reqSignin() seems like it would get tedious and very verbose very fast. It would be good to have bypass that, like how RStudio's authentication and {auth0} really don't load the UI until it's safe to do so

Microsoft Docs client secret

hello,

Just FYI, I succeed in using microsoft AAD with your package (thanks btw for the amazing work !) ,

BUT I spend 3 hours to figure out that what I needed was the "Value" and not the "Secret ID" for the client secret that needs to be inputed to firebase.

image

So I just let it here in case people run into the same thing or maybe if you want to update the https://firebase.john-coene.com/auth/oauth-providers/ for new arrivers.

Anyway thanks again!

Blank page for example

The example below returns a blank white page in Chrome.

I see this error in the Chrome console:

Failed to load resource: the server responded with a status of 404 (Not Found)

library(shiny)
library(firebase)

ui <- fluidPage(
  useFirebase(), # import dependencies,
  firebaseUIContainer()
)

server <- function(input, output){
  f <- FirebaseUI$
    new()$ # instantiate
    set_providers( # define providers
      email = TRUE, 
      google = TRUE
    )$
    launch() # launch
}

shinyApp(ui, server)

persistence error

I made a bunch of changes to an app and an error popped up in Chrome console -- something about persistent state...

The error went away when I changed this:

f <- FirebaseUI$new(persistence = "local")$set_providers()

to

f <- FirebaseUI$new()$set_providers()

My old version worked with persistence = "local" and that's the way I'd prefer things to work.

The one other major change is that I had an app within an app (double iframes), so the problem may have had something to do with that.

Can you confirm that persistence = "local" is working as expected? Sorry, I've no time to create a MWE of my problem.

Thanks

UI allows registration, but not sign in

Hello,

Thank you for this package (and all the others!), and apologies if this is not the correct venue for this. I have followed the demo application provided in the documentation and a few variations of it, but I continue to experience the same problem:

  1. The shiny app launches with the basic UI
  2. There is only the option to register a new user -- not for an already registered user to login
  3. New users who register experience the app as intended. Pre-existing users who attempt to register again with the same email are greeted with this message:

This email already exists without any means of sign-in.

Any idea what is going on here? Below is the code I'm using. You can also experience it in the shiny app on shinyapps.io. firebase 1.0.2 (tried with 1.0.0 also), R 4.2.0, shiny 1.7.5 and 1.7.3.

library(firebase)

ui <- fluidPage(
  useFirebase(),
  firebaseUIContainer(),
  reqSignin(actionButton("signout", "Sign out")),
  uiOutput("msg"),
  plotOutput("plot")
)

server <- function(input, output){
  f <- FirebaseUI$
    new()$ # instantiate
    set_providers( # define providers
      email = TRUE,
      google = TRUE
    )

  observe({
    launch() # launch
  })
}

shinyApp(ui, server)

any help is greatly appreciated!

Specify Microsoft tenant when authenticating with Microsoft AAD

Hi John,

I have an app registration set up on portal.azure.com where I want to only allow users in my organisation's tenant to be able to log into my R Shiny app.

Firebase seems to launch the sign-in popup/redirect with the common/ endpoint by default. I can't seem to find where to change this to use my organisations tenant id.

image

This provides me with an error stating that Usage of the /common endpoint is not supported for such applications created after '10/15/2018'. Use a tenant-specific endpoint or configure the application to be multi-tenant.

Following along the firebase docs for microsoft-oauth I see that after you define a provider

`import { OAuthProvider } from "firebase/auth";

const provider = new OAuthProvider('microsoft.com');`

you can then add custom parameters, such as TENANT_ID.

provider.setCustomParameters({
  // Optional "tenant" parameter in case you are using an Azure AD tenant.
  // eg. '8eaef023-2b34-4da1-9baa-8bc8c9d6a490' or 'contoso.onmicrosoft.com'
  // or "common" for tenant-independent tokens.
  // The default value is "common".
  tenant: 'TENANT_ID'
});

I can't seem to find where I can specify the tenant ID in the docs / code in https://firebase.john-coene.com/.

I know that this probably the file where this addition/edit should be made: JohnCoene/firebase/blob/master/srcjs/components/oauth.js after this block of code.

Can you advise, am I missing some obvious way of achieving this - or has this functionality yet to be added to the JohnCoene/firebase R package on CRAN?

Thank you very much - great package!

Something is wrong, but I don't know what

Just a heads up that it looks like firebase is currently acting differently than it was a few hours ago. I'm digging to figure out what is going on, but so far my guess is that the values or type of values returned from f$get_signed_in()$response are now different.

The problem does not appear when running a shiny app locally, but rather just on shinyapps.io.

I'll post more when I know more!

Access via JS

Thanks for this great package. I am trying to access it via JS as I am using it in Rmarkdown. The code below works ( it hides elements when user is logged out). But it does not work when I want to show elements after user is logged in. To show I am using fireblaze__requires__signin and .show( )

Won't install on R 4.3

I get this error when I try to install:

install.packages("firebase")
Warning in install.packages :
  packagefirebaseis not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
> R.Version()
$platform
[1] "aarch64-apple-darwin20"

$arch
[1] "aarch64"

$os
[1] "darwin20"

$system
[1] "aarch64, darwin20"

$status
[1] ""

$major
[1] "4"

$minor
[1] "3.0"

$year
[1] "2023"

$month
[1] "04"

$day
[1] "21"

$`svn rev`
[1] "84292"

$language
[1] "R"

$version.string
[1] "R version 4.3.0 (2023-04-21)"

$nickname
[1] "Already Tomorrow"

firebaseUIContainer() does not show up in modal after sign out

This is based on the example in the documentation: https://firebase.john-coene.com/auth/social/

Goal

Display login buttons in a modal

Issue

The login buttons show up in a modal when signing in the first time. But when you sign out, the modal shows up without the firebaseUIContainer(). However, after a refresh, the login buttons appear in the modal.

What is preventing the firebaseUIContainer() to show up?

Here's the modified code from the example:

library(shiny)
library(firebase)

# define signin
signin <- modalDialog(
  title = "Login",
  firebaseUIContainer(),
  footer = NULL
)

ui <- fluidPage(
  useFirebase(),
  plotOutput("plot"),
  uiOutput("sign_out_button")
)

server <- function(input, output) {
  showModal(signin)
  
  f <- FirebaseUI$new(persistence = "local")$set_providers(
    email = TRUE,
    google = TRUE)$launch()
  

  observe({
    f$req_sign_in()
    removeModal()
  })
  
  output$plot <- renderPlot({
    f$req_sign_in()
    plot(cars)
  })
  
  ## Button for signing out
  output$sign_out_button <- shiny::renderUI({
    f$req_sign_in()
    actionButton("signout", "Sign out")
  })
  

  observeEvent(input$signout, {
    f$sign_out()
    showModal(signin)
  })
}

shinyApp(ui, server)

Manage Users - Re-auth example

Hey there,

First, thanks for the package!

I maybe just found a little issue with one of the examples you had here (https://firebase.john-coene.com/articles/manage.html) on your Manage Users page:

`f <- FirebaseEmailPassword$new()
observeEvent(input$reAuth, {
f$re_authenticate(input$reAuthPassword)
})

observeEvent(input$get_re_authenticated(), {
reauth <- input$get_re_authenticated()
print(reauth$success)
})`

Shouldn't input$get_re_authenticated() be replaced by f$get_re_authenticated()?

Thanks!

Microsoft accessToken returned after sign-in returns 401 error when used for Microsoft Graph API

Hey John,

According to the firebase docs, you should be able to query Microsoft's Graph API with the access token retrieved after sign-in.

However, when I try to query Microsoft's Graph API with the accessToken that is returned with get_signed_in()$response$stsTokenManager$accessToken, I get a 401 error with the following message informing me that the Required claim nbf not present in token.

I have tried a couple of different approaches such as manually adding the nbf claim, however this is still unsuccessful.

I have also successfully retrieved the accessToken using the AzureAuth package AzureAuth::get_azure_token() outside of my Shiny web app environment. I can successfully query the Graph API with this token. When I compare both tokens using https://jwt.ms/, I see this token has the nbf claim and a bunch of other additional claims.

Because I can successfully retrieve the token using AzureAuth::get_azure_token(), I am confident that my app registration is set up correctly and the issue may be caused on the firebase side.

I also note another firebase user posted a similar issue on StackOverflow, where they were attempting to use the accessToken they retrieved from signing in via the signInWithPopup method of authentication and also getting a 401 from the Graph API. Therefore, I'm not sure if the issue lies with the firebase package itself rather than your R package, or if it is something I am doing incorrectly.

Thanks again for a great package!

Error `Signture issued at time is in the future`

Hi,

I'm working on a rather shinyApp which involves a firebase login.
Until most recently, the app was working but, potentially since upgrading to Windows 11, I am getting this error in the console:

Signture issued at time is in the future

The elements that load with reqSignin do load, but the ones that use f$req_sign_in() do not.

What could this error be referring to?
What could be causing it?

For context, I am testing the same app on the windows machine where its throwing this error and on a Mac where no error is thrown and the app works as expected.

I was able to reproduce this in a smaller shinyapp:


library(shiny)
library(firebase)

Sys.setenv(FIREBASE_API_KEY = "xxx")
Sys.setenv(FIREBASE_PROJECT_ID = "xxx")
Sys.setenv(FIREBASE_AUTH_DOMAIN = "xxx")
Sys.setenv(FIREBASE_APP_ID = "xxx")
Sys.setenv(FIREBASE_STORAGE_BUCKET = "xxx")

ui <- fluidPage(
  useFirebase(), # import dependencies
  firebaseUIContainer(),
  reqSignin(
    h1('Hello')
  ),
  uiOutput("test")
  
)

server <- function(input, output){
  f <- FirebaseUI$
    new()$ # instantiate
    set_providers( # define providers
      email = TRUE, 
      google = TRUE
    )$
    launch() # launch
  
  output$test = renderUI({
    
    f$req_sign_in()
    
    h1("World")
    
  })
  
}

shinyApp(ui, server)
> sessionInfo()

R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default


locale:
[1] LC_COLLATE=English_United Kingdom.utf8 
[2] LC_CTYPE=English_United Kingdom.utf8   
[3] LC_MONETARY=English_United Kingdom.utf8
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.utf8    

time zone: Europe/Berlin
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.5     miniUI_0.1.1.1     dplyr_1.1.2       
 [4] compiler_4.3.1     promises_1.2.0.1   tidyselect_1.2.0  
 [7] Rcpp_1.0.10        stringr_1.5.0      jquerylib_0.1.4   
[10] later_1.3.1        fastmap_1.1.1      mime_0.12         
[13] plyr_1.8.8         R6_2.5.1           shinyjs_2.1.0     
[16] generics_0.1.3     colourpicker_1.2.0 htmlwidgets_1.6.2 
[19] tibble_3.2.1       shiny_1.7.4.1      bslib_0.5.0       
[22] pillar_1.9.0       rlang_1.1.1        DT_0.28           
[25] utf8_1.2.3         stringi_1.7.12     cachem_1.0.8      
[28] httpuv_1.6.11      fs_1.6.2           sass_0.4.6        
[31] cli_3.6.1          magrittr_2.0.3     shinyWidgets_0.7.6
[34] digest_0.6.32      rstudioapi_0.15.0  xtable_1.8-4      
[37] lifecycle_1.0.3    vctrs_0.6.3        gargle_1.5.1      
[40] glue_1.6.2         googledrive_2.1.1  fansi_1.0.4       
[43] reshape2_1.4.4     purrr_1.0.1        tools_4.3.1       
[46] pkgconfig_2.0.3    ellipsis_0.3.2     htmltools_0.5.5 

hello shinyapp hello shinyapp error

Thank you!!

P.S. there is a typo in the word signature.

Wordpress connection

Hi there,

I'm using firebase on my website. I have a button to redirect user to my shinyapp.

My problem is, user should login two time, 1. in website, 2. in app.

I wonder that is there any way to user login ones?

Thank you!

Clarification on use of `interactive` needed

Background Info

I was going through the source code and stumbled upon this:
image
Link: https://github.com/JohnCoene/firebase/blob/b72e8847191d7826f0bfd204409682581cd8251e/R/class-auth.R#L280C25-L280C25

if (interactive) is used instead of the expected if (interactive()). I can't find any explicit definition for interactive as a variable.
This pattern is repeated multiple times so I'd assume it's not a bug.

Question

Is this a unique R feature or am I overlooking something?

Expectation

My expectation of if (interactive) is that it should throw an error since interactive is a function, not a logical. And, indeed, it is what happens in my reprex below:

check_interactive_mode <- \() {
  if (interactive) {
    print("This is an interactive session")
  } else {
    print("This is a non-interactive session")
  }
}

check_interactive_mode()
#> Error in if (interactive) {: argument is not interpretable as logical

Created on 2023-12-13 with reprex v2.0.2

How to migrate to the new version?

I've got an existing app that uses firebase. After upgrading firebase to 1.0, the firebase stuff doesn't work (e.g., no providers are shown). I saw a message to use firebaseUIContainer, but switching that for useFirebaseUI didn't work.

I can try to create repro's of my specific issues, but I'm wondering if there are any obvious steps needed to upgrade to 1.0.

Thanks for the library!

ERR_HTTP_RESPONSE_CODE_FAILURE

Thanks for this great package.

The following error messages appear in console when firebase package gets loaded.

DevTools failed to load SourceMap: Could not load content for http://127.0.0.1:5610/firebase/js/firebase-app.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
DevTools failed to load SourceMap: Could not load content for http://127.0.0.1:5610/firebase/js/firebase-auth.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
DevTools failed to load SourceMap: Could not load content for http://127.0.0.1:5610/firebase/js/firebase-analytics.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

Firebase in module not working

Hi John,

Seems to me Firebase is not working properly in Shiny modules. See below. If I create the Firebase object outside the module and pass it as argument it seems to work. Or am I doing something wrong?

Ivo

library(shiny)
library(firebase)

FirebaseEmailPasswordUI <- function(id) {
    ns <- NS(id)
    tagList(
        textInput(ns("email"), "Your email"),
        passwordInput(ns("password"), "Your password"),
        actionButton(ns("create"), "Register"),
        actionButton(ns("signin"), "Signin"),
        plotOutput(ns("plot"))
    )
}
 
FirebaseEmailPasswordServer <- function(id, f) {
    moduleServer(
        id,
        function(input, output, session) 
        {
            ns <- session$ns
            if(is.null(f)) f <- FirebaseEmailPassword$new()
            
            ## create the user
            observeEvent(input$create, {
                cat("Registering on FireBase server...\n")
                f$create(input$email, input$password)
            })
            
            ## check if creation sucessful
            observeEvent(f$get_created(), {
                created <- f$get_created()                
                if(created$success){
                    showNotification("Account created!", type = "message")
                } else {
                    showNotification("Error!", type = "error")
                }
                ## print results to the console
                print(created)
            })
            
            observeEvent(input$signin, {
                cat("Signing-in on FireBase server...\n")        
                f$sign_in(input$email, input$password)
            })
            
            output$plot <- renderPlot({
                f$req_sign_in()                      
                plot(cars)
            })
            
            observeEvent(f$get_signed_in(), {
                ## do something
                signed <- f$get_signed_in()
                user  <- signed$response$displayName
                email <- signed$response$email
                if(signed$success) {
                    showModal(modalDialog(paste("Hello",user,"!")))
                }
                
            })        
        }
    )
}

ui <- fluidPage(
    useFirebase(), # import dependencies
    FirebaseEmailPasswordUI("fire123")    
)

server <- function(input, output) {
    f <- NULL
    ##f <- FirebaseEmailPassword$new()
    FirebaseEmailPasswordServer("fire123", f)
}

shinyApp(ui, server)

including a reactable output breaks firebase storage

Super random error but it seems that including a reactable::reactableOutput breaks the firebase storage.. like all my queries just return as failed. Take the reactable output away and they work again. I am 100% sure this is the reason after an hour or narrowing it down. No idea why right now... just wanted to document this for others.

Error in private$.namespace

I'm completely unable to get any of the documentation examples to work. Shiny loads and appears to think I'm already logged in; even on first launch the only UI I see is the "Sign out" action button. I've tried on different machines, new Google firebase account, config file vs environ vars, but absolutely nothing works. Same results whether I use CRAN version or ‘1.0.0.9000’

One clue. I wonder why do I get this message

> f <- FirebaseUI
> f$new()$set_providers(email=TRUE, google=TRUE)
ℹ Fetching firebase config from environment variables
Error in private$.namespace(session) : attempt to apply non-function

Error : Cannot find configuration file, see `firebase_config` even if I set the environment variables.

Sys.setenv(FIREBASE_API_KEY="xxx")
Sys.setenv(FIREBASE_PROJECT_ID="xxx")
Sys.setenv(FIREBASE_AUTH_DOMAIN="xxx")
Sys.setenv(FIREBASE_APP_ID="xxxx")
Sys.setenv(FIREBASE_STORAGE_BUCKET="xxx")
Sys.setenv(FIREBASE_STORAGE_BUCKET="xxx")

library(shiny)
library(firebase)

ui <- fluidPage(
  useFirebase(), # import dependencies
  firebaseUIContainer(),
  plotOutput("plot")
)

server <- function(input, output){
  f <- FirebaseUI$
    new()$ # instantiate
    set_providers( # define providers
      email = TRUE, 
      google = TRUE
    )$
    launch() # launch

  output$plot <- renderPlot({
    f$req_sign_in() # require sign in
    plot(cars)
  })
}

shinyApp(ui, server)

I want to build a shiny app that uses Firebase authentication. However i dont want to use config file since its not secure to do so. So, I set environment variables as instructed in the documentation (https://firebase.john-coene.com/guide/config/) . However when i run the above code, i still get the Error : Cannot find configuration file, see `firebase_config error.

Enhancement - f$req_sign_in() which can apply to the whole app

Hey, this package is great.

One thing I am trying to have is a separate modal box which has to be completed before showing the rest of the app. I can see there is this approach can be applied to individual plots, e.g.

output$plot <- renderPlot({
f$req_sign_in()
plot(cars)
})

is it possible instead to apply this to the whole shiny app? It could be a useful feature for larger apps.

Thanks, P.

How to embed it in other page frame?(e.g. bs4dash)

I try the code below,but it dosen't work.

library(bs4Dash)
library(shiny)
library(firebase)

ui <- bs4DashPage(
  useFirebase(),
  useFirebaseUI(),
  title = "test",
  navbar = bs4DashNavbar(),
  sidebar = bs4DashSidebar(
    skin = "light",
    title = "test"),
  controlbar = bs4DashControlbar(),
  footer = bs4DashFooter(),
  body = bs4DashBody()
)

server <- function(input, output, session) {
  f <- FirebaseUI$
    new("session")$ # instantiate
    set_providers( # define providers
      email = TRUE, 
      google = TRUE
    )$
    launch() # launch
}

shinyApp(ui, server)

I try another way, it dosen't work either.

ui <- fluidPage(
  useFirebase(),
  useFirebaseUI(),
  reqSignin(bs4DashPage(
    title = "test",
    navbar = bs4DashNavbar(),
    sidebar = bs4DashSidebar(
      skin = "light",
      title = "test"),
    controlbar = bs4DashControlbar(),
    footer = bs4DashFooter(),
    body = bs4DashBody()
  )))

Using Firebase with Prerendered Shiny Documents

Context on Prerendered Shiny Documents

I have a lightweight app that I've created using Prerendered Shiny Documents. From my understanding of how this works, you specify code normally placed in a ui.R file in a chunk with context="render"
and code normally placed in a server.R file in a chunk with context="server"}

Integrating Firebase with Prerendered Shiny Documents

Using the most basic Firebase app example from John Coene's documentation, I try to specify the ui and server components in the prerendered Shiny document format as described above (see Reprex). The problem is I'm not seeing the authentication modal pop up with email and Google sign-in options. Any insights would be appreciated!

Reprex (copy in between quotes)

"```{r setup, include=FALSE, context="setup"}
library(shiny)
library(firebase)


"```{r, echo=FALSE, context="render"}
useFirebase()
firebaseUIContainer()
reqSignin(h4("Logged in!"))
```"

"```{r, context="server"}
FirebaseUI$
    new()$ # instantiate
    set_providers( # define providers
      email = TRUE, 
      google = TRUE
    )$
    launch() # launch

What I see when I render document

Screenshot 2023-04-16 at 9 08 46 PM

Cannot download through remotes::install_github

Hi, I know this project is no longer in CRAN since it is not maintained.

But I am unable to download this from remotes::install_github as well

> remotes::install_github("JohnCoene/firebase")
Downloading GitHub repo JohnCoene/firebase@HEAD
Error in utils::download.file(url, path, method = method, quiet = quiet,  : 
  download from 'https://api.github.com/repos/JohnCoene/firebase/tarball/HEAD' failed

I reproduced the error on my coworker's machine as well.

Work with Shiny Server

Hello,

I am trying to get this to work with an application hosted on Shiny Server. I host my application in the standard /svr/shiny-server/ location under a subdirectory called svr/shiny-server/prod.

When I follow the basic authentication example (the one that just uses a very simple email and Google sign-in), I just get a blank page. However, I know something is working because in my Shiny logs, I see the warning message about terms of service. If it means anything, my firebase.rds file is located in the same directory as my app.R (that is, /svr/shiny-server/prod/firebase.rds).

I can not seem to figure out why I can't get the Firebase log in to show. Any ideas? Could it have anything to do with needing to specify the auth_domain argument for the firebase_config function?

f$get_signed_in() now returns $response not $user as documented

The print for the below code:

 output$msg <- renderUI({
    f$req_sign_in() # require sign in

    user <- f$get_signed_in() # get logged in user info
    print(user)

    h4("Welcome,", user$response$displayName)
  })

is

$success
[1] TRUE

$response
$response$uid
[1] "XXXX"

$response$displayName
[1] "Mark Edmondson"
...

but the documentation on https://firebase.john-coene.com/articles/manage.html states:

#> $signed_in
#> [1] TRUE
#> 
#> $user
#> $user$uid
#> [1] "XXxxX"
#> 
#> $user$displayName
#> [1] "John"
...

which led to some confusion :)

Enhancement: support upload of data objects

Currently seems like only files can be uploaded since 'data_url' is passed to the uploadString function from firebase SDK. This could be handled by using uploadBytes or by setting the file type argument to 'base64' instead of 'data_url'. The major question here would be how to best convert a dataframe to a bytestring... guessing that's not so hard.

Reference: https://firebase.google.com/docs/storage/web/upload-files

My current solution is to just write the data to a temp file before upload and then delete it afterwards, but that's not ideal. I may tackle this and submit a pr if it really becomes an issue.

Sign out button disappears for a gmail user with bslib version 0.5.1

I am not sure if this needs work from bslib or firebase but reporting here. My app server contains the regular firebase code for signing out, and the email and google login options:

server <- function(input, output, session) {

  # Firebase authentication ---------------------------------------------------
  f <- FirebaseUI$new(persistence = "local")$set_providers(
    email = TRUE,
    google = TRUE)$launch()

  # Sign out ----------------------------------------------------------------
  ## Button for signing out
  output$sign_out_button <- shiny::renderUI({
    f$req_sign_in()
    actionButton("signout", "Sign out")
  })

  ## User signs out when the button with ID "signout" is clicked
  observeEvent(input$signout, {
    f$sign_out()
  })
}

The sign out button does not appear if signed in with google. But it does appear if signed in with email.

> sessionInfo()
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_Canada.utf8  LC_CTYPE=English_Canada.utf8   
[3] LC_MONETARY=English_Canada.utf8 LC_NUMERIC=C                   
[5] LC_TIME=English_Canada.utf8    

time zone: America/Toronto
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] shiny_1.7.5    firebase_1.0.2 bslib_0.5.1   

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.7       dplyr_1.1.3          compiler_4.3.1      
 [4] promises_1.2.1       tidyselect_1.2.0     Rcpp_1.0.11         
 [7] later_1.3.1          jquerylib_0.1.4      fastmap_1.1.1       
[10] mime_0.12            R6_2.5.1             shinyjs_2.1.0       
[13] generics_0.1.3       jose_1.2.0           tibble_3.2.1        
[16] openssl_2.1.0        pillar_1.9.0         rlang_1.1.1         
[19] utf8_1.2.4           cachem_1.0.8         httpuv_1.6.12       
[22] sass_0.4.7           cli_3.6.1            magrittr_2.0.3      
[25] digest_0.6.33        rstudioapi_0.15.0    xtable_1.8-4        
[28] base64enc_0.1-3      askpass_1.2.0        lifecycle_1.0.3     
[31] vctrs_0.6.4          glue_1.6.2           fansi_1.0.5         
[34] tools_4.3.1          pkgconfig_2.0.3      ellipsis_0.3.2      
[37] htmltools_0.5.6.9001

Security

To report security issues:

  • Add security file to repository
  • Add github issue template -> don't open issue, email me
  • See if Github can notify users who use the package

RMarkdown

Does it work in Rmarkdown? I am using shiny_prerendered markdown doc. I am including all JS and CSS of firebase package using tags$head( )

The code below does not work in any of this including or excluding context='server'-

  f <- FirebaseUI$
    new()$ # instantiate
    set_providers( # define providers
      email = TRUE, 
      google = TRUE
    )

Stripe Extension for Firebase

Hi,

Thanks to your library, I successfully hosted a shiny app in Google Cloud Run, using Firebase for authentication.
I am now trying to use the Stripe Extension provided through Firebase.
I followed the steps outlined here, adding the javascript functions in the app's .js file, but the app seems to be ignoring this. Any ideas on how the extension could be leveraged with your library?

Empty providerData

Hi,
I'm getting an empty list in f$get_signed_in()$response$providerData where previously I would get microsoft.com or other providers being used.
But confusingly when I reload the page ("session" persistence) the providerData field is filled.
I haven't been able to figure out why this is happening :(

(I'm using this to check which provider is being used, if it is email then I check whether the email has been verified).

thanks!

Enh: return sub-folders when calling `list_all_files()`

Right now, calling e.g., firebase::Storage$new()$ref(some_directory)$list_files_all(response = 'some_response') returns only the list of files in that directory. It would be nice to also return the list of any sub-folders in that directory. I think this is because the custom message handler 'fireblaze-list-all-files' in storage.js only returns res.items, while the sub-folders are in a separate key called res.prefixes (see ref)

Ref: https://firebase.google.com/docs/reference/js/v8/firebase.storage.Reference#listall

Shiny dashboard, Firebase, and external css files

Hi,

I am trying to add an external style sheet to a shiny dashboard app but the server responded with a status of 404 (Not Found) regarding the CSS file. The style link works fine without firebase.

Should I be changing the path to the CSS file in any way?
Is there another way around this other than pasting all the CSS in the app code?

Thank you in advance!

app.R

library(shiny)
library(shinydashboard)
library(firebase)

ui <- dashboardPage(
  header = dashboardHeader(title = 'title'),
  sidebar = dashboardSidebar(sidebarMenu(
    menuItem(
      "login",
      tabName = "login",
      icon = icon(lib = 'glyphicon', "th")
    ),
    menuItem(
      "plot",
      tabName = "plot",
      icon = icon(lib = 'glyphicon', "th")
    )
  )),
  body = dashboardBody(
    useFirebase(),
    firebaseUIContainer(),
    tags$head(
      tags$link(rel = "stylesheet", type = "text/css", href = "style.css")
    ),
    tabItems(
      tabItem(tabName = 'login',
              h1('login/logout'),
              reqSignin(actionButton(
                "signout", "Sign out"
              ))),
      tabItem(tabName = 'plot',
              h1('plot'),
              plotOutput("plot"))
    )
  )
)

server <- function(input, output) {
  f <- FirebaseUI$new("session")$set_providers(email = TRUE,
                                               google = TRUE)$launch()
  
  output$plot <- renderPlot({
    f$req_sign_in()
    plot(cars)
  })
  
  observeEvent(input$signout, {
    f$sign_out()
  })
  
}

shinyApp(ui, server)

style.css


body{
  color:red!important;
}

Time Zone and Availability of $response$lastLoginAt

Hello,

I have two problems about the $lastLoginAt data provided after logging in.

(1)
I want to create an auto Logout after x minutes for my hosted App. For the current time I want to use Sys.time() which is the server time. If the current time exceeds the "$response$lastLoginAt" time + x minutes, the user shall be logged out.

So I want to ask whether the number of $response$lastLoginAt and the number as.numeric(Sys.time()) are comparable to each other. Otherwise my approach would be to convert the $response$lastLoginAt number to POSIXct and fit the time zone to the one of Sys.time(). After that, I would retransform the date with correct time zone to a number again.

(2)
It appears that if I log into the shiny app using firebase, the "get_signed_in()$response" object contains no $lastLoginAt or $createdAt data. Only if I reload the page this data shows up. Other data like $email is always available.

Thank you in advance.

How should firebase be integrated with a shinydashboard app?

Hi,

I am trying to use the firebase lib in a shiny app built using shinydashboard.
I tried adjusting the example provided in the documentation but I don't think this is the correct way of doing this.
Is there a suggested way to integrate the two libs?


library(shiny)
library(shinydashboard)
library(firebase)

ui <- dashboardPage(
  header = dashboardHeader(title = 'title'),
  sidebar = dashboardSidebar(),
  body = dashboardBody(
    useFirebase(),
    firebaseUIContainer(),
    reqSignin(actionButton("signout", "Sign out")),
    uiOutput("msg"),
    plotOutput("plot")
  )
)

server <- function(input, output){
  f <- FirebaseUI$
    new("session")$
    set_providers(
      email = TRUE,
      google = TRUE
    )$
    launch()
  
  output$plot <- renderPlot({
    f$req_sign_in() # require sign in
    plot(cars)
  })
  
  output$msg <- renderUI({
    f$req_sign_in() # require sign in
    
    user <- f$get_signed_in() # get logged in user info
    print(user)
    
    h4("Welcome,", user$response$displayName)
  })
  
  observeEvent(input$signout, {
    f$sign_out()
  })
  
}

shinyApp(ui, server)

add text to firebaseUIContainer

Hi

I wonder if its possible to add additional info or text to firebaseUIContainer.

I would like to add 1 line of text. Is that possible or is this a feauture request than?

Example App does not render anything in Firefox, sometimes

The below works reliably in Chrome and Safari, but only intermittently Firefox. When it doesn't work, nothing is rendered in the Firefox browser.

library(shiny)
library(firebase)

ui <- fluidPage(
  useFirebase(), # import dependencies,
  firebaseUIContainer()
)

server <- function(input, output){
  f <- FirebaseUI$
    new()$ # instantiate
    set_providers( # define providers
      email = TRUE, 
      google = TRUE
    )$
    launch() # launch
}

shinyApp(ui, server)

The rendered HTML in Firefox (using view page source in Firefox) looks identical when it works and doesn't work. There are no errors in the Firefox console. Opening a new tab and pasting the locally generated URL (from Shiny, using RStudio) sometimes results in the expected Firebase login buttons, but sometimes does not. This appears to be a problem with how Firefox is rendering the JS or something else with Firefox (that is, the same Shiny instance sometimes works in Firefox, but sometimes doesn't).

OAuth redirect stuck in loop (Microsoft)

Hey John,

If I modify the code on your example app to launch with redirect instead of popup with Microsoft as the service provider, the auth seems to get stuck in a loop.

It works perfect with launch(flow = "popup").

Same behaviour is experienced when specifying the TENANT_ID, fyi.

Two reprex below, the first is a successful log in with popup and the second is unsuccessful login with redirect.

# reprex 1) working with popup

library(shiny)
library(firebase)

ui <- fluidPage(
  useFirebase(), 
  firebaseUIContainer()
)

server <- function(input, output){
  f <- FirebaseOauthProviders$
    new()$ 
    set_provider("microsoft.com")$
    launch(flow="popup") # works 
}

shinyApp(ui, server)
# reprex 2) not working with redirect

library(shiny)
library(firebase)

ui <- fluidPage(
  useFirebase(), 
  firebaseUIContainer()
)

server <- function(input, output){
  f <- FirebaseOauthProviders$
    new()$ 
    set_provider("microsoft.com")$
    launch(flow="redirect") # doesn't work, gets stuck in loop
}

shinyApp(ui, server)

Thanks again for a really great package!

Warning: Missing Terms of Service and/or Privacy policy URL, see `set_tos_url` and `set_privacy_policy_url` methods

Hello,

I am not able to find any documentation on how to add the URLs for policy and terms.

I have deployed my app on shinyapps.io.

Warning: Missing Terms of Service and/or Privacy policy URL, see set_tos_url and set_privacy_policy_url methods

The document only mentions that:
link to the document: https://firebase.john-coene.com/articles/ui.html
Notice the warning in the console; this should be fixed when deploying to prod.

Thanks,
Manohar

FirebaseUI not showing up half of the time

I have to reload the page multiple times for FirebaseUI to appear, when I reload more it goes away again, then back...

When it doesn't appear: FirebaseUI$launch is called before the Shiny.addCustomMessageHandlerfor "fireblaze-ui-config" is registered (I see it by logging both events to the js console).

Any idea how to fix the timing?

Email verification not working with FirebaseUI

I'm using firebase::FirebaseUI and firebase::useFirebase() in my app with email-password authentication among other providers (set_providers(email = TRUE, ...)), but sending the verification email is not working.

The problem seems to be that useFirebase does not include all necessary javascript functions for it to work properly. Particularly, it does not add "inst/packer/email-password.js" as a html dependency. This file includes message handlers for "fireblaze-send-verification-email" and others which, I guess, are need for email-password authentication to work properly when using FirebaseUI.

As a workaround, I included these dependencies manually in to my app:

  addResourcePath(
    "firebase-assets",
    system.file("packer", package = "firebase")
  )

and in the UI:

    htmlDependency(
      "firebase-email-password",
      utils::packageVersion("firebase"),
      src = c(href = "firebase-assets"),
      script = "email-password.js"
    )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.