R/auth.R

Defines functions gtm_auth

Documented in gtm_auth

#' Authenticate this session
#'
#' A wrapper for \link[googleAuthR]{gar_auth} and \link[googleAuthR]{gar_auth_service}
#'
#' @param new_user If TRUE, reauthenticate via Google login screen
#' @param no_auto Will ignore auto-authentication settings if TRUE
#'
#' If you have set the environment variable \code{GCE_AUTH_FILE} to a valid file location,
#'   the function will look there for authentication details.
#' Otherwise it will look in the working directory for the `.httr-oauth` file, which if not present
#'   will trigger an authentication flow via Google login screen in your browser.
#'
#' If \code{GCE_AUTH_FILE} is specified, then \code{gce_auth()} will be called upon loading the package
#'   via \code{library(googleComputeEngineR)},
#'   meaning that calling this function yourself at the start of the session won't be necessary.
#'
#' \code{GCE_AUTH_FILE} can be either a token generated by \link[googleAuthR]{gar_auth} or
#'   service account JSON ending with file extension \code{.json}
#'
#' @return Invisibly, the token that has been saved to the session
#' @import googleAuthR
#' @export
gtm_auth <- function(new_user = FALSE, no_auto = FALSE){
  
  required_scopes <- c("https://www.googleapis.com/auth/tagmanager.readonly",
                       "https://www.googleapis.com/auth/tagmanager.edit.containers")
  
  googleAuthR::gar_auto_auth(required_scopes,
                             new_user = new_user,
                             no_auto = no_auto,
                             environment_var = "",
                             travis_environment_var = "")
}


## store bucket name
.gce_env <- new.env(parent = emptyenv())
MarkEdmondson1234/gtmR documentation built on Dec. 9, 2020, 3:26 a.m.