MarkEdmondson1234 / googleAuthR

Google API Client Library for R. Easy authentication and help to build Google API R libraries with OAuth2. Shiny compatible.
https://code.markedmondson.me/googleAuthR
Other
175 stars 54 forks source link

googleAuthR.redirect is hard-coded to localhost #219

Open JARACH-209 opened 2 years ago

JARACH-209 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

I guess you are using shinyapps.io ? It has an issue where it caches packages - see https://github.com/MarkEdmondson1234/googleAuthR/issues/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 commented 2 years ago

No I'm not using shinyapps.io. It is r-studio running on a server(ec2 instance) which I can access via nginx web server. Shiny server where the app is deployed resides on the same server.

On Thu, 30 Jun 2022, 18:31 Mark, @.***> wrote:

I guess you are using shinyapps.io ? It has an issue where it caches packages - see #74 https://github.com/MarkEdmondson1234/googleAuthR/issues/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.

— Reply to this email directly, view it on GitHub https://github.com/MarkEdmondson1234/googleAuthR/issues/219#issuecomment-1171191339, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKL64V7GI27UUWIXSKOODV3VRWLDBANCNFSM52I5AHTA . You are receiving this because you authored the thread.Message ID: @.***>

JARACH-209 commented 2 years ago

@MarkEdmondson1234 can you add me to the slack channel ?

chintanp commented 1 year ago

@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.