Hello there!
I am currently trying to use the MSAL javascript library in a R markdown report to obtain an oauth token to authenticate a db connection in a code chunk. Currently my script is like this:
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
<script src="https://alcdn.msauth.net/browser/2.35.0/js/msal-browser.js"></script>
```{js}
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"]);
});
```
But I am getting this error below in the console when deploying to r studio connect. All I need at this stage is for the oauth token to be printed in the console (or ideally obtained as an R variable).
How do I obtain this oauth token?! Or at least load the msal library correctly?