Shiny app not working in browser due to js variable not being available in environment?

I have put together an app using Golem that uses a js script to obtain an Azure AD Oauth token for a db connection.

The intended use of this app is for when someone presses the "search" action button, it initiates a connection (with Azure AD authentication) to a snowflake database for querying data. I am running this app through the browser by default (it will eventually be deployed to a RS Connect server).

When it is running through the browser, I am being hit by a message that says "invalid oauth token". It's looking looking like the JS script in the UI is not communication with the dbconnect section in the server - how do I go about fixing this? It works when I run it locally though.

The relevant pieces of code are below (credentials blocked out using "XXX"). Apologies for the long winded code.


mod_01_search_ui <- function(id){
 ns <- NS(id)
   # Leave this function for adding external resources

     shinydashboard::dashboardSidebar(disable = TRUE),

       # oauth JS

       async function wrapperFunc() {
               const msalConfig = {
                   auth: {
                       clientId: 'XXX',
                       authority: ''

               const msalInstance = new msal.PublicClientApplication(msalConfig);

               const silentRequest = {
                   scopes: ['api://XXX/session:role-any']


               const callLogin = async function(silentRequest, msalInstance) {
                   try {
                       const loginResponse = await msalInstance.loginPopup(silentRequest);
                       return loginResponse;
                   } catch (err) {

               response = callLogin(silentRequest, msalInstance);
             return response;
     wrapperFunc().then(result => {
           Shiny.setInputValue('01_search_1-oauthToken', result['accessToken']);

     fluidRow(align = 'center',
                               style="color: #000000; background-color: #ffb80c; border-color: 



mod_01_search_server <- function(id){
 moduleServer( id, function(input, output, session){
   ns <- session$ns


   data <- eventReactive(input$search, {

   connection <- connection <- DBI::dbConnect(
     drv = odbc::odbc(),
     dsn = "snowflake",
     token = input$oauthToken,
     authenticator = "oauth")


This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.