I am trying to import the javascript MSAL library into an rMarkdown script so that I can use it to obtain an oauth token for a db connection.
The first script called is to import the msal library. And the second one is the script used to obtain the oauth token. However I'm assuming it errors at the first script as the "msal library is not defined". Where am I going wrong?
Here is the minimal reproducible script:
---
title: "Test"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(htmltools)
# serve the files
addResourcePath(prefix = "files", directoryPath = "assets")
htmltools::tagList(
htmltools::tags$script(src = c(href = "https://alcdn.msauth.net/browser/2.17.0/js/msal-browser.js")),
htmltools::tags$script("
async function wrapperFunc() {
const msalConfig = {
auth: {
clientId: 'XXX',
authority: 'XXX'
}
};
const msalInstance = new msal.PublicClientApplication(msalConfig);
const silentRequest = {
scopes: ["XXX]
};
const callLogin = async function(silentRequest, msalInstance) {
try {
const loginResponse = await msalInstance.loginPopup(silentRequest);
return loginResponse;
} catch (err) {
console.log(err)
}
}
response = callLogin(silentRequest, msalInstance);
return response;
}
wrapperFunc().then(result => {
console.log(result['accessToken']);
});
")
)