Skip to content

For an app served by the portal under /app/<id>/ or /api/<id>/. The proxy adds the identity to each request when the app's spec opts in:

Usage

hosted_identity(session)

hosted_identity_plumber(request)

Arguments

session

For Shiny, the session object (its $request is read), or the request environment itself.

request

For plumber2, the request argument of a handler (a reqres::Request; anything with a get_header(name) method works).

Value

An identity (see has_group()), or NULL for an anonymous visitor — or when the spec has not enabled the headers.

Details

Spec settingHeaderIdentity field
add-default-http-headers: trueX-SP-UserIdusername
X-SP-UserGroups (comma-separated)groups
identity-claims: [email]X-Ruscker-User-Emailemail
identity-claims: [setor]X-Ruscker-User-Setorsetor
identity-claims: [roles]X-Ruscker-User-Rolesgroup_roles

Why the values can be trusted: the proxy removes any X-SP-* and X-Ruscker-User-* header that arrives from outside, so a value the app sees was put there by the portal. That only holds when the app is reachable only through the portal.

Read identity per request, never from an environment variable: one container may serve many people.

The headers carry no permanent account id, so sub and name are always NULL here; key on username. An app restricted to some groups receives only those groups' roles.

Examples

# Shiny, inside server():  id <- hosted_identity(session)
# plumber2 handler:        id <- hosted_identity_plumber(request)
fake <- list(request = list(HTTP_X_SP_USERID = "ana",
                            HTTP_X_SP_USERGROUPS = "fiscal,obras"))
hosted_identity(fake)$groups
#> [1] "fiscal" "obras"