Skip to contents

Request an OAuth access token for a third-party resource from Posit Connect. The OAuth token will belong to the client (usually a "service principal" or "service account") managed by Connect, not the publisher.

Usage

connect_service_account_token(
  resource = NULL,
  scope = NULL,
  content_token = Sys.getenv("CONNECT_CONTENT_SESSION_TOKEN"),
  server_url = Sys.getenv("CONNECT_SERVER"),
  api_key = Sys.getenv("CONNECT_API_KEY")
)

has_service_account_token(...)

Arguments

resource

The URI that identifies the resource that the client is trying to access, if applicable.

scope

Scopes to be requested from the resource owner.

content_token

A token that uniquely identifies this content session. Defaults to the value of the CONNECT_CONTENT_SESSION_TOKEN environment variable, which is set automatically when running on Connect.

server_url

The Connect server to exchange credentials with. Defaults to the value of the CONNECT_SERVER environment variable, which is set automatically when running on Connect.

api_key

An API key for the Connect server. Defaults to the value of the CONNECT_API_KEY environment variable, which is set automatically when running on Connect.

...

Further arguments passed on to connect_service_account_token().

Value

connect_service_account_token() returns an httr2::oauth_token.

has_service_account_token() returns TRUE if there is a Connect-managed service account avaiable and FALSE otherwise.

Details

connect_service_account_token() handles caching automatically.

Examples

token <- "default-token"
if (has_service_account_token()) {
  token <- connect_service_account_token()
}