Overview:
Domino passes the username of a user accessing your Domino App in an HTTP header nameddomino-username
. If your App framework gives you access to the HTTP headers of the active request, you can retrieve the username for use by your App code. If you allow users who are not logged in to Domino to view your Apps, for their requests to the App the value of thedomino-username
header will be "Anonymous."
Prerequisite
An App framework that can access proxied HTTP headers. This is supported by Flask and Dash by default, but is only supported by Shiny if using Server Pro.
Usage:
Is there a workaround to extract username of R shiny App Viewer if not using Server Pro?
Resolution:
To extract username from document.cookie in JavaScript and sending that as an input value to Shiny with Shiny.setInputValue, https://shiny.rstudio.com/articles/communicating-with-js.html
Sample JavaScript snippet other customer used to obtain the username and send it to the R Shiny app.
var req = new XMLHttpRequest()
// Handle HTTP GET response event
req.addEventListener("load", function() {
// If the HTTP GET failed, log and exit event handler early
if (this.status !== 200) {
console.error("Failed to retrive username with HTTP code", this.status)
// Maybe set a default username?
Shiny.setInputValue('username', 'anonymous')
return
}
// Parse the returned JSON and retrive the username
var response = JSON.parse(this.responseText)
var username = response.canonicalName
console.log("Your username is:", username)
// Send username to Shiny
// https://shiny.rstudio.com/articles/communicating-with-js.html
Shiny.setInputValue('username', username)
})
// Send the HTTP GET request
req.open('GET', '/v4/auth/principal')
req.send()
Comments
0 comments
Please sign in to leave a comment.