New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use httpuv for oauth_listener #32

Closed
hadley opened this Issue May 13, 2013 · 2 comments

Comments

Projects
None yet
1 participant
@hadley
Member

hadley commented May 13, 2013

Currently, oauth_listener uses the built in httpd server which has the limitation that if help has already been started you can not change the port. Switching to httpuv would remedy this (and the blocking nature of httpuv might actually be an advantage). It should be a simple switch given that httpuv supports Rook.

@hadley

This comment has been minimized.

Member

hadley commented May 13, 2013

Code might look something like:

info <- NULL
listen <- function(env) {
  info <<- req$params()

  res <- Response$new()
  res$header("Content-type", "text/plain")
  res$write("Authentication complete - you can now close this page and ")
  res$write("return to R.")
  res$finish()
}

message("Waiting for authentication in browser...")
BROWSE(request_url)

server <- startServer("127.0.0.1", port, list(call = listen))
tryCatch(service(2000), finally = stopServer(server))

if (is.null(info)) {
  stop("Server failed to respond in 2 seconds", call. = FALSE)
}
message("Authentication complete.")
@hadley

This comment has been minimized.

Member

hadley commented May 13, 2013

Actually that will only catch one event, so need to do:

while(is.null(info)) {
  service(100)
  Sys.sleep(0.001)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment