ShinyApp Google登录 [英] ShinyApp Google Login
问题描述
我有一个闪亮的应用程序,我想为使用Google登录名登录该应用程序的会员启用某些功能.我无法使用GoogleAuthR包在我的应用程序中实现Google登录和身份验证过程.有没有人有一个示例ShinyApp的示例,该示例允许观众通过google或任何其他社交论坛授权登录
I have a shinyapp and I want to enable certain features to the members who login to the app using google login. I am not able to implement the Google login and authentication process within my app using the GoogleAuthR package. Does anyone has an example of a sample ShinyApp which allows the audience to login through either google or any other social forum authorizations
通过代码欣赏演示.
PS:我无意对Google数据进行统计,但我只想消除为我的应用程序创建登录模块的麻烦,而让Google登录来解决麻烦
PS: I have no intention of running statistics on Google data but I only want to do away with the hassle of creating a login module for my app and let Google login take care of the hassles
谢谢 SD
推荐答案
我使用gar_shiny_ui
I solved this problem in a different manner using gar_shiny_ui
-
我们需要在服务器中定义UI
we need to define the UI in the server
获取用户信息并从其Google登录信息中提取电子邮件
Get user info and extract email from his/her google login
使用此电子邮件来确定此人是否来自您的组织
Use this email to determine if the person is from your organisation
如果此人来自您的组织,请显示主用户界面,否则请显示一个您无法访问此工具"的用户界面
If the person is from your organisation, show the main UI else show a UI which says '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)
这篇关于ShinyApp Google登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!