
Tools for handling GitHub personal access tokens (PAT)
Source:R/github_rate_limit.R, R/github_token.R
github_token.Rdgithub_get_token- returns the user's GitHub personal access token (PAT).github_set_token- defines the user's GitHub PAT by setting theGITHUB_PATenvironmental variable. This value will persist until the session ends orgihub_reset_token()is called.github_reset_token- removes the value stored in theGITHUB_PATenvironmental variable.github_test_token- checks if a PAT is valid by attempting to authenticate with the GitHub API.github_token_scopes- returns a vector of scopes granted to the token.
Usage
github_rate_limit()
github_graphql_rate_limit()
github_get_token()
github_set_token(token)
github_reset_token()
github_test_token(token = github_get_token())
github_token_scopes(token = github_get_token())Value
github_get_token() returns the current PAT as a character string with the gh_pat
class. See gh::gh_token() for additional details.
github_set_token() and github_reset_token() return the result of Sys.setenv() and
Sys.unsetenv() respectively.
github_test_token() invisibly returns a logical value, TRUE if the test passes,
FALSE if not.
github_token_scopes() returns a character vector of granted scopes.
Details
This package looks for the personal access token (PAT) in the following places (in order):
Value of
GITHUB_PATenvironmental variable.Any GitHub PAT token(s) stored with
gitcredsviagitcreds_set().
For additional details on creating a GitHub PAT see the usethis vignette on Managing Git(Hub) Credentials. For those who do not wish to read the entire article, the quick start method is to use:
usethis::create_github_token()- to create the token and then,gitcreds::gitcreds_set()- to securely cache the token.