Automation of unusual auth routine

I regularly access a web api which uses an access token and refresh tokens for its auth flow.

As an additional layer of security, the access token expires every ten days at which point one must:

  • navigate to a url over https
  • enter login/ password credentials
  • click an "are you sure" button

Then, the browser is redirected to a localhost url (with a 404 code), a portion of which contains the NEW access token, which I've been manually copying/ pasting, eg:


Realizing this onerous procedure is by design, how can I nevertheless automate it? It seems that the redirect is beyond the ability of the httr package, but I might be doing it wrong.

As I'm dealing with auth credentials and given that I don't know where to start, I don't really have a reprex to offer.

Thank you in advance for any help.

You could probably do this using the rvest package.

The following might not work, I'm following the structure of some old code of mine.

# Load Packages

# Specify URL
url <- "YOUR_URL_HERE"
my_session <- html_session(url)

# Grab Login Form
form <- my_session %>% html_node("form") %>% html_form()

#  Form is filled using set_keys and key-value pairs
filled_form <- form %>%
set_values("LOGIN_NODE" = "YOUR_LOGIN",

# submit the form and save as a new session
session <- submit_form(my_session, filled_form) 

# If successful and redirected, you can then get the URL
1 Like

Unfortunately this suggested approach does not work, due to the redirect. It seems my solution probably lies with the RSelenium package, which can do anything a browser can do, though I don't yet have a solution.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.