R Shiny - 使用 google 身份验证器允许具有特定类型电子邮件地址的人登录
R Shiny - use google authenticator to allow people with a certain type of email address to log in
我正在尝试构建一个允许我组织中的用户提交某些分析请求的应用程序。这是一个非常基本的闪亮应用程序,人们在其中输入参数,然后将此数据插入到 redshift 中的 table 中。
我添加了一个 Google 身份验证器使用
shinyApp(gar_shiny_ui(ui, login_ui = silent_auth), server)
在我的 app.R
结束时
这是我的服务器功能的顶部
gar_shiny_auth(session)
(我正在使用 googleAuthR 包)
这会在我的应用程序 UI 之前添加一个 Google 身份验证 UI 但问题是
它允许任何 google 电子邮件访问我的应用程序
我想添加一个过滤器,只允许 以 myorganisation.com 结尾的电子邮件地址访问应用程序。
有人知道如何实现吗?非常感谢您的帮助!
最后我找到了一个可行的解决方案。
除了我在问题中写的内容,
我们需要在服务器中定义UI
从 his/her google 登录获取用户信息并提取电子邮件
使用此电子邮件确定此人是否来自您的组织
如果此人来自您的组织,请显示主要 UI 否则显示 UI,其中显示 'You cannot access this tool'
#Function to get google user data which will be used for checking if the user comes from your organisation
user_info <- function(){
f <- gar_api_generator("https://www.googleapis.com/oauth2/v1/userinfo",
"GET",
data_parse_function = function(x) x
)
f()
}
#UI code based on Output coming via server code
ui<-uiOutput('myUI')
#Server side code to do all the lifting
server = function(input, output,session) {
gar_shiny_auth(session)
#Check if user has already logged in with google authentication
gmail='john.doe@unkwown.com'
tryCatch({
x<- user_info()
gmail=x$email
print(gmail)})
print(gmail)
#Create a different UI based on where the user comes from (MyOrg or Not)
output$myUI <- renderUI({
if(grepl('@myorganisation.com',gmail)){
ui = fluidPage(
shinyjs::useShinyjs(),
title='Your Product',
theme = shinytheme("cerulean"),
img(src = "mycompany_logo.png", height = 200, width = 400),
sidebarLayout(
sidebarPanel(write whatever you want)
,
mainPanel( write whatever you want)
)
)}
else {
ui = fluidPage(mainPanel(
h4("My Company Data Team Presents", allign="center"),
h1("My Tool", allign="center"),
p("Tool that makes analysing any and everything ",
em("incredibly easy "),
"with a simple click."),
br(),
p("- But unfortunately, your account does not have the rights to ",
em("access "),
"this tool."))) }
})
shinyApp(gar_shiny_ui(ui, login_ui = silent_auth), server)
我正在尝试构建一个允许我组织中的用户提交某些分析请求的应用程序。这是一个非常基本的闪亮应用程序,人们在其中输入参数,然后将此数据插入到 redshift 中的 table 中。
我添加了一个 Google 身份验证器使用
shinyApp(gar_shiny_ui(ui, login_ui = silent_auth), server)
在我的 app.R
结束时这是我的服务器功能的顶部
gar_shiny_auth(session)
(我正在使用 googleAuthR 包)
这会在我的应用程序 UI 之前添加一个 Google 身份验证 UI 但问题是
它允许任何 google 电子邮件访问我的应用程序
我想添加一个过滤器,只允许 以 myorganisation.com 结尾的电子邮件地址访问应用程序。
有人知道如何实现吗?非常感谢您的帮助!
最后我找到了一个可行的解决方案。
除了我在问题中写的内容,
我们需要在服务器中定义UI
从 his/her google 登录获取用户信息并提取电子邮件
使用此电子邮件确定此人是否来自您的组织
如果此人来自您的组织,请显示主要 UI 否则显示 UI,其中显示 'You cannot access this tool'
#Function to get google user data which will be used for checking if the user comes from your organisation user_info <- function(){ f <- gar_api_generator("https://www.googleapis.com/oauth2/v1/userinfo", "GET", data_parse_function = function(x) x ) f() } #UI code based on Output coming via server code ui<-uiOutput('myUI') #Server side code to do all the lifting server = function(input, output,session) { gar_shiny_auth(session) #Check if user has already logged in with google authentication gmail='john.doe@unkwown.com' tryCatch({ x<- user_info() gmail=x$email print(gmail)}) print(gmail) #Create a different UI based on where the user comes from (MyOrg or Not) output$myUI <- renderUI({ if(grepl('@myorganisation.com',gmail)){ ui = fluidPage( shinyjs::useShinyjs(), title='Your Product', theme = shinytheme("cerulean"), img(src = "mycompany_logo.png", height = 200, width = 400), sidebarLayout( sidebarPanel(write whatever you want) , mainPanel( write whatever you want) ) )} else { ui = fluidPage(mainPanel( h4("My Company Data Team Presents", allign="center"), h1("My Tool", allign="center"), p("Tool that makes analysing any and everything ", em("incredibly easy "), "with a simple click."), br(), p("- But unfortunately, your account does not have the rights to ", em("access "), "this tool."))) } }) shinyApp(gar_shiny_ui(ui, login_ui = silent_auth), server)