r - 用于 flexdashboard 闪亮应用的 Oauth2.0 流程
问题描述
我们正在尝试使用 Flex Dashboard 将 OAuth2.0 实施到 Shiny 应用程序中。OAuth 流程当前正在执行,我可以登录并查看 URL 中的code
和state
变量。当 OAuth 服务器重定向到我的应用程序时,它会卡在灰色的 flexdashboard 加载屏幕上。
除了检查我们是否正确执行此操作之外,应用程序是否还应该有一个用于 OAuth 的重定向 URL,在该处处理令牌?如果是这样,我们将如何配置它?
我们基本上是按照这里的说明进行的。以下是该过程的 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,但它只是卡在了加载页面上。
解决方案
推荐阅读
- arrays - 如何从数组反应中删除正确的元素?
- postgresql - Docker postgress 用户“postgres”没有分配密码
- python - 如何使用 python apply/lambda/shift 函数根据 2 列的值获取该特定列的前一行值?
- ssrs-2008 - SSRS 货币未显示为加元
- javascript - 来自个人经验或资源的优化建议
- azure - 在 yaml 文件中转换可视化构建管道
- amazon-web-services - 自动伸缩组:如何允许从我自己的 ec2 入网?(子网?)
- java - 如何将特定于项目的设置从 Eclipse 共享到 Intelij?
- if-statement - Cypress 中的 If Else 语句
- java - @JoinColumn name 和 ForeignKey 的区别