R/myTarRefreshToken.R

Defines functions myTarRefreshToken

Documented in myTarRefreshToken

myTarRefreshToken <-
function(old_auth = NULL, client_id = NULL,client_secret = NULL){
  if(is.null(old_auth) | is.null(client_id) | is.null(client_secret)){
    
    stop("All arguments is require!!!",call. = FALSE)
  }
  query_body <- paste0("grant_type=", "refresh_token",
                       "&refresh_token=", old_auth$refresh_token,
                       "&client_id=", client_id,
                       "&client_secret=", client_secret)
  
  mtRefrsh <- POST(stringr::str_interp("${getOption('rmytarget.url')}api/v2/oauth2/token.json"),body = query_body, content_type(type = "application/x-www-form-urlencoded"))
  stop_for_status(mtRefrsh)
  mtRefrsh <- content(mtRefrsh, "parsed", "application/json")
  
  old_auth$access_token <- mtRefrsh$access_token
  return(old_auth)
}
maraevdima/rmytarget documentation built on May 26, 2019, 6:56 p.m.