Skip to content

This uses oauth_flow_refresh() to generate an access token, which is then used to authentication the request with req_auth_bearer_token(). This is primarily useful for testing: you can manually execute another OAuth flow (e.g. by calling oauth_flow_auth_code() or oauth_flow_device()), extract the refresh token from the result, and then save in an environment variable for future use in automated tests.

When requesting an access token, the server may also return a new refresh token. If this happens, oauth_flow_refresh() will error, and you'll have to create a new refresh token following the same procedure you did to get the first token (so it's a good idea to document what you did the first time because you might need to do it again).

Usage

req_oauth_refresh(
  req,
  client,
  refresh_token = Sys.getenv("HTTR_REFRESH_TOKEN"),
  scope = NULL,
  token_params = list()
)

Arguments

req

A request.

client

An oauth_client().

refresh_token

A refresh token. This is equivalent to a password so shouldn't be typed into the console or stored in a script. Instead, we recommend placing in an environment variable; the default behaviour is to look in HTTR_REFRESH_TOKEN.

scope

Scopes to be requested from the resource owner.

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_refresh(client)
#> <httr2_request>
#> GET https://example.com
#> Body: empty
#> Policies:
#>auth_oauth: a list