Skip to content

This uses oauth_flow_device() to generate an access token, which is then used to authentication the request with req_auth_bearer_token(). The token is automatically cached (either in memory or on disk) to minimise the number of times the flow is performed.

Usage

req_oauth_device(
  req,
  client,
  cache_disk = FALSE,
  cache_key = NULL,
  scope = NULL,
  auth_params = list(),
  token_params = list()
)

Arguments

req

A request.

client

An oauth_client().

cache_disk

Should the access token be cached on disk? This reduces the number of times that you need to re-authenticate at the cost of storing access credentials on disk. Cached tokens are encrypted and automatically deleted 30 days after creation.

cache_key

If you want to cache multiple tokens per app, use this key to disambiguate them.

scope

Scopes to be requested from the resource owner.

auth_params

List containing additional parameters passed to oauth_flow_auth_code_url()

token_params

List containing additional parameters passed to the token_url.

Value

A modified HTTP request.

Examples

client <- oauth_client("example", "https://example.com/get_token")
req <- request("https://example.com")

req %>% req_oauth_device(client)
#> <httr2_request>
#> GET https://example.com
#> Body: empty
#> Policies:
#>auth_oauth: a list