# HG changeset patch # User Kim Alvefur # Date 1677797949 -3600 # Node ID 7c531137a5532b4960cd70fdbfcaad4ae40d3a74 # Parent 6a3c1febd7beb35f952fbb30296335a2f7547168 mod_http_oauth2: Implement OOB special redirect URI in code flow Aka "copy and paste this into your client" diff -r 6a3c1febd7be -r 7c531137a553 mod_http_oauth2/mod_http_oauth2.lua --- a/mod_http_oauth2/mod_http_oauth2.lua Thu Mar 02 23:57:29 2023 +0100 +++ b/mod_http_oauth2/mod_http_oauth2.lua Thu Mar 02 23:59:09 2023 +0100 @@ -119,7 +119,20 @@ return {status_code = 429}; end - local redirect = url.parse(params.redirect_uri or client.redirect_uri); + local redirect_uri = params.redirect_uri or client.redirect_uri; + if redirect_uri == "urn:ietf:wg:oauth:2.0:oob" then + -- TODO some nicer template page + local response = { status_code = 200; headers = { content_type = "text/plain" } } + response.body = module:context("*"):fire_event("http-message", { + response = response; + title = "Your authorization code"; + message = "Here's your authorization code, copy and paste it into your app:"; + extra = code; + }) or ("Here's your authorization code:\n%s\n"):format(code); + end + + local redirect = url.parse(redirect_uri); + local query = http.formdecode(redirect.query or ""); if type(query) ~= "table" then query = {}; end table.insert(query, { name = "code", value = code })