This can be used to call authenticated services such as Cloud Run.

cr_jwt_create(the_url, service_json = Sys.getenv("GCE_AUTH_FILE"))

cr_jwt_token(signed_jwt, the_url)

cr_jwt_with_httr(req, token)

cr_jwt_with_curl(h = curl::new_handle(), token)

cr_jwt_async(urls, token, ...)



The URL of the service you want to call


The account service key JSON that will be used to generate the JWT


A JWT created from cr_jwt_create


A httr request to the service running on the_url, using httr verbs such as GET


The token created via cr_jwt_token


A curl handle such as set with new_handle


URLs to request asynchronously


Other arguments passed to new_handle


For certain Google services a JWT is needed to authenticate access, which is distinct from OAuth2. An example of this is authenticated Cloud Run such as deployed when using cr_run and parameter allowUnauthenticated = FALSE. These functions help you call your services by generating the JWT from your service account key.

The token is set to expire in 1 hour, so it will need refreshing before then by calling this function again.

See also


if (FALSE) { # The private authenticated access only Cloud Run service the_url <- "" # creating the JWT and token jwt <- cr_jwt_create(the_url) token <- cr_jwt_token(jwt, the_url) # call Cloud Run app using token with any httr verb library(httr) res <- cr_jwt_with_httr( GET(""), token) content(res) # call Cloud Run app with curl - you can pass in a curl handle library(curl) h <- new_handle() handle_setopt(h, customrequest = "PUT") handle_setform(h, a = "1", b = "2") h <- cr_jwt_with_curl(h, token = token) r <- curl_fetch_memory("", h) cat(rawToChar(r$content)) # use curls multi-asynch functions many_urls <- paste0("", paste0("?param="),1:6) cr_jwt_async(many_urls, token = token) }