Мы пытаемся внедрить OAuth2.0 в приложение Shiny, используя Flex Dashboard.Поток OAuth в данный момент выполняется, я могу войти в систему и увидеть переменные code
и state
в URL.Когда сервер OAuth перенаправляет в мое приложение, он застревает на сером экране загрузки flexdashboard.
В дополнение к проверке, правильно ли мы это делаем, должно ли приложение иметь URL-адрес перенаправления для OAuth, где токенобрабатывается?Если да, то как бы это настроить?
Мы в основном следовали инструкциям здесь .Ниже приведено содержимое rmarkdown для процесса.
---
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%'
)
```
Мы получили следующий вывод в окне rmarkdown:
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
Мы ожидали, что он откроет flexdashboard в окне браузера, ион просто застрял на странице загрузки.