## ----eval = FALSE-------------------------------------------------------------
# library(shiny)
# library(shinyOAuth)
# 
# provider <- oauth_provider_github()
# 
# client <- oauth_client(
#   provider = provider,
#   client_id = Sys.getenv("GITHUB_OAUTH_CLIENT_ID"),
#   client_secret = Sys.getenv("GITHUB_OAUTH_CLIENT_SECRET"),
#   redirect_uri = "http://127.0.0.1:8100",
#   scopes = c("read:user", "user:email")
# )
# 
# ui <- fluidPage(
#   # Include JavaScript dependency:
#   use_shinyOAuth(),
#   # Render login status & user info:
#   uiOutput("login")
# )
# 
# server <- function(input, output, session) {
#   auth <- oauth_module_server("auth", client, auto_redirect = TRUE)
#   output$login <- renderUI({
#     if (auth$authenticated) {
#       user_info <- auth$token@userinfo
#       tagList(
#         tags$p("You are logged in!"),
#         tags$pre(paste(capture.output(str(user_info)), collapse = "\n"))
#       )
#     } else {
#       tags$p("You are not logged in.")
#     }
#   })
# }
# 
# runApp(
#   shinyApp(ui, server),
#   port = 8100,
#   launch.browser = FALSE
# )
# 
# # Open the app in your regular browser at http://127.0.0.1:8100
# # (viewers in RStudio/Positron/etc. cannot perform necessary redirects)

## ----eval = FALSE-------------------------------------------------------------
# library(shiny)
# library(shinyOAuth)
# 
# provider <- oauth_provider_github()
# 
# client <- oauth_client(
#   provider = provider,
#   client_id = Sys.getenv("GITHUB_OAUTH_CLIENT_ID"),
#   client_secret = Sys.getenv("GITHUB_OAUTH_CLIENT_SECRET"),
#   redirect_uri = "http://127.0.0.1:8100",
#   scopes = c("read:user", "user:email")
# )
# 
# ui <- fluidPage(
#   use_shinyOAuth(),
#   actionButton("login_btn", "Login"),
#   uiOutput("login")
# )
# 
# server <- function(input, output, session) {
#   auth <- oauth_module_server(
#     "auth",
#     client,
#     auto_redirect = FALSE
#   )
# 
#   observeEvent(input$login_btn, {
#     auth$request_login()
#   })
# 
#   output$login <- renderUI({
#     if (auth$authenticated) {
#       user_info <- auth$token@userinfo
#       tagList(
#         tags$p("You are logged in!"),
#         tags$pre(paste(capture.output(str(user_info)), collapse = "\n"))
#       )
#     } else {
#       tags$p("You are not logged in.")
#     }
#   })
# }
# 
# runApp(
#   shinyApp(ui, server),
#   port = 8100,
#   launch.browser = FALSE
# )
# 
# # Open the app in your regular browser at http://127.0.0.1:8100
# # (viewers in RStudio/Positron/etc. cannot perform necessary redirects)

## ----eval = FALSE-------------------------------------------------------------
# library(shiny)
# library(shinyOAuth)
# 
# provider <- oauth_provider_github()
# 
# client <- oauth_client(
#   provider = provider,
#   client_id = Sys.getenv("GITHUB_OAUTH_CLIENT_ID"),
#   client_secret = Sys.getenv("GITHUB_OAUTH_CLIENT_SECRET"),
#   redirect_uri = "http://127.0.0.1:8100",
#   scopes = c("read:user", "user:email")
# )
# 
# ui <- fluidPage(
#   use_shinyOAuth(),
#   uiOutput("ui")
# )
# 
# server <- function(input, output, session) {
#   auth <- oauth_module_server(
#     "auth",
#     client,
#     auto_redirect = TRUE
#   )
# 
#   repositories <- reactiveVal(NULL)
# 
#   observe({
#     req(auth$authenticated)
# 
#     # Example additional API request using the access token
#     # (e.g., fetch user repositories from GitHub)
#     resp <- perform_resource_req(
#       auth$token,
#       "https://api.github.com/user/repos"
#     )
# 
#     if (httr2::resp_is_error(resp)) {
#       repositories(NULL)
#     } else {
#       repos_data <- httr2::resp_body_json(resp, simplifyVector = TRUE)
#       repositories(repos_data)
#     }
#   })
# 
#   # Render username + their repositories
#   output$ui <- renderUI({
#     if (isTRUE(auth$authenticated)) {
#       user_info <- auth$token@userinfo
#       repos <- repositories()
# 
#       return(tagList(
#         tags$p(paste("You are logged in as:", user_info$login)),
#         tags$h4("Your repositories:"),
#         if (!is.null(repos)) {
#           tags$ul(
#             Map(function(url, name) {
#               tags$li(tags$a(href = url, target = "_blank", name))
#             }, repos$html_url, repos$full_name)
#           )
#         } else {
#           tags$p("Loading repositories...")
#         }
#       ))
#     }
# 
#     return(tags$p("You are not logged in."))
#   })
# }
# 
# runApp(
#   shinyApp(ui, server),
#   port = 8100,
#   launch.browser = FALSE
# )
# 
# # Open the app in your regular browser at http://127.0.0.1:8100
# # (viewers in RStudio/Positron/etc. cannot perform necessary redirects)

## ----eval = FALSE-------------------------------------------------------------
# library(shiny)
# library(shinyOAuth)
# 
# provider <- oauth_provider_keycloak(
#   base_url = "http://localhost:8080",
#   realm = "shinyoauth"
# )
# 
# client <- oauth_client(
#   provider = provider,
#   client_id = "shiny-public",
#   client_secret = "",
#   # `/callback` is only an example sub-route. The app root also works if the
#   # provider redirect URI matches the path handled by `oauth_form_post_ui()`
#   redirect_uri = "http://127.0.0.1:8100/callback",
#   scopes = c("openid", "profile", "email"),
#   response_mode = "form_post"
# )
# 
# base_ui <- fluidPage(
#   uiOutput("login")
# )
# 
# ui <- oauth_form_post_ui(base_ui, id = "auth", client = client)
# 
# server <- function(input, output, session) {
#   auth <- oauth_module_server("auth", client, auto_redirect = TRUE)
# 
#   output$login <- renderUI({
#     if (auth$authenticated) {
#       tagList(
#         tags$p("You are logged in!"),
#         tags$pre(paste(capture.output(str(auth$token@userinfo)), collapse = "\n"))
#       )
#     } else {
#       tags$p("You are not logged in.")
#     }
#   })
# }
# 
# runApp(
#   shinyApp(ui, server, uiPattern = ".*"),
#   port = 8100,
#   launch.browser = FALSE
# )
# 
# # Open the app in your regular browser at http://127.0.0.1:8100
# # (viewers in RStudio/Positron/etc. cannot perform necessary redirects)

