Mercurial > prosody-modules
comparison mod_auth_oauthbearer/mod_auth_oauthbearer.lua @ 3115:d2bf9c8be3a3
Remove debugging helpers and clean up a little
| author | JC Brand <jc@opkode.com> |
|---|---|
| date | Thu, 14 Jun 2018 09:11:03 +0000 |
| parents | 73ada978dabc |
| children |
comparison
equal
deleted
inserted
replaced
| 3114:73ada978dabc | 3115:d2bf9c8be3a3 |
|---|---|
| 27 -- | 27 -- |
| 28 -- See: http://lua-users.org/wiki/StringInterpolation | 28 -- See: http://lua-users.org/wiki/StringInterpolation |
| 29 return (s:gsub('(%b{})', function(w) return tab[w:sub(3, -3)] or w end)) | 29 return (s:gsub('(%b{})', function(w) return tab[w:sub(3, -3)] or w end)) |
| 30 end | 30 end |
| 31 | 31 |
| 32 function provider.test_password(sasl, username, password, realm) | 32 function provider.test_password(username, password, realm) |
| 33 log("debug", "Testing signed OAuth2 for user %s at realm %s", username, realm); | 33 log("debug", "Testing signed OAuth2 for user %s at realm %s", username, realm); |
| 34 -- TODO: determine, based on the "realm" which OAuth provider to verify with. | |
| 35 module:log("debug", "sync_http_auth()"); | |
| 36 local https = require "ssl.https"; | 34 local https = require "ssl.https"; |
| 37 local url = interp(oauth_url, {oauth_client_id = oauth_client_id, password = password}); | 35 local url = interp(oauth_url, {oauth_client_id = oauth_client_id, password = password}); |
| 38 | 36 |
| 39 module:log("debug", "The URL is: "..url); | 37 module:log("debug", "The URL is: "..url); |
| 40 local _, code, headers, status = https.request{ | 38 local _, code, headers, status = https.request{ |
| 43 Authorization = "Basic "..base64(oauth_client_id..":"..oauth_client_secret); | 41 Authorization = "Basic "..base64(oauth_client_id..":"..oauth_client_secret); |
| 44 } | 42 } |
| 45 }; | 43 }; |
| 46 if type(code) == "number" and code >= 200 and code <= 299 then | 44 if type(code) == "number" and code >= 200 and code <= 299 then |
| 47 module:log("debug", "OAuth provider confirmed valid password"); | 45 module:log("debug", "OAuth provider confirmed valid password"); |
| 48 return 'johnny', true; | 46 return true; |
| 49 else | 47 else |
| 50 module:log("warn", "OAuth provider returned status code: "..code); | 48 module:log("debug", "OAuth provider returned status code: "..code); |
| 51 end | 49 end |
| 52 module:log("warn", "OAuth failed. Invalid username or password."); | 50 module:log("warn", "Auth failed. Invalid username/password or misconfiguration."); |
| 53 return nil, false; | 51 return nil; |
| 54 end | 52 end |
| 55 | 53 |
| 56 function provider.users() | 54 function provider.users() |
| 57 return function() | 55 return function() |
| 58 return nil; | 56 return nil; |
| 76 end | 74 end |
| 77 | 75 |
| 78 function provider.get_sasl_handler() | 76 function provider.get_sasl_handler() |
| 79 local supported_mechanisms = {}; | 77 local supported_mechanisms = {}; |
| 80 supported_mechanisms["OAUTHBEARER"] = true; | 78 supported_mechanisms["OAUTHBEARER"] = true; |
| 81 | |
| 82 return new_sasl(host, { | 79 return new_sasl(host, { |
| 83 oauthbearer = function(sasl, username, password, realm) | 80 oauthbearer = function(sasl, username, password, realm) |
| 84 return provider.test_password(sasl, username, password, realm); | 81 return provider.test_password(username, password, realm), true; |
| 85 end, | 82 end, |
| 86 mechanisms = supported_mechanisms | 83 mechanisms = supported_mechanisms |
| 87 }); | 84 }); |
| 88 end | 85 end |
| 89 | 86 |
