Handle callbacks and establish the connection owner's browser session
Source:R/oauth_connections_ui.R
oauth_connections_ui.RdHandles login returns and restores the user's saved connections. The wrapper
and oauth_connections_server() share the same manager and module ID.
Browser setup from use_shinyOAuth() is included.
Arguments
- base_ui
A Shiny UI object or request-dependent UI function.
- id
Module ID shared with
oauth_connections_server().- manager
Configuration from
oauth_connections().- request_uri_resolver
Optional trusted function mapping a Rook request to its public absolute URI. Required when a trusted reverse proxy changes the apparent scheme/host. The custom resolver defines which proxy headers are trusted; the wrapper checks the resolved origin against the manager's origin.
- app_base_path
Public path at which the Shiny application is hosted, default
"/". Must begin and end with/. The wrapper inserts a document base before scripts so Shiny dependencies load from the app root even on nested callback pages. The wrapper manages the page's HTMLbaseelement. Managed JAR Request Object URLs are also published beneath this path.- launch_routes
List of
smart_launch_route()configurations, empty by default. EHR entry requires browser retention and top-level navigation.- additional_clients
Optional named list of ordinary OAuth/OIDC clients used by separate
oauth_module_server()modules. Names are their full module IDs. These clients keep their existing login lifecycle and are not managed connections. This wrapper dispatches their callbacks alongside managed ones. Their callback routes must be distinct from managed callbacks and SMART launch routes, on this app's origin and insideapp_base_path. All clients must select an appropriate multi-server authorization mode, even when the manager contains one client.
Details
With shinyApp(..., uiPattern = ".*"), callback paths reach the wrapper.
With browser retention, a cookie lets the returning browser
find its saved connections.
Advanced browser and proxy requirements
With Strict cookies, returning from another site may briefly show an intermediate
page before Shiny starts. This lets the browser send its existing cookie.
Proxies must preserve
same-origin Fetch Metadata, Referer or Origin information for recovery.
The shinyOAuth_owner_recovery query parameter is reserved for this flow.
A managed login return must still belong to a valid local owner. An ordinary
entry or an independently validated additional_clients callback can create
an empty browser owner, but cannot recover someone else's connections.
Invalid cookies are cleared before a fresh owner is created.
Cookies are shared across ports and paths on the same hostname. Services on that hostname share the owner cookie's trust boundary.
Examples
# Replace this example provider and client ID with your registered application.
provider <- oauth_provider(
name = "Example service",
auth_url = "https://example.com/authorize",
token_url = "https://example.com/token",
token_auth_style = "public"
)
client <- oauth_client(
provider = provider,
client_id = "example-client",
redirect_uri = "http://127.0.0.1:8100/callback/service",
resource_bases = c(api = "https://api.example.com")
)
# Create the manager once, outside server(). Default retention is one Shiny session.
manager <- oauth_connections(
clients = list(service = client),
app_origin = "http://127.0.0.1:8100"
)
ui <- oauth_connections_ui(
shiny::fluidPage(
shiny::actionButton("connect", "Connect to service"),
shiny::verbatimTextOutput("connections")
),
id = "auth",
manager = manager
)
server <- function(input, output, session) {
auth <- oauth_connections_server("auth", manager)
shiny::observeEvent(input[["connect"]], auth[["connect"]]("service"))
output[["connections"]] <- shiny::renderPrint(auth[["connections"]]())
}
# Construct the app without launching it or contacting the provider.
app <- shiny::shinyApp(
ui,
server,
uiPattern = ".*",
options = list(port = 8100)
)