LocalhostBrowserRedirectHandler

class LocalhostBrowserRedirectHandler @JvmOverloads constructor(port: Int, path: String, timeoutMs: Long = DEFAULT_TIMEOUT_MS, successResponse: String = DEFAULT_SUCCESS_RESPONSE, browserLauncher: (String) -> Unit = Companion::defaultBrowserLauncher) : BrowserRedirectHandler

A BrowserRedirectHandler implementation for JVM that starts a localhost HTTP server, opens the system browser, and captures the redirect callback.

The port and path must match the redirect URI registered in the Okta admin console. For example, if registered as http://localhost:8080/callback, use port = 8080 and path = "/callback".

Parameters

port

the port to listen on. Must match the port in the registered redirect URI.

path

the expected callback path. Must match the path in the registered redirect URI.

timeoutMs

the maximum time in milliseconds to wait for the redirect. Defaults to 5 minutes.

successResponse

the raw HTTP response written back to the browser after the callback is captured. Defaults to DEFAULT_SUCCESS_RESPONSE, a plain HTML page telling the user to close the window. Override to show custom branding or to issue a redirect, e.g.: "HTTP/1.1 302 Found\r\nLocation: https://app.example.com/done\r\n\r\n".

browserLauncher

opens the given URL in a browser. Defaults to Desktop.browse.

Constructors

Link copied to clipboard
constructor(port: Int, path: String, timeoutMs: Long = DEFAULT_TIMEOUT_MS, successResponse: String = DEFAULT_SUCCESS_RESPONSE, browserLauncher: (String) -> Unit = Companion::defaultBrowserLauncher)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun handleRedirect(url: String): String

Opens the given URL in a browser and suspends until the redirect callback is captured.