Mercurial > prosody-modules
comparison misc/sasl/example.lua @ 2354:7d2fcc7a15f7
Example SASL mechanism implementation
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 08 Nov 2016 00:15:02 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 2353:ea97a87c3828 | 2354:7d2fcc7a15f7 |
|---|---|
| 1 local method = {} | |
| 2 local method_mt = { __index = method } | |
| 3 | |
| 4 -- This should return a set of supported mechanisms | |
| 5 function method:mechanisms() | |
| 6 return { | |
| 7 ["OAUTH-SOMETHING"] = true; | |
| 8 } | |
| 9 end | |
| 10 | |
| 11 -- Called when a mechanism is selecetd | |
| 12 function method:select(mechanism) | |
| 13 return mechanism == "OAUTH-SOMETHING"; | |
| 14 end | |
| 15 | |
| 16 -- Called for each message received | |
| 17 function method:process(message) | |
| 18 -- parse the message | |
| 19 if false then | |
| 20 -- To send a SASL challenge: | |
| 21 return "challenge", "respond-to-this"; | |
| 22 end | |
| 23 | |
| 24 if false then | |
| 25 -- To fail, send: | |
| 26 return "failure", "not-authorized", "Helpful error message here"; | |
| 27 end | |
| 28 | |
| 29 self.username = "someone"; | |
| 30 return "success"; | |
| 31 end | |
| 32 | |
| 33 local function new_sasl() | |
| 34 return setmetatable({}, method_mt); | |
| 35 end | |
| 36 | |
| 37 function method:clean_clone() | |
| 38 return setmetatable({}, method_mt); | |
| 39 end | |
| 40 | |
| 41 local provider = {} | |
| 42 | |
| 43 function provider.get_sasl_handler() | |
| 44 return new_sasl(); | |
| 45 end | |
| 46 | |
| 47 module:provides("auth", provider); |
