1010
1111KAGGLE_USER_SECRETS_TOKEN <- Sys.getenv(" KAGGLE_USER_SECRETS_TOKEN" )
1212KAGGLE_BASE_URL <- Sys.getenv(" KAGGLE_URL_BASE" )
13- GET_USER_SECRET_ENDPONT = " /requests/GetUserSecretRequest"
13+ GET_USER_SECRET_ENDPOINT = " /requests/GetUserSecretRequest"
1414
1515# We create a Token2.0 Credential object (from httr library) and use bigrquery's set_access_cred
1616# to override the interactive authentication (https://github.com/r-dbi/bigrquery/blob/master/R/auth.R).
@@ -27,8 +27,15 @@ TokenBigQueryKernel <- R6::R6Class("TokenBigQueryKernel", inherit = Token2.0, li
2727 if (KAGGLE_USER_SECRETS_TOKEN == ' ' ) {
2828 stop(" Expected KAGGLE_USER_SECRETS_TOKEN environment variable to be present." , call. = FALSE )
2929 }
30- request_body <- list (JWE = KAGGLE_USER_SECRETS_TOKEN , Target = 1 )
31- response <- POST(paste0(KAGGLE_BASE_URL , GET_USER_SECRET_ENDPONT ), body = request_body , encode = " json" )
30+ request_body <- list (Target = 1 )
31+ auth_header <- paste0(" Bearer " , KAGGLE_USER_SECRETS_TOKEN )
32+ headers <- add_headers(c(" X-Kaggle-Authorization" = auth_header ))
33+ response <- POST(paste0(KAGGLE_BASE_URL , GET_USER_SECRET_ENDPOINT ),
34+ headers ,
35+ # Reset the cookies on each request, since the server expects none.
36+ handle = handle(' ' ),
37+ body = request_body ,
38+ encode = " json" )
3239 if (http_error(response ) || ! identical(content(response )$ wasSuccessful , TRUE )) {
3340 err <- paste(" Unable to refresh token. Please ensure you have a connected BigQuery account. Error: " ,
3441 paste(content(response , " text" , encoding = ' utf-8' )))
0 commit comments