R/authorize_from_secret.R

Defines functions authorize_from_secret

Documented in authorize_from_secret

#' Authorize from access token
#'
#' Get authorization from access token
#'
#' @param access_token
#'
#' @return factor
#' @export
#' @examples
#' token <- rgoogleslides::authorize()
#' token <- token$credentials$access_token
#' rgoogleslides::authorize(authorize_from_secret(token))
#'
authorize_from_secret <- function(access_token) {

  client_id <- getOption("slides.client.id")
  client_secret <- getOption("slides.client.secret")

  credentials = list(
    access_token = access_token,
    expires_in = 3599L,
    # refresh_token = refresh_token,
    scope = "https://www.googleapis.com/auth/presentations https://www.googleapis.com/auth/drive.readonly",
    token_type = "Bearer")

  app <- httr::oauth_app(appname = "googleslides", key = client_id,
                         secret = client_secret)
  endpoint <- httr::oauth_endpoints("google")

  token <- httr::oauth2.0_token(endpoint = endpoint, app = app,
                                scope = c("https://www.googleapis.com/auth/presentations",
                                          "https://www.googleapis.com/auth/drive.readonly"),
                                credentials = credentials)

  out <- rgoogleslides::authorize(token = token)

  return(out)
}
cansavvy/GoogleSlidesAutomatR documentation built on Dec. 19, 2021, 1:48 p.m.