util/sasl/oauthbearer.lua

changeset 477
b0a8d4e9934e
equal deleted inserted replaced
476:c34b263499be 477:b0a8d4e9934e
1
2 return function (stream, name)
3 if name == "OAUTHBEARER" and stream.username then
4 return function (stream)
5 local auth = stream.bearer_token and ("Bearer "..stream.bearer_token) or "";
6 local message, data = coroutine.yield("n,a="..stream.username.."@"..stream.host..",\001auth="..auth.."\001");
7 if message == "success" then
8 return true;
9 elseif message == "challenge" then
10 stream:event("oauth-failure", {
11 json = data;
12 });
13 -- Note: No code after the yield should generally execute, as "failure"
14 -- doesn't get passed through to us (it contains no data anyway)
15 if coroutine.yield("\001") ~= "failure" then
16 error("Unexpected SASL state: expected failure after challenge");
17 end
18 return false;
19 end
20 end, stream.bearer_token and 6 or 4; -- Prefer OAUTHBEARER if we have a token, otherwise prefer password if we have one
21 end
22 end

mercurial