9

We’re trying to implement OAuth2.0 into a Shiny app using Flex Dashboard. The OAuth flow is currently executing, I can login and see the code and state variables in the URL. When the OAuth server redirects to my app, it gets stuck on the grey flexdashboard loading screen.

In addition to examining if we are doing this correctly, should the app also have a redirect URL for OAuth, where the token is processed? If so, how would we configure that?

We were basically following the instructions here. Below is the rmarkdown content for the process.


    ---
    title: "Question"
    output: 
      flexdashboard::flex_dashboard:
        orientation: rows
        vertical_layout: fill
    fontsize: 12
    runtime: shiny
    ---

    ```{r oauth1}    
    options(shiny.host = '0.0.0.0', shiny.port = 8100, shiny.trace = TRUE)  

    APP_URL <- "https://localhost:8100/"

    if (interactive()) {
       # testing url
       cat(file=stderr(), "starting in interactive mode!")
       APP_URL <- "http://localhost:8100/"
     } else {
       # deployed URL
       cat(file=stderr(), "starting in non-interactive mode!")
       APP_URL <- example_url
    }

    app <- oauth_app("Accounts",
                     key = KEY,# Add key value here
                     secret = SECRET,# Add secret value here
                     redirect_uri = APP_URL
    )

    api <- oauth_endpoint(
      authorize = "https://example_url/oauth/authorize",
      access = "https://example_url/oauth/token"
    )

    scope <- ""

    has_auth_code <- function(params) {
      urlParams = parseQueryString(isolate(session$clientData$url_search))
      browser()
      }

    ```

    ```{r oauth2}
    # Manually create a token
    token <- oauth2.0_token(
        app = app,
        endpoint = api,
        cache = FALSE)
    )
    save(token, file="ox_oauth")

    params <- parseQueryString(isolate(session$clientData$url_search))

    resp <-GET("https://example_url_1/api/user", config(token = token))
    #stop_for_status(resp)

    cat(file=stderr(), "Looking for response")
    cat(file=stderr(), resp)
    ```

    ```{r ui}
    uiFunc <- function(req) {
      cat(file=stderr(), "starting UI function")
      if (!has_auth_code(parseQueryString(req$QUERY_STRING))) {
        url <- oauth2.0_authorize_url(api, app, scope = scope)
        cat(file=stderr(), url)
        redirect <- sprintf("location.replace(\"%s\");", url)
        tags$script(HTML(redirect))
      } else {
        ui
      }
    }
    ```

    ```
    Page 1
    =====================================================================
    row {data-width=800 data-height=100 .tabset .tabset-fade}
    -----------------------------------------------------------------------

    ### Section 1

    ```{r pg1sec1}
    selectizeInput(
        "A_Type",
        label = "Assignment type",
        choices = c("HW", "R"),
        multiple = TRUE,
        # selectize = TRUE,
        options = list(placeholder = "Select assignment type(s)"),
        width = '98%',
        selected = ""
    )
    ```

    ```{r og1sec1.1}
    observeEvent(input$A_Type, {
        x <- input$A_Type
        updateSelectizeInput(session, "A_Type2",
                            selected = x)
    })
    ```
    ```
    Page 2
    =====================================================================
    row {data-width=800 data-height=100 .tabset .tabset-fade}
    -----------------------------------------------------------------------

    ### Section 1

    ```{r pg2sec1}
    selectizeInput(
        "A_Type2",
        label = "Assignment type",
        choices = c("HW", "R"),
        multiple = TRUE,
        width = '98%'
    )
    ```

We got the following output in the rmarkdown window:

    Waiting for authentication in browser...
    Press Esc/Ctrl + C to abort
    Please point your browser to the following url: 
        https://example_url/oauth/authorize?client_id=KEY&redirect_uri=XXX%2F&response_type=code&state=XXX

We expected it to open the flexdashboard in the browser window, and it just got stuck on the loading page.

dbm
  • 133
  • 1
  • 1
  • 8
  • If you are using Chrome, can you check the console to see what messages are there if any? – Green Jun 19 '19 at 17:56
  • Hi @Green I checked the messages on chrome (Version 74.0.3729.169) under the `Network` tab. There were only 3 things: `[INF] Connection opened. [DBG]: Open channel 0 [DBG]: 2 messages discarded from buffer.` – dbm Jun 19 '19 at 19:26
  • In the GitHub link you provided, someone else added a modification T https://gist.github.com/hadley/144c406871768d0cbe66b0b810160528#gistcomment-2389768 Try to see if it works for you. – Green Jun 19 '19 at 20:31
  • @Green I tried the other solution and even that did not seem to work for me. I shall continue to tinker with it. Thanks. – dbm Jun 21 '19 at 18:36
  • Hi! Did you ever find a solution? Im stuck at the same spot as you it seems; no browser pops up for the user to login to. – Serkan Apr 29 '21 at 10:43

0 Answers0