From 3417860210c8aa8bd7e96efe47ae635c9d9d3781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Li=C3=A9tar?= Date: Wed, 11 Sep 2024 17:19:13 +0100 Subject: [PATCH] Don't use interactive for oauth --- R/location_packit.R | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/R/location_packit.R b/R/location_packit.R index 2a1ff671..b169ca03 100644 --- a/R/location_packit.R +++ b/R/location_packit.R @@ -10,13 +10,23 @@ github_oauth_client <- function() { } do_oauth_device_flow <- function(base_url) { - res <- httr2::oauth_token_cached( - client = github_oauth_client(), - flow = httr2::oauth_flow_device, - flow_params = list( - auth_url = "https://github.com/login/device/code", - scope = "read:org"), - cache_disk = TRUE) + # httr2 has a pretty unintuitive output when running interactively. + # It waits for the user to press and then opens up a browser, but the + # wording isn't super clear. It also does not work at all if a browser can't + # be opened, eg. in an SSH session. + # + # Thankfully, if we pretend to not be interactive the behaviour is a lot more + # obvious. It will just print the link to the console and with instructions + # for the user to open it up. + res <- rlang::with_interactive(value = FALSE, { + httr2::oauth_token_cached( + client = github_oauth_client(), + flow = httr2::oauth_flow_device, + flow_params = list( + auth_url = "https://github.com/login/device/code", + scope = "read:org"), + cache_disk = TRUE) + }) res$access_token }