You can read more about PATs here: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ and you can access your PATs here (if logged in to GitHub): https://github.com/settings/tokens.
gh_token(api_url = NULL)
Github API url. Defaults to GITHUB_API_URL
environment variable if set, otherwise https://api.github.com.
A string, with the token, or a zero length string scalar, if no token is available.
gh supports storing your PAT in the system keyring, on Windows, macOS
and Linux, using the keyring package. To turn on keyring support, you
need to set the GH_KEYRING
environment variables to true
, in your
.Renviron
file or profile.
If keyring support is turned on, then for each PAT environment variable,
gh first checks whether the key with that value is set in the system
keyring, and if yes, it will use its value as the PAT. I.e. without a
custom GITHUB_API_URL
variable, it checks the
GITHUB_PAT_API_GITHUB_COM
key first, then the env var with the same
name, then the GITHUB_PAT
key, etc. Such a check looks like this:
keyring::key_get("GITHUB_PAT_API_GITHUB_COM")
and it uses the default keyring backend and the default keyring within
that backend. See keyring::default_backend()
for details and changing
these defaults.
If the selected keyring is locked, and the session is interactive, then gh will try to unlock it. If the keyring is locked, and the session is not interactive, then gh will not use the keyring. Note that some keyring backends cannot be locked (e.g. the one that uses environment variables).
On some OSes, e.g. typically on macOS, you need to allow R to access the system keyring. You can allow this separately for each access, or for all future accesses, until you update or re-install R. You typically need to give access to each R GUI (e.g. RStudio) and the command line R program separately.
To store your PAT on the keyring run
keyring::key_set("GITHUB_PAT")
gh supports storing your PAT in the system keyring, on Windows, macOS
and Linux, using the keyring package. To turn on keyring support, you
need to set the GH_KEYRING
environment variables to true
, in your
.Renviron
file or profile.
If keyring support is turned on, then for each PAT environment variable,
gh first checks whether the key with that value is set in the system
keyring, and if yes, it will use its value as the PAT. I.e. without a
custom GITHUB_API_URL
variable, it checks the
GITHUB_PAT_API_GITHUB_COM
key first, then the env var with the same
name, then the GITHUB_PAT
key, etc. Such a check looks like this:
keyring::key_get("GITHUB_PAT_API_GITHUB_COM")
and it uses the default keyring backend and the default keyring within
that backend. See keyring::default_backend()
for details and changing
these defaults.
If the selected keyring is locked, and the session is interactive, then gh will try to unlock it. If the keyring is locked, and the session is not interactive, then gh will not use the keyring. Note that some keyring backends cannot be locked (e.g. the one that uses environment variables).
On some OSes, e.g. typically on macOS, you need to allow R to access the system keyring. You can allow this separately for each access, or for all future accesses, until you update or re-install R. You typically need to give access to each R GUI (e.g. RStudio) and the command line R program separately.
To store your PAT on the keyring run
keyring::key_set("GITHUB_PAT")
Set the GITHUB_PAT
environment variable to avoid having to include
your PAT in the code. If you work with multiple GitHub deployments,
e.g. via GitHub Enterprise, then read 'PATs for GitHub Enterprise' below.
If you want a more secure solution than putting authentication tokens into environment variables, read 'Storing PATs in the system keyring' below.
slugify_url()
for computing the environment variables that
gh uses to search for API URL specific PATs.