diff --git a/NEWS.md b/NEWS.md index 968f5fe..0f373a5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # AzureAuth 1.2.1 * Pass the resource and scope as explicit parameters to the AAD endpoint when refreshing a token. Among other things, this allows using a refresh token from one resource to obtain an access token for another resource. +* Use `utils::askYesNo` for prompts, eg when creating the AzureR caching directory and deleting tokens; this fixes a bug in reading the input. As a side-effect, Windows users who are using RGUI.exe will see a popup dialog box instead of a message in the terminal. # AzureAuth 1.2.0 diff --git a/R/AzureAuth.R b/R/AzureAuth.R index 99dd9ae..695228d 100644 --- a/R/AzureAuth.R +++ b/R/AzureAuth.R @@ -15,11 +15,11 @@ make_AzureR_dir <- function() AzureR_dir <- AzureR_dir() if(!dir.exists(AzureR_dir) && interactive()) { - yn <- readline(paste0( + ok <- askYesNo(paste0( "The AzureR packages can save your authentication credentials in the directory:\n\n", AzureR_dir, "\n\n", - "This saves you having to re-authenticate with Azure in future sessions. Create this directory? (Y/n) ")) - if(tolower(substr(yn, 1, 1)) == "n") + "This saves you having to re-authenticate with Azure in future sessions. Create this directory?")) + if(!isTRUE(ok)) return(invisible(NULL)) dir.create(AzureR_dir, recursive=TRUE) diff --git a/R/token.R b/R/token.R index 457daae..dd63070 100644 --- a/R/token.R +++ b/R/token.R @@ -256,8 +256,8 @@ delete_azure_token <- function(resource, tenant, app, password=NULL, username=NU if(confirm && interactive()) { - yn <- readline(paste0("Do you really want to delete this Azure Active Directory token? (y/N) ")) - if(tolower(substr(yn, 1, 1)) != "y") + ok <- askYesNo("Do you really want to delete this Azure Active Directory token?", FALSE) + if(!isTRUE(ok)) return(invisible(NULL)) } file.remove(file.path(AzureR_dir(), hash)) @@ -274,8 +274,8 @@ clean_token_directory <- function(confirm=TRUE) if(confirm && interactive()) { - yn <- readline(paste0("Do you really want to delete ALL saved Azure Active Directory tokens? (y/N) ")) - if(tolower(substr(yn, 1, 1)) != "y") + ok <- askYesNo("Do you really want to delete ALL saved Azure Active Directory tokens?", FALSE) + if(!isTRUE(ok)) return(invisible(NULL)) } toks <- dir(AzureR_dir(), pattern="^[0-9a-f]{32}$", full.names=TRUE)