From afd8bd958355b4f3242e56e3ad0d50e2792705c7 Mon Sep 17 00:00:00 2001 From: Arthur Shaw <47256431+arthur-shaw@users.noreply.github.com> Date: Tue, 2 Nov 2021 08:57:54 -0400 Subject: [PATCH] Check credentials by getting API user's details rather than fetching workspaces it can access The former only requires simple API access for the workspace. The latter requires admin API access. --- R/authenticate.R | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/R/authenticate.R b/R/authenticate.R index 23cd389..7ae9206 100644 --- a/R/authenticate.R +++ b/R/authenticate.R @@ -130,28 +130,33 @@ check_credentials <- function( # by making getting the workspaces for which the user is authorized } else { - workspaces_df <- tryCatch( + credentials_valid <- tryCatch( error = function(cnd) { - data.frame(Name = NA_character_) + FALSE }, - susoapi::get_workspaces(server = server, user = user, password = password) + is.data.frame( + suppressMessages( + susoapi::get_user_details( + user_id = user, + server = server, + workspace = workspace, + user = user, + password = password + ) + ) + ) ) - workspaces_names <- workspaces_df$Name - - credentials_valid <- (workspace %in% workspaces_names) - if (credentials_valid == TRUE) { - workspaces_list <- glue::glue_collapse(glue::backtick(workspaces_names), sep = ", ", last = "and ") - message(glue::glue("Credentials valid for workspace(s) {workspaces_list}.")) + message(glue::glue("Credentials valid for workspace `{workspace}`.")) } else { message(glue::glue( "Credentials invalid for workspace {glue::backtick(workspace)}.", "Here are some steps to troubleshoot.", "First, `show_credentials()` to view the credentials.", "If they are incorrect, use use `set_credentials()` to correct them.", - "Next, check which workspace(s) the user can access.", - "To do so, use `get_workspaces()`.", + "Next, as server admin, check which workspace(s) the user can access.", + "If the target workspace cannot be accessed by the user, add the user.", .sep = "\n" ))