10
10
11
11
KAGGLE_USER_SECRETS_TOKEN <- Sys.getenv(" KAGGLE_USER_SECRETS_TOKEN" )
12
12
KAGGLE_BASE_URL <- Sys.getenv(" KAGGLE_URL_BASE" )
13
- GET_USER_SECRET_ENDPONT = " /requests/GetUserSecretRequest"
13
+ GET_USER_SECRET_ENDPOINT = " /requests/GetUserSecretRequest"
14
14
15
15
# We create a Token2.0 Credential object (from httr library) and use bigrquery's set_access_cred
16
16
# 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
27
27
if (KAGGLE_USER_SECRETS_TOKEN == ' ' ) {
28
28
stop(" Expected KAGGLE_USER_SECRETS_TOKEN environment variable to be present." , call. = FALSE )
29
29
}
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" )
32
39
if (http_error(response ) || ! identical(content(response )$ wasSuccessful , TRUE )) {
33
40
err <- paste(" Unable to refresh token. Please ensure you have a connected BigQuery account. Error: " ,
34
41
paste(content(response , " text" , encoding = ' utf-8' )))
0 commit comments