req_oauth_refresh {httr2} | R Documentation |
This uses oauth_flow_refresh()
to generate an access token, which is
then used to authenticate 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).
req_oauth_refresh(
req,
client,
refresh_token = Sys.getenv("HTTR2_REFRESH_TOKEN"),
scope = NULL,
token_params = list()
)
req |
A request. |
client |
An |
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 |
scope |
Scopes to be requested from the resource owner. |
token_params |
List containing additional parameters passed to the
|
A modified HTTP request.
client <- oauth_client("example", "https://example.com/get_token")
req <- request("https://example.com")
req %>% req_oauth_refresh(client)