Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

googleAuthR.redirect is hard-coded to localhost #219

Open
JARACH-209 opened this issue Jun 30, 2022 · 6 comments
Open

googleAuthR.redirect is hard-coded to localhost #219

JARACH-209 opened this issue Jun 30, 2022 · 6 comments

Comments

@JARACH-209
Copy link

What goes wrong

The redirect_uri is hard coded in the package to https://localhost:1221. See the file -> options.R

Steps to reproduce the problem

Please note that if a reproduceable example that I can run is not available, then the likelihood of getting any bug fixed is low.

Just try to run the app on a R-studio server and pass the (googleAuthR.redirect = "https://XYZ.com/dashboard")

Point is that the redirect option in options.R seems to be hardcoded to localhost:1221

Expected output

Use the value passed by the user.

Actual output

image

Before you run your code, please run:

options(googleAuthR.verbose=2) and copy-paste the console output here.
Check it doesn't include any sensitive info like auth tokens or accountIds - you can usually just edit those out manually and replace with say XXX

Session Info

Please run sessionInfo() so we can check what versions of packages you have installed

sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

@MarkEdmondson1234
Copy link
Owner

Can I see the code you are trying? I think you need to make sure you are setting the option in the right place e.g. options(googleAuthR.redirect = "https://xyz.com/dashboard") needs to be done before the authentication URL is generated.

@JARACH-209
Copy link
Author

JARACH-209 commented Jun 30, 2022

it is a simple single page app. I have set up the correct redirects and origins but I suspect that since the redirect parameter is hardcoded to localhost:1221 the app redirects to that uri instead of the one I assign through options()


library(shiny)
library(tidyverse)
library(lubridate)
library(sf)
library(googleAuthR)
load('pricing_files.RData')

WHITELIST <- c("X","Y")

options(googleAuthR.webapp.client_id = "XXXXX")
options(gooleAuthR.webapp.client_secret = "XXXXX")
options(gooleAuthR.redirect = "https://xx.XYZ.com/DASHBOARD")

options(googleAuthR.scopes.selected = c("https://www.googleapis.com/auth/userinfo.email",
                                        "https://www.googleapis.com/auth/userinfo.profile"))


user_info <- function() {
  f <- gar_api_generator(
    "https://www.googleapis.com/oauth2/v1/userinfo",
    "GET",
    data_parse_function = function(x) x)
  f()
}

*** SOME DATA LOADING CODE ***

ui <- uiOutput('myUI') 

source('ui.R')

# Define server logic required to draw a histogram
server <- function(input, output, session) {
  
  gar_shiny_auth(session)
  
  #Check if user has already logged in with google authentication
  gmail=''  
  tryCatch({
    x <- user_info()
    gmail=x$email
    }) 
  print(gmail)
  
  output$myUI <- renderUI({
    if (gmail %in% WHITELIST){
    ui = dash_ui
  }
  else{
    ui = denied_ui
    Sys.sleep(1000000)
  }
  })
  
  observeEvent(input$browser,{
    browser()
  })
  
  polygonList <- reactive({
    polygon_list(input$dc)
  })
  
  *** DASHBOARD CODE ***
  
  # val <- reactiveValues( clickx = NULL, clicky = NULL)
  # 
  # observe({
  #   input$plot_click 
  #   isolate({
  #     # save new points added
  #     val$clickx = c(val$clickx, input$plot_click$x)
  #     val$clicky = c(val$clicky, input$plot_click$y)
  #   })
  # })
  # 
  
  
*** MORE DASHBOARD CODE ***
  
}

# Run the application 
#shinyApp(ui = ui, server = server)
shinyApp(gar_shiny_ui(ui, login_ui = silent_auth), server) 

@MarkEdmondson1234
Copy link
Owner

I guess you are using shinyapps.io ? It has an issue where it caches packages - see #74

The redirect URL its not possible to set via an environmental variable though.

I suggest you look at client based JS authentication instead, via the firebase package https://firebase.john-coene.com/

Or rebuild the package with your options by cloning this github locally and rebuilding the package, and upload that to Shinyapps.io instead of the CRAN version.

@JARACH-209
Copy link
Author

JARACH-209 commented Jun 30, 2022 via email

@JARACH-209
Copy link
Author

@MarkEdmondson1234 can you add me to the slack channel ?

@chintanp
Copy link

chintanp commented Jan 2, 2023

@JARACH-209 were you able to resolve this issue? I have a similar setup - AWS EC2 instance for development and production. During development, I use RStudio Server for debugging and would like the auth to work as well.

@MarkEdmondson1234 Appreciate if you can add a note or an example config for this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants