gh_token: Get a token for accessing GitHub

Description Usage Arguments Details Value Examples

View source: R/github-api.R

Description

This function initiates the OAuth authentication code grant flow with GitHub. The user will be redirected to GitHub's login page to enter a user name and password. Once complete the user can close the window and this function returns a token which can be used for all calls to the githapi API.

Usage

1
2
3
4
5
6
7
8
9
gh_token(
  token = getOption("github.token"),
  oauth = getOption("github.oauth"),
  proxy = getOption("github.proxy"),
  id = getOption("githapi.id"),
  secret = getOption("githapi.secret"),
  cache = getOption("githapi.cache"),
  refresh = FALSE
)

Arguments

token

(string, optional) A personal access token. If NULL then the OAuth process is triggered. Can be set in the github.token option or the GITHAPI_TOKEN, GITHUB_PAT, or GITHUB_TOKEN environment variable. Default: NULL.

oauth

(string, optional) The base URL for for the OAuth endpoint. Can be set in the github.oauth option or the GITHUB_OAUTH environment variable. Default: "https://github.com/login/oauth".

proxy

(character, optional) The proxy server to use to connect to the github API. If NULL then no proxy is used. Can be set in the option github.proxy or the environment variable GITHUB_PROXY. Default: NULL.

id

(string, optional) The application ID for accessing GitHub. Can be set in the githapi.id option or the GITHAPI_ID environment variable. Default: The id for the githapi application in github.com.

secret

(string, optional) The secret for the application to access GitHub. Can be set in the githapi.secret option or the GITHAPI_SECRET environment variable. Default: The secret for the githapi application in github.com

cache

(boolean or string, optional) The location to store a cached token. If TRUE the cache uses the httr default; if FALSE it does not cache. Can be set in the "githapi.cache" option or the GITHAPI_CACHE environment variable. Default: FALSE.

refresh

(boolean, optional) Whether to force the refresh of the cached token. Default: FALSE.

Details

For non-interactive processes a personal access token can be specified, either as an R option ("github.token") or as an environment variable (either GITHAPI_TOKEN, GITHUB_PAT, or GITHUB_TOKEN).

Value

A token which is either a string, for a personal access token, or a httr::Token object for an OAuth token.

Examples

1
2
3
4
5
6
## Not run: 

  token <- gh_token()


## End(Not run)

ChadGoymer/githapi documentation built on Oct. 22, 2021, 10:56 a.m.