get_token: Get OAuth1.0 Token

View source: R/get_token.R

get_tokenR Documentation

Get OAuth1.0 Token

Description

Authorize access to Trello API, required for private boards and write access (see details).

Usage

get_token(
  app = NULL,
  key = NULL,
  secret = NULL,
  scope = c("read", "write", "account"),
  expiration = c("30days", "1day", "1hour", "never"),
  cache = getOption("httr_oauth_cache"),
  appname
)

Arguments

app

A string, NULL or a Token.

  • If key and secret are set, a new token will be initialized and its name set to this value. A meaningful name can help you to spot your token on the settings page ⁠https://trello.com/username/account⁠. A token cannot be initialized without a name, so it will default to "trello-app" if it needs to.

  • If key and secret are not set, the value of app will be used as a path from which an existing token is read. If NULL, the token will be read from the working directory. NULL is returned if nothing is found.

  • If a Token, return as is.

key, secret

Developer credentials from ⁠https://trello.com/app-key⁠ (see details). If NULL and a cache file exists, the newest token is read from it, otherwise an error is thrown.

scope

Can be one or several of "read", "write" or "account". Defaults to "read".

expiration

Can be "1hour", "1day", "30days" or "never". Defaults to "30days".

cache

Passed to httr::oauth1.0_token(). Can specify whether the token should be cached locally (will ask the first time and then TRUE by default) or choose an alternative path for the cache file.

appname

Deprecated, use app.

Value

An object of class "Trello_API_token" (a Token).

Getting developer access

To access private data, a secure token is required. In order to create it, you will need your developer key and secret which you can get by visiting ⁠https://trello.com/app-key⁠ after logging in to Trello. You may also want to set at least one allowed origin there. If you are using trelloR locally (ie. from your laptop or PC), ⁠http://localhost:1410⁠ is a good value to use.

Creating tokens

Once back in R, run this function the following way:

my_token = get_token("my_app", key = key, secret = secret)

passing the values you have obtained on the developer page. First time you create a token, you will be prompted to confirm the authorization in a browser. If you chose to store the token locally as prompted, you won't have to do this anymore until your token expires (see expiration) or your local cache file is deleted.

Tokens are stored inside a hidden .httr-oauth cache file and automatically read when any function in the package is called. Optionally, you can specify a different cache path using the cache argument, or avoid caching the token completely with cache = FALSE. See httr::oauth1.0_token() for details.

If you opt out of storing the token, then it will only be held until your R session is over, and you will have to pass it to the token argument, eg. get_my_boards(token = my_token) each time you are fetching data.

Remember to store your credentials in a secure, non-shared location. To minimize the risk of unwanted disclosure when using remote code repositories, .httr-oauth (or whatever cache path you have specified using the cache argument) is automatically added to .gitignore.

See Also

httr::oauth_app(), httr::oauth_endpoint(), httr::oauth1.0_token()

Examples

# This example assumes you are reading your key and secret from environment
# variables. This is not obligatory, but wherever you read them from, make
# sure it is a secure, non-shared location.

## Not run: 

key = Sys.getenv("MY_TRELLO_KEY")
secret = Sys.getenv("MY_TRELLO_SECRET")

token = get_token("my_app", key = key, secret = secret,
                  scope = c("read", "write"))

## End(Not run)

trelloR documentation built on Aug. 28, 2023, 1:07 a.m.