arc_token {arcgisutils} | R Documentation |
Manage authorization tokens
Description
These functions are used to set, fetch, and check authorization tokens.
Usage
arc_token(token = "ARCGIS_TOKEN")
set_arc_token(token, ...)
unset_arc_token(token = NULL)
obj_check_token(token, call = rlang::caller_env())
check_token_has_user(token, call = rlang::caller_env())
Arguments
token |
for |
... |
named arguments to set |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
Details
It is possible to have multiple authorization tokens in one session. These functions assist you in managing them.
arc_token()
is used to fetch tokens by name. The default token is ARCGIS_TOKEN
.
However, they can be any valid character scalar. set_arc_token()
will create
store a token with the name ARCGIS_TOKEN
. However, you can alternatively
set the tokens by name using a key-value pair. The key is what you would pass
to arc_token()
to fetch the httr2_token
object. To remove a token that has
been set, use unset_arc_token()
.
obj_check_token()
is a developer oriented function that can be used to check
if an object is indeed an httr2_token
. To check if a token has expired,
validate_or_refresh_token()
will do so.
check_token_has_user()
is a developer oriented function that checks to see
if a token has a username
field associated with it.
For developers:
set_arc_token()
uses a package level environment to store the tokens. The
tokens are fetched from the environment using arc_token()
.
Examples
# create fake tokens
token_a <- httr2::oauth_token("1234", arcgis_host = arc_host())
token_b <- httr2::oauth_token("abcd", arcgis_host = arc_host())
# set token to the default location
set_arc_token(token_a)
# fetch token from the default location
arc_token()
# set token by name
set_arc_token(org_a = token_a, org_b = token_b)
# fetch token by name
arc_token("org_a")
arc_token("org_b")
# unset tokens
unset_arc_token()
unset_arc_token(c("org_a", "org_b"))