Mercurial > prosody-modules
comparison mod_http_oauth2/mod_http_oauth2.lua @ 5188:7c531137a553
mod_http_oauth2: Implement OOB special redirect URI in code flow
Aka "copy and paste this into your client"
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 02 Mar 2023 23:59:09 +0100 |
parents | 6a3c1febd7be |
children | 4ee8eb1134a8 |
comparison
equal
deleted
inserted
replaced
5187:6a3c1febd7be | 5188:7c531137a553 |
---|---|
117 }); | 117 }); |
118 if not ok then | 118 if not ok then |
119 return {status_code = 429}; | 119 return {status_code = 429}; |
120 end | 120 end |
121 | 121 |
122 local redirect = url.parse(params.redirect_uri or client.redirect_uri); | 122 local redirect_uri = params.redirect_uri or client.redirect_uri; |
123 if redirect_uri == "urn:ietf:wg:oauth:2.0:oob" then | |
124 -- TODO some nicer template page | |
125 local response = { status_code = 200; headers = { content_type = "text/plain" } } | |
126 response.body = module:context("*"):fire_event("http-message", { | |
127 response = response; | |
128 title = "Your authorization code"; | |
129 message = "Here's your authorization code, copy and paste it into your app:"; | |
130 extra = code; | |
131 }) or ("Here's your authorization code:\n%s\n"):format(code); | |
132 end | |
133 | |
134 local redirect = url.parse(redirect_uri); | |
135 | |
123 local query = http.formdecode(redirect.query or ""); | 136 local query = http.formdecode(redirect.query or ""); |
124 if type(query) ~= "table" then query = {}; end | 137 if type(query) ~= "table" then query = {}; end |
125 table.insert(query, { name = "code", value = code }) | 138 table.insert(query, { name = "code", value = code }) |
126 if params.state then | 139 if params.state then |
127 table.insert(query, { name = "state", value = params.state }); | 140 table.insert(query, { name = "state", value = params.state }); |