R/auth.R

.slidesEnv <- new.env(parent = emptyenv())
.slidesEnv$Token <- NULL

# Set token to environment
set_token <- function(value) {
  .slidesEnv$Token <- value
  return(value)
}

# Get token from environment
get_token <- function() {
  .slidesEnv$Token
}


#' Authorize R package to access Github API
#' @description This is a function to authorize the R package to access
#' @importFrom httr oauth_app oauth_endpoints oauth2.0_token
#' @export
authorize <- function(client.id = getOption("github.client.id"),
                      client.secret = getOption("github.client.secret")){
  app <- oauth_app(appname = "github", key = client.id, secret = client.secret)
  endpoint <- oauth_endpoints("github")
  token <- oauth2.0_token(endpoint = endpoint, app = app,
                          scope = c("repo"))
  set_token(token)
  return(invisible(token))
}
hairizuanbinnoorazman/githubR documentation built on May 17, 2019, 2:25 p.m.