Mercurial > prosody-modules
comparison mod_openid/mod_openid.lua @ 1343:7dbde05b48a9
all the things: Remove trailing whitespace
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Tue, 11 Mar 2014 18:44:01 +0100 |
parents | 723fd785815f |
children |
comparison
equal
deleted
inserted
replaced
1342:0ae065453dc9 | 1343:7dbde05b48a9 |
---|---|
15 local associations = {} | 15 local associations = {} |
16 | 16 |
17 local function genkey(length) | 17 local function genkey(length) |
18 -- FIXME not cryptographically secure | 18 -- FIXME not cryptographically secure |
19 str = {} | 19 str = {} |
20 | 20 |
21 for i = 1,length do | 21 for i = 1,length do |
22 local rand = math.random(33, 126) | 22 local rand = math.random(33, 126) |
23 table.insert(str, string.char(rand)) | 23 table.insert(str, string.char(rand)) |
24 end | 24 end |
25 | 25 |
27 end | 27 end |
28 | 28 |
29 local function tokvstring(dict) | 29 local function tokvstring(dict) |
30 -- key-value encoding for a dictionary [#4.1.3] | 30 -- key-value encoding for a dictionary [#4.1.3] |
31 local str = "" | 31 local str = "" |
32 | 32 |
33 for k,v in pairs(dict) do | 33 for k,v in pairs(dict) do |
34 str = str..k..":"..v.."\n" | 34 str = str..k..":"..v.."\n" |
35 end | 35 end |
36 | 36 |
37 return str | 37 return str |
88 -- generate a response nonce [#10.1] | 88 -- generate a response nonce [#10.1] |
89 local random = "" | 89 local random = "" |
90 for i=0,10 do | 90 for i=0,10 do |
91 random = random..string.char(math.random(33,126)) | 91 random = random..string.char(math.random(33,126)) |
92 end | 92 end |
93 | 93 |
94 local timestamp = os.date("%Y-%m-%dT%H:%M:%SZ", utctime()) | 94 local timestamp = os.date("%Y-%m-%dT%H:%M:%SZ", utctime()) |
95 | 95 |
96 return timestamp..random | 96 return timestamp..random |
97 end | 97 end |
98 | 98 |
140 return true | 140 return true |
141 end | 141 end |
142 | 142 |
143 local function handle_endpoint(method, body, request) | 143 local function handle_endpoint(method, body, request) |
144 module:log("debug", "Request at OpenID provider endpoint") | 144 module:log("debug", "Request at OpenID provider endpoint") |
145 | 145 |
146 local params = nil | 146 local params = nil |
147 | 147 |
148 if method == "GET" then | 148 if method == "GET" then |
149 params = query_params(request.url.query) | 149 params = query_params(request.url.query) |
150 elseif method == "POST" then | 150 elseif method == "POST" then |
151 params = query_params(body) | 151 params = query_params(body) |
152 else | 152 else |
153 -- TODO error | 153 -- TODO error |
154 return response_404 | 154 return response_404 |
155 end | 155 end |
156 | 156 |
157 module:log("debug", "Request Parameters:\n"..humane(params)) | 157 module:log("debug", "Request Parameters:\n"..humane(params)) |
158 | 158 |
159 if params["openid.ns"] == openidns then | 159 if params["openid.ns"] == openidns then |
160 -- OpenID 2.0 request [#5.1.1] | 160 -- OpenID 2.0 request [#5.1.1] |
161 if params["openid.mode"] == "associate" then | 161 if params["openid.mode"] == "associate" then |
200 end | 200 end |
201 | 201 |
202 -- Verify the return url [#9.2.1] | 202 -- Verify the return url [#9.2.1] |
203 -- TODO implement return url verification | 203 -- TODO implement return url verification |
204 end | 204 end |
205 | 205 |
206 if params["openid.claimed_id"] and params["openid.identity"] then | 206 if params["openid.claimed_id"] and params["openid.identity"] then |
207 -- asserting an identifier [#9.1] | 207 -- asserting an identifier [#9.1] |
208 | 208 |
209 if params["openid.identity"] == "http://specs.openid.net/auth/2.0/identifier_select" then | 209 if params["openid.identity"] == "http://specs.openid.net/auth/2.0/identifier_select" then |
210 -- automatically select an identity [#9.1] | 210 -- automatically select an identity [#9.1] |
262 if sig == params["openid.sig"] then | 262 if sig == params["openid.sig"] then |
263 is_valid = "true" | 263 is_valid = "true" |
264 end | 264 end |
265 | 265 |
266 module:log("debug", "Signature is: "..is_valid) | 266 module:log("debug", "Signature is: "..is_valid) |
267 | 267 |
268 openidresponse = { | 268 openidresponse = { |
269 ns = openidns, | 269 ns = openidns, |
270 is_valid = is_valid, | 270 is_valid = is_valid, |
271 } | 271 } |
272 | 272 |
273 -- Delete this association | 273 -- Delete this association |
274 associations[params["openid.assoc_handle"]] = nil | 274 associations[params["openid.assoc_handle"]] = nil |
275 return { | 275 return { |
303 if port == '' then | 303 if port == '' then |
304 endpointurl = string.format("http://%s/%s", host, base) | 304 endpointurl = string.format("http://%s/%s", host, base) |
305 else | 305 else |
306 endpointurl = string.format("http://%s:%s/%s", host, port, base) | 306 endpointurl = string.format("http://%s:%s/%s", host, port, base) |
307 end | 307 end |
308 | 308 |
309 local nonce = nonce() | 309 local nonce = nonce() |
310 local key = genkey(32) | 310 local key = genkey(32) |
311 local assoc_handle = newassoc(key) | 311 local assoc_handle = newassoc(key) |
312 | 312 |
313 local openidresponse = { | 313 local openidresponse = { |
378 end | 378 end |
379 | 379 |
380 user, domain = jidutil.split(id) | 380 user, domain = jidutil.split(id) |
381 | 381 |
382 local exists = usermanager.user_exists(user_name, user_domain) | 382 local exists = usermanager.user_exists(user_name, user_domain) |
383 | 383 |
384 if not exists then | 384 if not exists then |
385 return response_404 | 385 return response_404 |
386 end | 386 end |
387 | 387 |
388 local endpointurl = "" | 388 local endpointurl = "" |
389 if port == '' then | 389 if port == '' then |
390 endpointurl = string.format("http://%s/%s", host, base) | 390 endpointurl = string.format("http://%s/%s", host, base) |
391 else | 391 else |
392 endpointurl = string.format("http://%s:%s/%s", host, port, base) | 392 endpointurl = string.format("http://%s:%s/%s", host, port, base) |
393 end | 393 end |
394 | 394 |
395 local head = string.format("<title>Prosody OpenID : %s@%s</title>", user_name, user_domain) | 395 local head = string.format("<title>Prosody OpenID : %s@%s</title>", user_name, user_domain) |
396 -- OpenID HTML discovery [#7.3] | 396 -- OpenID HTML discovery [#7.3] |
397 head = head .. string.format('<link rel="openid2.provider" href="%s" />', endpointurl) | 397 head = head .. string.format('<link rel="openid2.provider" href="%s" />', endpointurl) |
398 | 398 |
399 local content = 'request.url.path: ' .. request.url.path .. '<br/>' | 399 local content = 'request.url.path: ' .. request.url.path .. '<br/>' |
400 content = content .. 'host+port: ' .. request.headers.host .. '<br/>' | 400 content = content .. 'host+port: ' .. request.headers.host .. '<br/>' |
401 content = content .. 'host: ' .. tostring(host) .. '<br/>' | 401 content = content .. 'host: ' .. tostring(host) .. '<br/>' |
402 content = content .. 'port: ' .. tostring(port) .. '<br/>' | 402 content = content .. 'port: ' .. tostring(port) .. '<br/>' |
403 content = content .. 'user_name: ' .. user_name .. '<br/>' | 403 content = content .. 'user_name: ' .. user_name .. '<br/>' |
404 content = content .. 'user_domain: ' .. user_domain .. '<br/>' | 404 content = content .. 'user_domain: ' .. user_domain .. '<br/>' |
405 content = content .. 'exists: ' .. tostring(exists) .. '<br/>' | 405 content = content .. 'exists: ' .. tostring(exists) .. '<br/>' |
406 | 406 |
407 local body = string.format('<p>%s</p>', content) | 407 local body = string.format('<p>%s</p>', content) |
408 | 408 |
409 local data = string.format([[ | 409 local data = string.format([[ |
410 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | 410 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
411 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | 411 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
412 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | 412 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
413 <head> | 413 <head> |