Equivalent of fetch_token with auth_code in httr2 library

205 views Asked by At

I want to replicate python example of receiving both access and refresh tokens, like here (Python)

token_response = oauth2_session.fetch_token(TOKEN_GRANT_URL, code=AUTHORIZATION_CODE, client_secret=CLIENT_SECRET)

How could I do it using httr2 library?

There are my previous steps to get the AUTHORIZATION_CODE (R)

client <- httr2::oauth_client(token_url = token_grant_url,secret = .app_secret,id = .app_key)
url_to_browse <- httr2::oauth_flow_auth_code_url(client=client, auth_url = auth_url,
                                                 scope = paste0(SCOPES_TO_REQUEST, collapse = " "),
                                                 redirect_uri = .client_redirect,state = STATE)

But I don't understand which function should I use instead of fetch_token

Thanks for any help you can provide

Also I leave the link of my issue from github page of httr2 project

1

There are 1 answers

3
tavdp On

You would use the oauth2.0_token function (https://httr.r-lib.org/reference/oauth2.0_token.html)

token <- oauth2.0_token(
  endpoint,
  app,
  scope = NULL,
  user_params = NULL,
  type = NULL,
  use_oob = getOption("httr_oob_default"),
  oob_value = NULL,
  as_header = TRUE,
  use_basic_auth = FALSE,
  cache = getOption("httr_oauth_cache"),
  config_init = list(),
  client_credentials = FALSE,
  credentials = NULL,
  query_authorize_extra = list()
)