This is probably a basic question, but: how can I display some programmatically-generated text to the user, and then send an object to the server?
The context is that I'm trying to get my AzureAuth package for Azure Active Directory OAuth authentication working with Shiny, using the device code flow. How this works is that first, your app contacts the server to get some authorization details: a user code, and a verification code. The user then visits a login page (whose URL is also provided by the server) and enter the user code. This prompts them to login to Azure.
Meanwhile, your app polls the server, passing it the verification code to identify itself. When the user has successfully logged in, the server will then return the token to your app.
The device code flow is really meant for situations where a web browser isn't available, so isn't really necessary for use with Shiny, but I'd still like to get it working. I already have the authorization code flow working, which is the usual way of logging in.
Here is some code I've rigged up. In the UI component, I contact the server to get the user and verification codes. I then pass the object containing the verification code to the server, via the global environment. Points of note:
- I have to display the provided message to tell the user the code and login URL
- The
get_azure_token
function in the server is continuously polling AAD until the user logs in
This works, but I'm sure there's a better way.
devtools::install_github("Azure/AzureAuth")
library(shiny)
library(AzureAuth)
options(shiny.port=8100)
# parameters -- should work for anyone with an Azure account
resource <- "https://management.azure.com"
tenant <- "common"
app <- "04b07795-8ddb-461a-bbee-02f9e1bf7b46"
ui <- fluidPage(
{
creds <<- get_device_creds(resource, tenant, app)
tags$p(creds$message)
},
verbatimTextOutput("token")
)
server <- function(input, output, session)
{
on.exit(rm(creds, envir=globalenv()))
token <- get_azure_token(resource, tenant, app, auth_type="device_code",
use_cache=FALSE, device_creds=creds)
output$token <- renderPrint(token)
}
shinyApp(ui, server)