Skip to content

Instantly share code, notes, and snippets.

@sproctor
Created March 23, 2022 22:41
Show Gist options
  • Save sproctor/da7ca16e206dc664e043e1d44d7d16ad to your computer and use it in GitHub Desktop.
Save sproctor/da7ca16e206dc664e043e1d44d7d16ad to your computer and use it in GitHub Desktop.
val code = suspendCancellableCoroutine { continuation ->
val server = HttpServer.create(InetSocketAddress(5789), 0)
server.createContext("/callback") { http ->
val parameters = http.requestURI.query?.let { decodeQueryString(it) }
val code = parameters?.get("code") ?: throw RuntimeException("Received a response with no code")
sendResponse(http)
continuation.resume(code)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment