Does the googledrive package support pkce flow?

Hello first timer here,

I'm working on a project and we were wondering if it is possible to use the googledrive package with a pkce (Proof Key for Code Exchange) flow, which is an extension fo OAuth2.0. Maybe someone here has run into this issue before?

Security is not really my background, and I have searched in the documentation and git and found nothing...

Hoping to maybe find an answer, and if i'm lucky an exemple on how to implement this (if it does support the flow).

Thanks in advance for any help you can provide!

All I found is the function below—ee_Authenticate() in the {rgee} package that could be adapted. Use the code_verifier argument for pkce token. I haven't tested this, because I don't use googledrive or Google Drive.

function (user = NULL, earthengine = TRUE, drive = FALSE, gcs = FALSE, 
    authorization_code = NULL, code_verifier = NULL, auth_mode = "notebook", 
    scopes = NULL, quiet = FALSE, verbose = TRUE) 
{
    sdkpath <- sprintf("%s/google-cloud-sdk/bin/", Sys.getenv("HOME"))
    if (!grepl(sdkpath, Sys.getenv("PATH"))) {
        Sys.setenv(PATH = sprintf("%s:%s", Sys.getenv("PATH"), 
            sdkpath))
    }
    init <- ee_check_init()
    ee_utils <- init$ee_utils
    if (is.null(user)) {
        ee_path <- ee_utils_py_to_r(ee_utils$ee_path())
        ee_path_user <- ee_path
    }
    else {
        ee_path <- ee_utils_py_to_r(ee_utils$ee_path())
        ee_path_user <- sprintf("%s/%s", ee_path, user)
    }
    if (!is.null(user)) {
        ee_create_user_subfolder(ee_utils, user)
    }
    if (earthengine) {
        unlink(sprintf("%s/credentials", ee_path_user))
        if (verbose) 
            ee_message_04(init = TRUE)
        auth_params <- list(authorization_code = authorization_code, 
            code_verifier = code_verifier, scopes = scopes)
        ee_create_credentials_earthengine(user, auth_mode, quiet, 
            ee_utils, auth_params)
        if (verbose) 
            ee_message_04(init = FALSE)
    }
    if (drive) {
        ee_check_packages("ee_Initialize", "googledrive")
        full_credentials <- list.files(path = ee_path_user, full.names = TRUE)
        drive_condition <- grepl(".*_.*@.*", basename(full_credentials))
        unlink(full_credentials[drive_condition])
        if (verbose) 
            ee_message_02(init = TRUE)
        drive_credentials <- ee_create_credentials_drive(user, 
            ee_utils, quiet = verbose)
        test_drive_privileges(user)
        if (verbose) 
            ee_message_02(init = FALSE)
    }
    if (gcs) {
        ee_check_packages("ee_Initialize", "googleCloudStorageR")
        if (verbose) 
            ee_message_03(init = TRUE, gcs_credentials)
        gcs_credentials <- ee_create_credentials_gcs(user = user, 
            ee_utils)
        if (verbose) {
            ee_message_03(init = FALSE, gcs_credentials = gcs_credentials)
            if (is.na(gcs_credentials[["path"]])) {
                message(gcs_credentials[["message"]])
            }
        }
    }
    if (verbose) {
        message("credentials are cached in the path: ", ee_path_user)
    }
    invisible(TRUE)
}

Thank You, I will look into this

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.