token handling overhaul #132
Replies: 5 comments 4 replies
-
@elipousson i'd love to know your thoughts on this and if it would get closer to allaying some of your qualms. This still does not get to the persisting tokens across sessions problem, but it does do a fair bit to ensuring more internal consistency and type checking. |
Beta Was this translation helpful? Give feedback.
-
This all seems promising! One possible addition: I noticed the other day that I could write the httr2 token object to disk as an rds file, restart the session, read the file back in, and the token still worked. You could stash the token in a user cache directory and encrypt the file using the built-in httr2 secret handling functions https://httr2.r-lib.org/reference/secrets.html |
Beta Was this translation helpful? Give feedback.
-
Confirmed that we need to use |
Beta Was this translation helpful? Give feedback.
-
The major part of this has been fixed and is on CRAN. |
Beta Was this translation helpful? Give feedback.
-
I'm having difficulty generating a valid token for interactive use using the R version 4.2.0 (2022-04-22 ucrt) locale: attached base packages: other attached packages: loaded via a namespace (and not attached): THIS TOKEN WORKS:
THIS TOKEN DOES NOT WORK:
API CALL AND ERROR MESSAGE:
I've tried running the non-interactive token in separate sessions within R-Studio, and also run via RScript using a batch file trigger. I get the same error either way. If you have any insight into what could be causing the token to fail, or how to troubleshoot this further, I would greatly appreciate it. Thanks for developing this great package for R users! |
Beta Was this translation helpful? Give feedback.
-
I think the state of functionality of arcgislayers is stable enough that we can begin rejiggering the internals. This discussion is scoped on ensuring there is consistency in which the way that tokens are handled by the
{arcgis}
location services family of packages (consisting of only arcgisutils and arcgislayers, today).Some notable issues are:
httr2_token
but are set as character scalars usingset_auth_token()
arc_open()
andarc_select()
X-Esri-Authorization: Bearer {token}
(note that this has the potential to be a security issue)Improving boilerplate
I think a first step is to adapt @elipousson's
arc_request()
(#129 (comment)) function to be a little bit more bare bones. This would be used to create a basic request from a url that has the minimum that we need for each request: the authorization header and the the user-agent. Having a function for this would ensure that basic requirements are fulfilled.httr2::request()
arc_agent()
In addition to make sure boiler plate is handled cleanly by having a standardized base-request function, there's issue of handling tokens.
Token Generation and Storing
@mmachir first brought up the issue of managing multiple portal credentials almost a year ago #15 and this was brought up again by @elipousson in #128 (comment). Notably:
Issue with environment variables
Environment variables are a good solution when we're working with API keys since the key is a scalar character. But in our case, we're working with OAuth tokens which are much more complex. OAuth tokens are represented as list objects with info on the token itself, its expiry, a refresh token and its expiry, and other metadata.
Environment variables are limiting in that they can be only scalars! So? How can we solve this? I think one way that could be use an R environment. We could create an environment in the package that is globally available:
Then we when we set a token, we would set it into the environment. The default token in the environment would be called
ARCGIS_TOKEN
, but we could also support any arbitrarily named tokens being set into the environment.arc_token()
would then let us grab a token by name from the environment.Help functions for the below
We can then use a new version of
arc_token()
to fetch items out of the environment:Here's what this mock up looks like:
Beta Was this translation helpful? Give feedback.
All reactions