Add runtime OAuth2 browser flow demos with httr and httr2
Change-Id: If244a6c6c68115f52125189445c30c167c61b13b
diff --git a/demo/OAuthBrowserflowHttr.R b/demo/OAuthBrowserflowHttr.R
new file mode 100644
index 0000000..47fccd1
--- /dev/null
+++ b/demo/OAuthBrowserflowHttr.R
@@ -0,0 +1,22 @@
+library(RKorAPClient)
+library(httr)
+library(kableExtra)
+library(dplyr)
+
+query = 'V\u00F6ner' # "Portable packages must use only ASCII characters in their demos. Use \uxxxx escapes for other characters."
+
+korap_app <-oauth_app("test-korap-client", key = "773NHGM76N7P9b6rLfmpM4", secret = NULL)
+korap_endpoint <- oauth_endpoint(NULL,
+ "settings/oauth/authorize",
+ "api/v1.0/oauth2/token",
+ base_url = "https://korap.ids-mannheim.de")
+token_bundle = oauth2.0_token(korap_endpoint, korap_app, scope = "search match_info", cache = FALSE)
+
+new("KorAPConnection", verbose = TRUE, accessToken = token_bundle[["credentials"]][["access_token"]]) %>%
+ corpusQuery(query, fields = c("textSigle", "pubDate", "corpusTitle", "snippet"),
+ metadataOnly = FALSE) %>%
+ fetchAll() %>%
+ slot("collectedMatches") %>%
+ dplyr::arrange(pubDate) %>%
+ kable(escape = FALSE, caption = paste0("Query hits for '", query, "' ordered by date of publication")) %>%
+ kable_styling()