Skip to content

Simplify reading Connect pins as the viewer #363

Open

Description

@mconflitti-pbc

#362 documents how to read pins as the viewer on Posit Connect with a visitor API key. The example must read the Posit-Connect-User-Session-Token header from the Shiny session and exchange it with posit-sdk:

token = session.http_conn.headers.get("Posit-Connect-User-Session-Token")
client = connect.Client()
credentials = client.oauth.get_credentials(
    token,
    requested_token_type="urn:posit:connect:api-key",
)
board = board_connect(server_url=..., api_key=credentials["access_token"], cache=None)

Users must know about the header, the token exchange, and the token type, and it is easy to get wrong. Client.with_user_session_token() already does the exchange, but it does not expose the API key that pins needs.

In the review of the matching pins-r docs (rstudio/pins-r#906), a helper was proposed, so that the example does not need to explain the header or the exchange.

Tasks:

  • Add a helper to posit-sdk that takes a Shiny session and returns the visitor API key, or a client that exposes it.
  • Update the visitor example in docs/index.qmd to use the helper.
  • Decide if board_connect() should accept the visitor client or session directly, so that users do not pass the key and cache by hand.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions